解决方法
你可以用
event handlers做到这一点.
首先,为您的Load平均定义添加一个事件处理程序:
define service{ use generic-service host_name xx service_description Load_Average check_command check_nrpe!check_load event_handler processes_snapshot!xx contact_groups admin-sms }
processes_snapshot命令在commands.cfg中定义:
define command{ command_name processes_snapshot command_line $USER1$/eventhandlers/processes_snapshot.sh $SERVICESTATE$$SERVICESTATETYPE$$SERVICEATTEMPT$$HOSTADDRESS$ }
第二,编写事件处理程序脚本(processes_snapshot.sh):
#!/bin/bash case "$1" in OK) ;; WARNING) /usr/local/nagios/libexec/check_nrpe -H $4 -c processes_snapshot ;; UNKNOWN) ;; CRITICAL) /usr/local/nagios/libexec/check_nrpe -H $4 -c processes_snapshot ;; esac exit 0
命令processes_snapshot在xx主机上的nrpe.cfg中定义,如下所示:
command[processes_snapshot]=top -cSbn 1 | tail -n +8 | sort -rn -k11 | head > /tmp/proc_snap.txt
PS:我还没有测试过这个配置.