差異處

這裏顯示兩個版本的差異處。

連向這個比對檢視

兩邊的前次修訂版 前次修改
下次修改
前次修改
tech:librenms:nagios_agent [2020/07/08 08:46] jonathan_tsaitech:librenms:nagios_agent [2023/04/08 11:05] (目前版本) – [檢查網址回應效率與關鍵字] jonathan
行 1: 行 1:
 +====== 加裝 Nagios Plugin 增加監控能力 ======
  
 +  * 返回 [[tech:librenms]]
 +
 +===== 安裝語法 =====
 +  * CentOS 7 <cli>
 +yum install nagios-plugins-all
 +</cli>
 +  * Ubuntu 20.04 <cli>
 +sudo apt install nagios-plugins
 +</cli>
 +
 +===== 進行設定 =====
 +==== CentOS 7 ====
 +  * 更改設定檔 <code sh>vi /opt/librenms/config.php</code><file>
 +:
 +# nagios-plugins-all
 +$config['show_services'          = 1;
 +$config['nagios_plugins'  = "/usr/lib64/nagios/plugins";
 +</file><code sh>
 +chmod +x /usr/lib64/nagios/plugins/*
 +</code>
 +
 +==== Ubuntu 20.04 ====
 +  * 更改設定檔 <code sh>vi /opt/librenms/config.php</code><file>
 +:
 +# nagios-plugins
 +$config['show_services'          = 1;
 +$config['nagios_plugins'  = "/usr/lib/nagios/plugins";
 +</file><code sh>
 +chmod +x /usr/lib/nagios/plugins/*
 +</code>
 +
 +===== 共同設定 =====
 +  * 設定定時起動 services-wrapper.py <code sh>vi /etc/cron.d/librenms</code><file>
 +:
 +*/5  *    * * *   librenms    /opt/librenms/services-wrapper.py 1
 +
 +# Daily maintenance script. DO NOT DISABLE!
 +:
 +</file>
 +  * CentOS 7<code sh>
 +service crond restart
 +</code>
 +  * Ubuntu 20.04 <cli>
 +systemctl restart cron 
 +</cli>
 +  * 可以透過 Add Service 增加設定檢查 SSL 憑證到期日, mail 服務運作是否正常...等等的設定
 +    * {{:tech:2019010801.png}}
 +    * {{:tech:2019010802.png}}
 +    * {{:tech:2019010803.png}}
 +    * {{:tech:2019010804.png}}
 +
 +<note>
 +  * 如果要研究所有 plugin 的語法, 可以直接到 /usr/lib64/nagios/plugins 目錄內下命令測試 Exp. ssmtp -> check_ssmtp <code sh>
 +cd /usr/lib64/nagios/plugins/
 +./check_ssmtp --help
 +</code>
 +++++看結果|<file>
 +[root@ct-librenms plugins]# ./check_ssmtp --help
 +check_ssmtp v2.2.1.git (nagios-plugins 2.2.1)
 +Copyright (c) 1999 Ethan Galstad <[email protected]>
 +Copyright (c) 1999-2014 Nagios Plugin Development Team
 +        <[email protected]>
 +
 +This plugin tests SSMTP connections with the specified host (or unix socket).
 +
 +Usage:
 +check_ssmtp -H host -p port [-w <warning time>] [-c <critical time>] [-s <send string>]
 +[-e <expect string>] [-q <quit string>][-m <maximum bytes>] [-d <delay>]
 +[-t <timeout seconds>] [-r <refuse state>] [-M <mismatch state>] [-v] [-4|-6] [-j]
 +[-D <warn days cert expire>[,<crit days cert expire>]] [-S <use SSL>] [-E]
 +[-N <server name indication>]
 +
 +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:<timeout state>
 +    Seconds before connection times out (default: 10)
 +    Optional ":<timeout state>" 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 [email protected] if you have questions regarding use
 +of this software. To submit patches or suggest improvements, send email to
 +[email protected]
 +</file>++++
 +</note>
 +
 +===== 檢查網站 SSL 憑證到期日 =====
 +  * 因為網站大量使用 Web Virtual Host 方式設定, 但檢查 SSL 憑證到期日都只會回應預設的網址憑證到期日.. Exp. www.ichiayi.com 與 svn.ichiayi.com <file>
 +./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.
 +</file> 所以看到 svn.ichiayi.com 回應出來的結果會出現 www.ichiayi.com , 這問題可以**增加 --sni 參數**來解決<file>
 +./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).
 +</file>
 +
 +===== 檢查網址回應效率與關鍵字 =====
 +  * 檢查特定網址的回應效率與正確性 .. 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. <cli>--sni -S</cli>
 +      * -p 443 : 使用連線埠 443
 +      * -u : 要進行效能檢核的網址
 +      * -s : 網頁內容必須出現的關鍵字串 Exp. Jonathan
 +    * 檢核的結果可能類似以下的訊息 : <code>
 +HTTP OK: HTTP/1.1 200 OK - 1073685 bytes in 0.536 second response time
 +</code>
 +
 +===== 參考網址 =====
 +  * 參考相關參數的意義 - 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}}