====== 加裝 Nagios Plugin 增加監控能力 ====== * 返回 [[tech:librenms]] ===== 安裝語法 ===== * CentOS 7 yum install nagios-plugins-all * Ubuntu 20.04 sudo apt install nagios-plugins ===== 進行設定 ===== ==== CentOS 7 ==== * 更改設定檔 vi /opt/librenms/config.php : # nagios-plugins-all $config['show_services'] = 1; $config['nagios_plugins'] = "/usr/lib64/nagios/plugins"; chmod +x /usr/lib64/nagios/plugins/* ==== Ubuntu 20.04 ==== * 更改設定檔 vi /opt/librenms/config.php : # nagios-plugins $config['show_services'] = 1; $config['nagios_plugins'] = "/usr/lib/nagios/plugins"; chmod +x /usr/lib/nagios/plugins/* ===== 共同設定 ===== * 設定定時起動 services-wrapper.py vi /etc/cron.d/librenms : */5 * * * * librenms /opt/librenms/services-wrapper.py 1 # Daily maintenance script. DO NOT DISABLE! : * CentOS 7 service crond restart * Ubuntu 20.04 systemctl restart cron * 可以透過 Add Service 增加設定檢查 SSL 憑證到期日, mail 服務運作是否正常...等等的設定 * {{:tech:2019010801.png}} * {{:tech:2019010802.png}} * {{:tech:2019010803.png}} * {{:tech:2019010804.png}} * 如果要研究所有 plugin 的語法, 可以直接到 /usr/lib64/nagios/plugins 目錄內下命令測試 Exp. ssmtp -> check_ssmtp cd /usr/lib64/nagios/plugins/ ./check_ssmtp --help ++++看結果| [root@ct-librenms plugins]# ./check_ssmtp --help check_ssmtp v2.2.1.git (nagios-plugins 2.2.1) Copyright (c) 1999 Ethan Galstad Copyright (c) 1999-2014 Nagios Plugin Development Team This plugin tests SSMTP connections with the specified host (or unix socket). Usage: check_ssmtp -H host -p port [-w ] [-c ] [-s ] [-e ] [-q ][-m ] [-d ] [-t ] [-r ] [-M ] [-v] [-4|-6] [-j] [-D [,]] [-S ] [-E] [-N ] Options: -h, --help Print detailed help screen -V, --version Print version information --extra-opts=[section][@file] Read options from an ini file. See https://www.nagios-plugins.org/doc/extra-opts.html for usage and examples. -H, --hostname=ADDRESS Host name, IP Address, or unix socket (must be an absolute path) -p, --port=INTEGER Port number (default: none) -4, --use-ipv4 Use IPv4 connection -6, --use-ipv6 Use IPv6 connection -E, --escape Can use \n, \r, \t or \\ in send or quit string. Must come before send or quit option Default: nothing added to send, \r\n added to end of quit -s, --send=STRING String to send to the server -e, --expect=STRING String to expect in server response (may be repeated) -A, --all All expect strings need to occur in server response. Default is any -q, --quit=STRING String to send server to initiate a clean close of the connection -r, --refuse=ok|warn|crit Accept TCP refusals with states ok, warn, crit (default: crit) -M, --mismatch=ok|warn|crit Accept expected string mismatches with states ok, warn, crit (default: warn) -j, --jail Hide output from TCP socket -m, --maxbytes=INTEGER Close connection once more than this number of bytes are received -d, --delay=INTEGER Seconds to wait between sending string and polling for response -D, --certificate=INTEGER[,INTEGER] Minimum number of days a certificate has to be valid. 1st is #days for warning, 2nd is critical (if not specified - 0). -S, --ssl Use SSL for the connection. -w, --warning=DOUBLE Response time to result in warning status (seconds) -c, --critical=DOUBLE Response time to result in critical status (seconds) -t, --timeout=INTEGER: Seconds before connection times out (default: 10) Optional ":" can be a state integer (0,1,2,3) or a state STRING -v, --verbose Show details for command-line debugging (Nagios may truncate output) Send email to help@nagios-plugins.org if you have questions regarding use of this software. To submit patches or suggest improvements, send email to devel@nagios-plugins.org ++++ ===== 檢查網站 SSL 憑證到期日 ===== * 因為網站大量使用 Web Virtual Host 方式設定, 但檢查 SSL 憑證到期日都只會回應預設的網址憑證到期日.. Exp. www.ichiayi.com 與 svn.ichiayi.com ./check_http -H www.ichiayi.com --ssl -C 30,10 SSL OK - Certificate 'www.ichiayi.com' will expire in 79 days on 2019-06-14 23:34 +0800/CST. ./check_http -H svn.ichiayi.com --ssl -C 30,10 SSL OK - Certificate 'www.ichiayi.com' will expire in 79 days on 2019-06-14 23:34 +0800/CST. 所以看到 svn.ichiayi.com 回應出來的結果會出現 www.ichiayi.com , 這問題可以**增加 --sni 參數**來解決 ./check_http -H www.ichiayi.com --ssl --sni -C 30,10 SSL OK - Certificate 'www.ichiayi.com' will expire in 79 days on 2019-06-14 23:34 +0800/CST. ./check_http -H svn.ichiayi.com --ssl --sni -C 30,10 SSL WARNING - Certificate 'svn.ichiayi.com' expires in 29 day(s) (2019-04-26 15:26 +0800/CST). ===== 檢查網址回應效率與關鍵字 ===== * 檢查特定網址的回應效率與正確性 .. Exp. https://172.16.1.32/erptools/Tracing_material.php * 參考網址 - https://raymii.org/s/tutorials/Service_checks_in_LibreNMS_nagios_plugins.html * {{:tech:2019090301.png}} * 參數說明 * -E : 額外的效能資料 * -I : 指定特定的 IP (Exp. 網站內部外部 IP 不同) * -S : 使用 SSL 加密協定 (https) **如有出現 Cannot make SSL connection 錯誤訊息可加上 --sni** Exp. --sni -S * -p 443 : 使用連線埠 443 * -u : 要進行效能檢核的網址 * -s : 網頁內容必須出現的關鍵字串 Exp. Jonathan * 檢核的結果可能類似以下的訊息 : HTTP OK: HTTP/1.1 200 OK - 1073685 bytes in 0.536 second response time ===== 參考網址 ===== * 參考相關參數的意義 - https://www.monitoring-plugins.org/doc/man/index.html * https://www.monitoring-plugins.org/doc/man/check_http.html * https://www.monitoring-plugins.org/doc/man/check_ping.html {{tag>librenms_agent nagios}}