Nagios事件机制实践

Nagios事件机制实践

 blog地址:http://www.cnblogs.com/caoguo

 

一.事件触发执行脚本

[root@Nagios ~]# cd /usr/local/nagios/libexec/eventhandlers/
[root@Nagios eventhandlers]# touch process_snapshot.sh
[root@Nagios eventhandlers]# vi process_snapshot.sh 
#!/bin/bash
 
case "$1" in
    OK)
        ;;
    WARNING)
        /usr/local/nagios/libexec/check_nrpe -H $4 -c process_snapshot
        ;;
    UNKNOWN)
        ;;
    CRITICAL)
        /usr/local/nagios/libexec/check_nrpe -H $4 -c process_snapshot
        ;;
esac
exit 0

[root@Nagios eventhandlers]# chmod +x process_snapshot.sh 
[root@Nagios eventhandlers]# chown -R nagios.nagios /usr/local/nagios/libexec/eventhandlers/

 

[root@Nagios ~]# vi /etc/nagios/objects/commands.cfg 
define command{
        command_name    process_snapshot
        command_line    $USER1$/eventhandlers/process_snapshot.sh $SERVICESTATE$ $SERVICESTATETYPE$ $SERVICEATTEMPT$ $HOSTADDRESS$
}

 

 

二.配置nagios主机文件

# 开启触发脚本
[root@Nagios ~]# vi /etc/nagios/objects/nrpehost.cfg
define service{
        use                             generic-service         
        host_name                       nrpehost
        service_description             CHECK LOAD
        check_command                   check_nrpe!check_load
        notifications_enabled            1
        event_handler                    process_snapshot
        }
# 开启事件触发功能
[root@Nagios ~]# grep "enable_event_handlers" /etc/nagios/nagios.cfg 
enable_event_handlers=1

 

三.配置nrpe节点

# nrpe节点定义执行命令
[root@Nrpe ~]# vi /etc/nrpe/nrpe.cfg
command[process_snapshot]=top -cSb n 1 | tail -n +8 | sort -rn -k9 | head -n20 > /tmp/proc_snap.log
# 允许命令中带有参数
dont_blame_nrpe=1

 

四.测试远程执行

 

# 查看文件是否能创建

 

五.实验测试调整

[root@Nrpe ~]# grep 'load' /etc/nrpe/nrpe.cfg
command[check_load]=/usr/local/nrpe/libexec/check_load -w 0.7,0.6,0.5 -c 1,3,5

# 修改检查间隔为1分钟,这样可以来观测事件执行动作
[root@Nagios ~]# vi /etc/nagios/objects/templates.cfg
normal_check_interval           1

 

六.结果

 

[root@Nrpe ~]# dd bs=1G count=4k if=/dev/zero of=test

 

 

 

 

 

 

 

参考:http://www.ttlsa.com/nagios/nagios-event-handlers-application/

posted @ 2015-11-20 22:54  ca0guo  阅读(305)  评论(0编辑  收藏  举报