在被监控端192.168.5.110
1.先把getload.py放到/usr/local/nagios/libexec内
[root@nhserver1 ~]# vim /usr/local/nagios/libexec/getload.py
#! /usr/bin/env python
import os,sys
(d1,d2,d3) = os.getloadavg()
if d1 >= 5.0:
print "GETLOADAVG CRITICAL: Load average is %.2f" % (d1)
sys.exit(2)
elif d1 >= 2.0:
print "GETLOADAVG WARNING: Load average is %.2f" %(d1)
else:
print "GETLOADAVG OK: Load average is %.2f" %(d1)
[root@nhserver1 libexec]# chmod a+x getload.py
[root@nhserver1 libexec]# chown nagios:nagios getload.py
2. 在nrpe内加入自定义的命令
[root@nhserver1 libexec]# vim /usr/local/nagios/etc/nrpe.cfg
command[nh_check_getload]=/usr/local/nagios/libexec/getload.py
------------------------------------------------------------------------------------------
在nagios服务端测试192.168.5.10
[root@nhserver2 libexec]# /usr/local/nagios/libexec/check_nrpe -H 192.168.5.110 -c nh_check_getload
GETLOADAVG OK: Load average is 0.06
在服务端测试192.168.5.10的nagios中加入自定义脚本
[root@nhserver2 ~]# cd /usr/local/nagios/etc/objects
[root@nhserver2 objects]# vim hosts_192.168.5.110.cfg
define host{
use linux-server
host_name 192.168.5.110
alias 192.168.5.110
address 192.168.5.110
}
define hostgroup{
hostgroup_name nh_linuxs
alias nh_linuxs
members 192.168.5.110
}
define service{
use local-service
host_name 192.168.5.110
service_description check-host-alive
check_command check-host-alive
max_check_attempts 5
normal_check_interval 3
retry_check_interval 2
check_period 24x7
notification_interval 10
notification_period 24x7
}
define service{
use local-service
host_name 192.168.5.110
service_description SSH
check_command check_ssh
max_check_attempts 5
normal_check_interval 3
retry_check_interval 2
check_period 24x7
notification_interval 10
notification_period 24x7
}
define service{
use local-service
host_name 192.168.5.110
service_description check_nrpe_check_users
check_command check_nrpe!nh_check_users
max_check_attempts 5
normal_check_interval 3
retry_check_interval 2
check_period 24x7
notification_interval 10
notification_period 24x7
}
define service{
use local-service
host_name 192.168.5.110
service_description check_nrpe_check_getload
check_command check_nrpe!nh_check_getload
max_check_attempts 5
normal_check_interval 3
retry_check_interval 2
check_period 24x7
notification_interval 10
notification_period 24x7
}
[root@nhserver2 objects]# service nagios reload
在nagios的services中就可看到的状态了
192.168.5.110
check_nrpe_check_getload
OK 04-17-2014 16:21:53 0d 0h 4m 22s 1/5 GETLOADAVG OK: Load average is 0.00
转载于:https://www.cnblogs.com/nhlinkin/p/3671059.html