nagios nrpe 添加脚本

【基本介绍】
自己添加脚本进行监控

【脚本编写】
1. nagios status
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
脚本退出的状态就是nagios显示的状态

2.退出前的echo显示就是Status Information

例子:
#!/bin/bash
fileName='/etc/passwd'
fileLastModifyTime=`stat -c %y $fileName`
fileLastModifyTime_S=`stat -c %Y $fileName`
currentTime_S=`date +%s`
STATE_OK=0
STATE_CRITICAL=2
#compare date by seconds , check whether biger than 14400 seconds
#查看passwd文件4小时内是否被修改
if [ $[ $currentTime_S - $fileLastModifyTime_S ] -gt 14400  ]
then
        echo "$fileName not modify in past 4hours"
        exit ${STATE_OK}
else
        echo "$fileName modified at $fileLastModifyTime"
        exit ${STATE_CRITICAL}
fi 


【配置】
1.nrpe端
  添加脚本到nagios下面的libexec目录下面,给予运行nagios用户执行权限
  添加命令到nrpe.cfg:
command[check_passwd_modify]=/usr/local/nagios/libexec/check_passwd_modify
   
2.nagios端
  添加相应的service 
#add for passwd shadow file modify checking
define service{
        use                             generic-service
        host_name                       hostname
        service_description             check_passwd_modify
        check_command                   check_nrpe!check_passwd_modify
        max_check_attempts              2
        normal_check_interval           3
        notification_interval           5
        contact_groups                  nagios
}

猜你喜欢

转载自runpanda.iteye.com/blog/2090270