被监控端工作已经做好了,现在就只要在监控端进行操作了;

注意一下:被监控中mysql记得要设密码啊

添加服务类型也是2种:

1.web服务器

2.mysql服务器

下面是添加web服务的脚本:

webservices(){read-p"PleaseinputthewebserverIP:"webipread-p"pleaseinputthewebaliasname:"hostecho"definehost{host_name$hostaliasweb-serveraddress$webipcheck_commandcheck-host-alivemax_check_attempts5check_period24x7contact_groupsweb-servernotification_interval10notification_period24x7notification_optionsd,u,r}">>/usr/local/nagios/etc/objects/hosts.cfgsed-i"6,10{/members/s/$/,$host/}"/usr/local/nagios/etc/objects/hostgroups.cfgecho"definehostescalation{host_name$hostfirst_notification5last_notification0notification_interval10contact_groupsweb-server}defineserviceescalation{host_name$hostservice_descriptionNginx-Listenerfirst_notification5last_notification0notification_interval10contact_groupsweb-server}defineserviceescalation{host_name$hostservice_descriptionLinux-PHP-procsfirst_notification5last_notification0notification_interval10contact_groupsweb-server}defineserviceescalation{host_name$hostservice_descriptionLinux-iftrafficfirst_notification5last_notification0notification_interval10contact_groupsweb-server}defineserviceescalation{host_name$hostservice_descriptioncheck-ipsfirst_notification5last_notification0notification_interval10contact_groupsweb-server}">>/usr/local/nagios/etc/objects/escalations.cfgecho"defineservice{host_name$hostservice_descriptioncheck-host-alivecheck_commandcheck-host-alivemax_check_attempts4normal_check_interval3retry_check_interval2check_period24x7notification_interval10notification_period24x7notification_optionsw,u,c,rcontact_groupsweb-server}defineservice{host_name$hostservice_descriptiondisk-/check_commandcheck_local_disk!10%!5%!/max_check_attempts4normal_check_interval3retry_check_interval2check_period24x7notification_interval10notification_period24x7notification_optionsw,u,c,rcontact_groupsweb-server}defineservice{host_name$hostservice_descriptionSSH-Listenercheck_commandcheck_tcp!22max_check_attempts4normal_check_interval3retry_check_interval2check_period24x7notification_interval10notification_period24x7notification_optionsw,u,c,rcontact_groupsweb-server}defineservice{host_name$hostservice_descriptionNginx-Listenercheck_commandcheck_tcp!80max_check_attempts4normal_check_interval2retry_check_interval1check_period24x7notification_interval2notification_period24x7notification_optionsw,u,c,rcontact_groupsweb-server}defineservice{host_name$hostservice_descriptionLinux-Memorycheck_commandcheck_nrpe!check_memmax_check_attempts4normal_check_interval3retry_check_interval2check_period24x7notification_interval10notification_period24x7notification_optionsw,u,c,rcontact_groupsweb-server}defineservice{host_name$hostservice_descriptionLinux-loadcheck_commandcheck_nrpe!check_loadmax_check_attempts4normal_check_interval3retry_check_interval2check_period24x7notification_interval10notification_period24x7notification_optionsw,u,c,rcontact_groupsweb-server}defineservice{host_name$hostservice_descriptionLinux-total-procscheck_commandcheck_nrpe!check_total_procsmax_check_attempts4normal_check_interval3retry_check_interval2check_period24x7notification_interval10notification_period24x7notification_optionsw,u,c,rcontact_groupsweb-server}defineservice{host_name$hostservice_descriptionLinux-PHP-procscheck_commandcheck_nrpe!check_php_procsmax_check_attempts4normal_check_interval3retry_check_interval2check_period24x7notification_interval5notification_period24x7notification_optionsw,u,c,rcontact_groupsweb-server}defineservice{host_name$hostservice_descriptionLinux-CPUcheck_commandcheck_nrpe!check_cpumax_check_attempts4normal_check_interval3retry_check_interval2check_period24x7notification_interval10notification_period24x7notification_optionsw,u,c,rcontact_groupsweb-server}defineservice{host_name$hostservice_descriptionLinux-usercheck_commandcheck_nrpe!check_usersmax_check_attempts4normal_check_interval3retry_check_interval2check_period24x7notification_interval10notification_period24x7notification_optionsw,u,c,rcontact_groupsweb-server}defineservice{host_name$hostservice_descriptioncheck-ipscheck_commandcheck_nrpe!check_ipsmax_check_attempts4normal_check_interval2retry_check_interval2check_period24x7notification_interval8notification_period24x7notification_optionsw,u,c,rcontact_groupsweb-server}defineservice{host_name$hostservice_descriptionLinux-iftrafficcheck_commandcheck_nrpe!check_iftraffic!"eth0"!50!100!50!mmax_check_attempts4normal_check_interval4retry_check_interval2check_period24x7notification_interval5notification_period24x7notification_optionsw,u,c,rcontact_groupsweb-server}">>/usr/local/nagios/etc/objects/services.cfgecho"###############Addweb-serverservicescompleted########"}

下面是添加mysql服务的脚本:

addmysqlservicemaster(){read-p"PleaseinputthenagiosserverIP:"naigosipread-p"PleaseinputthemysqlserverIP:"mysqlipread-p"pleaseinputthemysqlaliasname:"hostread-p"pleaseinputthemysqlpassword:"mysqlpwdread-p"pleaseinputthenagiosformysql'spassword:"nagiospwdecho"definehost{host_name$hostaliasweb-serveraddress$mysqlipcheck_commandcheck-host-alivemax_check_attempts5check_period24x7contact_groupsweb-servernotification_interval10notification_period24x7notification_optionsd,u,r}">>/usr/local/nagios/etc/objects/hosts.cfgsed-i"11,15{/members/s/$/,$host/}"/usr/local/nagios/etc/objects/hostgroups.cfgecho"definehostescalation{host_name$hostfirst_notification5last_notification0notification_interval10contact_groupsmysql-server}defineserviceescalation{host_name$hostservice_descriptionMysql-Listenerfirst_notification5last_notification0notification_interval10contact_groupsmysql-server}defineserviceescalation{host_name$hostservice_descriptionMysql-Statusfirst_notification5last_notification0notification_interval10contact_groupsmysql-server}">>/usr/local/nagios/etc/objects/escalations.cfgecho"defineservice{host_name$hostservice_descriptioncheck-host-alivecheck_commandcheck-host-alivemax_check_attempts4normal_check_interval3retry_check_interval2check_period24x7notification_interval10notification_period24x7notification_optionsw,u,c,rcontact_groupsmysql-server}defineservice{host_name$hostservice_descriptioncheck_diskcheck_commandcheck_nrpe!check_diskmax_check_attempts4normal_check_interval3retry_check_interval2check_period24x7notification_interval10notification_period24x7notification_optionsw,u,c,rcontact_groupsmysql-server}defineservice{host_name$hostservice_descriptionSSH-Listenercheck_commandcheck_tcp!22max_check_attempts4normal_check_interval3retry_check_interval2check_period24x7notification_interval10notification_period24x7notification_optionsw,u,c,rcontact_groupsmysql-server}defineservice{host_name$hostservice_descriptionMysql-Listenercheck_commandcheck_tcp!3306max_check_attempts4normal_check_interval2retry_check_interval1check_period24x7notification_interval2notification_period24x7notification_optionsw,u,c,rcontact_groupsmysql-server}defineservice{host_name$hostservice_descriptionLinux-Memorycheck_commandcheck_nrpe!check_memmax_check_attempts4normal_check_interval3retry_check_interval2check_period24x7notification_interval10notification_period24x7notification_optionsw,u,c,rcontact_groupsmysql-server}defineservice{host_name$hostservice_descriptionLinux-loadcheck_commandcheck_nrpe!check_loadmax_check_attempts4normal_check_interval3retry_check_interval2check_period24x7notification_interval10notification_period24x7notification_optionsw,u,c,rcontact_groupsmysql-server}defineservice{host_name$hostservice_descriptionLinux-total-procscheck_commandcheck_nrpe!check_total_procsmax_check_attempts4normal_check_interval3retry_check_interval2check_period24x7notification_interval10notification_period24x7notification_optionsw,u,c,rcontact_groupsmysql-server}defineservice{host_name$hostservice_descriptionLinux-CPUcheck_commandcheck_nrpe!check_cpumax_check_attempts4normal_check_interval3retry_check_interval2check_period24x7notification_interval10notification_period24x7notification_optionsw,u,c,rcontact_groupsmysql-server}defineservice{host_name$hostservice_descriptionLinux-usercheck_commandcheck_nrpe!check_usersmax_check_attempts4normal_check_interval3retry_check_interval2check_period24x7notification_interval10notification_period24x7notification_optionsw,u,c,rcontact_groupsmysql-server}defineservice{host_name$hostservice_descriptionLinux-iftrafficcheck_commandcheck_nrpe!check_iftraffic!"eth0"!50!100!50!mmax_check_attempts4normal_check_interval3retry_check_interval2check_period24x7notification_interval10notification_period24x7notification_optionsw,u,c,rcontact_groupsweb-server}defineservice{host_name$hostservice_descriptionthreads-connectedcheck_commandcheck_mysql_health!nagios!$nagiospwd!threads-connected!$mysqlip!3306!max_check_attempts4normal_check_interval2retry_check_interval1check_period24x7notification_interval10notification_period24x7notification_optionsw,u,c,rcontact_groupsmysql-server}defineservice{host_name$hostservice_descriptionMysql-Statuscheck_commandcheck_mysqlmax_check_attempts4normal_check_interval2retry_check_interval1check_period24x7notification_interval2notification_period24x7notification_optionsw,u,c,rcontact_groupsmysql-server}">>/usr/local/nagios/etc/objects/services.cfgecho"###############addmysqlservices################"

这样就行了