在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

转载于:https://www.cnblogs.com/nhlinkin/p/3671059.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值