1 将check_log3.pl下载后放到客户端服务器的插件文件夹
[[email protected] libexec]# cp /tmp/check_log3.pl /usr/local/nagios/libexec
2 增加执行权限 #chmod +x check_log3.pl
[[email protected] libexec]# chmod +x check_log3.pl
3 修改owner #chown nagios.nagios check_log3.pl
[[email protected] libexec]# chown nagios.nagios check_log3.pl
4 运行 check_log3.pl 确认可执行,无报错,如果提示缺少pm文件,需要安装相应的perl module
之前安装check_linux_stats.pl ,此处不会出现报错
[[email protected] libexec]# ./check_log3.pl -h
[[email protected] libexec]# ./check_log3.pl -h
This is check_log3.pl version 3.11b
。。。。。。。
5 测试监控message,下面命令为扫描messages里的Error或者error为关键字的行,如果有多个关键字,用‘|’分隔
check_log3放在/usr/local/nagios/libexec里:
root直接跑没问题
[[email protected] libexec]# /usr/local/nagios/libexec/check_log3.pl -l /var/log/messages -p ‘[Ee]rror‘ -n nrpe
OK: Found 0 lines (limit=1/0): No matches found.|lines=0
[[email protected] libexec]#
但是sudo -u nagios有报错:
sudo -u nagios /usr/local/nagios/libexec/check_log3.pl -l /var/log/messages -p ‘[Ee]rror‘ -n nrpe
[[email protected] libexec]# sudo -u nagios /usr/local/nagios/libexec/check_log3.pl -l /var/log/messages -p ‘[Ee]rror‘ -n nrpe
Unable to open ‘/var/log/messages‘: Permission denied
/etc/sudoers里需要做如下设置:
[[email protected] libexec]# visudo
#zhailiang
Defaults requiretty
nagios ALL=(ALL) NOPASSWD:/usr/local/nagios/libexec/check_log3.pl
测试:
[[email protected] libexec]$ sudo ./check_log3.pl -l /var/log/messages -p ‘[Ee]rror‘ -n nrpe
OK: Found 0 lines (limit=1/0): No matches found.|lines=0
[[email protected] libexec]# ./check_nrpe -H 127.0.0.1 -c check_log
OK: Found 0 lines (limit=1/0): No matches found.|lines=0
[[email protected] ~]$ sudo /usr/local/nagios/libexec/check_log3.pl -l /var/log/messages -p ‘[Ee]rror‘ -n nrpe
OK: Found 0 lines (limit=1/0): No matches found.|lines=0
6 测试无误后加入nrpe.cfg
command[check_log]=/usr/bin/sudo /usr/local/nagios/libexec/check_log3.pl -l /var/log/messages -p ‘[Ee]rror‘ -n nrpe
7 重启xinetd
8 从poller上测试check_nrpe命令:
[[email protected] plugins]# ./check_nrpe -H 10.90.27.8 -c check_log
OK: Found 0 lines (limit=1/0): No matches found.|lines=0
[[email protected] plugins]#
结果验证正常,可以在centreon控制台中操作。
9 增加centreon service监控模板 添加log监控到相关服务器。
该脚本可以监控其他各种应用日志,有兴趣的同学可以做进一步研究。
check_log3.pl脚本的下载地址与介绍:
https://exchange.nagios.org/directory/Plugins/Log-Files/check_log3-2Epl/details