红联Linux门户
Linux帮助

Nagios(centreon)监控Linux日志

发布时间:2015-09-26 10:30:13来源:linux网站作者:linux人

1.将check_log3.pl下载后放到客户端服务器的插件文件夹
[root@SSAVL2475 libexec]# cp /tmp/check_log3.pl  /usr/local/nagios/libexec


2.增加执行权限 #chmod +x check_log3.pl
[root@SSAVL2475 libexec]# chmod +x check_log3.pl


3.修改owner #chown nagios.nagios check_log3.pl
[root@SSAVL2475 libexec]# chown nagios.nagios check_log3.pl


4.运行 check_log3.pl 确认可执行,无报错,如果提示缺少pm文件,需要安装相应的perl module
之前安装check_linux_stats.pl ,此处不会出现报错
[root@SSAVL2475 libexec]# ./check_log3.pl -h

[root@SSAVL2475 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直接跑没问题
[root@SSAVL2475 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
[root@SSAVL2475 libexec]#
但是sudo -u nagios有报错:
sudo -u nagios /usr/local/nagios/libexec/check_log3.pl -l /var/log/messages -p '[Ee]rror' -n nrpe
 
[root@SSAVL2475 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里需要做如下设置:
[root@SSAVL2475 libexec]# visudo
#zhailiang
Defaults    requiretty
nagios ALL=(ALL) NOPASSWD:/usr/local/nagios/libexec/check_log3.pl

测试:
[nagios@SSAVL2475 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

[root@SSAVL2475 libexec]# ./check_nrpe -H 127.0.0.1 -c check_log
OK: Found 0 lines (limit=1/0): No matches found.|lines=0

[nagios@SSAVL2475 ~]$ 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命令:
[root@SSAVL2521 plugins]# ./check_nrpe -H 10.90.27.8 -c check_log
OK: Found 0 lines (limit=1/0): No matches found.|lines=0
[root@SSAVL2521 plugins]#
结果验证正常,可以在centreon控制台中操作。


9.增加centreon service监控模板 添加log监控到相关服务器。

该脚本可以监控其他各种应用日志,有兴趣的同学可以做进一步研究。

check_log3.pl脚本的下载地址与介绍:

https://exchange.nagios.org/directory/Plugins/Log-Files/check_log3-2Epl/details


如何用Nagios监控通用服务:http://www.linuxdiyf.com/linux/12795.html

CentOS 6.4 x64 Nagios监控平台:监控Linux主机的CPU温度:http://www.linuxdiyf.com/linux/11405.html

在Linux下安装与配置Nagios:http://www.linuxdiyf.com/linux/11454.html

搭建基于Nagios的监控系统-之监控远程Linux服务器:http://www.linuxdiyf.com/linux/10433.html

Ubuntu安装运行Nagios:http://www.linuxdiyf.com/linux/8545.html