在nagios中使用python腳本監控linux主機


在被監控端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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM