1. Active monitoring mode
Monitoring Client LNMP Web Services
Server-side:
[[email protected]] #cd/usr/local/nagios/etc/objects
[Email protected] objects]# VI commands.cfg
#在最下面增加:
# ' Check_weburl ' command definition
Define Command{
Command_name Check_weburl
Command_line $USER 1$/check_http $ARG 1$-W 10-c 30
}
Save exit
[[Email protected] objects] #cd/usr/local/nagios/etc/services
Creating an active mode monitoring profile webzd.cfg
[[Email protected] objects] #vi webzd.cfg
Define Service {
Use Generic-service
HOST_NAME 1.34-web
Service_description blog_ip
Check_command check_weburl! -I. 10.89.1.34
Max_check_attempts 3
Normal_check_interval 2
Retry_check_interval 1
Check_period 24x7
Notification_interval 30
Notification_period 24x7
Notification_options W,u,c,r
Contact_groups Admins
Process_perf_data 1
}
Define Service {
Use Generic-service
HOST_NAME 1.34-web
Service_description Blog_url
Check_command check_http! -H bolg.etiantian.org
Max_check_attempts 3
Normal_check_interval 2
Retry_check_interval 1
Check_period 24x7
Notification_interval 30
Notification_period 24x7
Notification_options W,u,c,r
Contact_groups Admins
}
Define Service {
Use Generic-service
HOST_NAME 1.34-web
Service_description blog_port_80
Check_command check_tcp!80
Max_check_attempts 3
Normal_check_interval 2
Retry_check_interval 1
Check_period 24x7
Notification_interval 30
Notification_period 24x7
Notification_options W,u,c,r
Contact_groups Admins
}
Define Service {
Use Generic-service
HOST_NAME 1.34-web
Service_description Ssh_port
Check_command check_tcp! 22
Max_check_attempts 3
Normal_check_interval 2
Retry_check_interval 1
Check_period 24x7
Notification_interval 30
Notification_period 24x7
Notification_options W,u,c,r
Contact_groups Admins
}
Define Service {
Use Generic-service
HOST_NAME 1.34-web
Service_description Mysql_port
Check_command check_tcp!3306
Max_check_attempts 3
Normal_check_interval 2
Retry_check_interval 1
Check_period 24x7
Notification_interval 30
Notification_period 24x7
Notification_options W,u,c,r
Contact_groups Admins
}
Define Service {
Use Generic-service
HOST_NAME 1.34-web
Service_description rsync
Check_command check_tcp!873
Max_check_attempts 3
Normal_check_interval 2
Retry_check_interval 1
Check_period 24x7
Notification_interval 30
Notification_period 24x7
Notification_options W,u,c,r
Contact_groups Admins
}
Save and exit
Check syntax
[Email protected] @nagios objects]#/etc/init.d/nagios checkconfig
In case of no error:
[Email protected] @nagios objects]#/etc/init.d/nagios Reload
------------------------------------------------------------------
Custom plugins: monitor password files for changes
Client testing:
Generate a MD5 value for/etc/passwd
[Email protected] ~]# MD5SUM/ETC/PASSWD
5e2ebd59c3ebb7bd3c4b09b0674ca746/etc/passwd
Save to/etc/alvin.md5 (file name random, store location arbitrary)
[Email protected] ~]# md5sum/etc/passwd >/ETC/ALVIN.MD5
Analyze MD5 value change, no change show "OK"
[Email protected] ~]# md5sum-c/ETC/ALVIN.MD5
/etc/passwd:ok
Actual combat:
1. Add a custom script to the client
Cd/usr/local/nagios/libexec
Cat CHECK_PASSWD
#!/bin/bash
Char= ' md5sum-c/etc/alvin.md5 2>/dev/null|grep "OK" |wc-l '
If [$char-eq 1];
Then
echo "passwd is OK"
Exit 0
Else
echo "passwd is changed"
Exit 2
Fi
#添加执行的权限
[Email protected] libexec~]# chmod +x check_passwd
[email protected] libexec~]# ll CHECK_PASSWD
-rwxr-xr-x 1 root root 166 Jul 21:33 check_passwd
2. Add the command to the client and restart the Nrpe service to make it effective
[[email protected] libexec~] #vim/usr/local/nagios/etc/nrpe.cfg
Add check_passwd Definition Command
command[check_passwd]=/usr/local/nagios/libexec/check_passwd
[[email protected] libexec~] #pkill Nrpe
#重新启动nrpe
[Email protected] libexec~]#/usr/local/nagios/bin/nrpe-c/usr/local/nagios/etc/nrpe.cfg-d
#查看是否启动了
[Email protected] libexec~]ps-ef|grep Nrpe
Nagios 64672 1 0 Dec22? 00:00:21/usr/local/nagios/bin/nrpe-c/usr/local/nagios/etc/nrpe.cfg-d
Root 72255 72099 0 11:48 pts/0 00:00:00 grep Nrpe
3. Testing on the service side
[Email protected] services]#/usr/local/nagios/libexec/check_nrpe-h 10.89.1.34-c check_passwd
passwd is OK
Add Service Script
[[Email protected] ~] #cd/usr/local/nagios/etc/objects/
[Email protected] objects]# VI services.cfg
#在后面添加
Define Service{
Use Generic-service
HOST_NAME 1.34-WEB-LNMP
Service_description check_passwd
Check_command check_nrpe!check_passwd
}
Detect syntax and reload/etc/init.d/nagios checkconfig
In case of no error:
[Email protected] objects]#/etc/init.d/nagios Reload
4. Change Test Execute Add user command on client
[[Email protected] ~] #useradd Jack
Service-Side Execution
[Email protected] services]#/usr/local/nagios/libexec/check_nrpe-h 10.89.1.34-c check_passwd
PASSWD is changed
This article is from the "Knowledge Change Destiny" blog, please be sure to keep this source http://ahtornado.blog.51cto.com/4826737/1885436
Nagios Monitoring Configuration Introduction (III)