我有Nagios / NSCA安装程序运行在nagioshost上的perl自定义脚本。
我有它configuration像:
echo "myhost;myservice;1;Message"|/usr/local/nagios/libexec/send_nsca -to 10 -d ';' -c /etc/send_nsca.cfg -H localhost
它的工作完美无瑕..
所以我的查询,有没有办法在Nagios或NSCA来计算被动检查?
即Nagios在myhost上收到myservice的警报
注意:自定义脚本永远不会为服务发送“OK”
您可以configurationnsca (守护进程),通过在nsca.cfg中设置debug = 1来输出debugging到syslog。 确保debugging选项不会在configuration文件中以不同的值出现多次,也可能被覆盖。 发生在我身上 :)。
nsca.cfg:
# LOG FACILITY # The syslog facility that should be used for logging purposes. log_facility=daemon # DEBUGGING OPTION # This option determines whether or not debugging # messages are logged to the syslog facility. # Values: 0 = debugging off, 1 = debugging on debug=1
在CentOS 7的/ var / log / messages中的输出示例:
Sep 23 10:53:14 centos nsca[4504]: Starting up daemon Sep 23 10:53:19 centos nsca[4504]: Handling the connection... Sep 23 10:53:19 centos nsca[4504]: Time difference in packet: 0 seconds for host myhost Sep 23 10:53:19 centos nsca[4504]: SERVICE CHECK -> Host Name: 'myhost', Service Description: 'myservice', Return Code: '1', Output: 'Message' Sep 23 10:53:19 centos nsca[4504]: Attempting to write to nagios command pipe Sep 23 10:53:19 centos nsca[4504]: Command file '/var/spool/nagios/cmd/nagios.cmd' does not exist, attempting to use alternate dump file '/var/spool/nagios/cmd/nsca.dump' for output Sep 23 10:53:19 centos nsca[4504]: End of connection...
下一步是处理日志以获取所需的信息/数字。 有很多方法可以做到这一点…
按照您的要求示例: Nagios在myhost上收到myservice的警报
grep "SERVICE CHECK -> Host Name: 'myhost', Service Description: 'myservice'" /var/log/messages | wc -l 1
在这里你看到处理日志显示有1个条目符合你的标准。
如果可以编写脚本或编程,那么即使对于提交被动检查的许多客户端主机,只要在日志中包含此数据,就可以编写一些工作良好的内容。