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