2e2e2 发表于 2014-4-18 11:05:30

在nagios中使用python脚本监控linux主机

在被监控端192.168.5.110
1.先把getload.py放到/usr/local/nagios/libexec内
# 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)

# chmod a+x getload.py
# chown nagios:nagios getload.py


2. 在nrpe内加入自定义的命令
# vim /usr/local/nagios/etc/nrpe.cfg
command=/usr/local/nagios/libexec/getload.py

------------------------------------------------------------------------------------------

在nagios服务端测试192.168.5.10

# /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中加入自定义脚本
# cd /usr/local/nagios/etc/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
      }

# 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

页: [1]
查看完整版本: 在nagios中使用python脚本监控linux主机