http://blog./uid-26978448-id-3411107.html 2012
nagios-plugins自帶有一個check_ping二進(jìn)制文件可以檢測丟包率和ping的回應(yīng)值,但由于領(lǐng)導(dǎo)要求所有監(jiān)控腳本改用python寫,所以這里用python重新寫了一個。代碼如下: #cat check_ping.py 點(diǎn)擊(此處)折疊或打開
#easy_install ping 安裝成功后即可正常運(yùn)行本腳本。 直接執(zhí)行腳本不加參數(shù)可以查看腳本用法: #python check_ping.py Usage: check_python_ping.py 實例: 由于nagios程序是由nagios用戶執(zhí)行,使用該腳本的ping模塊會報錯,需要給nagios用戶開放sudo權(quán)限: #visudo 添加以下內(nèi)容 nagios ALL=(ALL) NOPASSWD: /usr/local/nagios/libexec/check_ping.py commands.cfg配置: ##### 飛信機(jī)器人的配置 ###### define command { command_name notify-service-by-fei command_line LD_LIBRARY_PATH=/usr/local/fetion /usr/local/fetion/fetion --mobile=158******** --pwd=123456 --to=$CONTACTPAGER$ --msg-type=1 --msg-utf8="**Nagios**\nNotification Type: $NOTIFICATIONTYPE$\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\nDate/Time: $LONGDATETIME$\nAdditional Info:\n$SERVICEOUTPUT$" } ##### 定義check_python_ping命令 ##### define command { command_name check_python_ping command_line sudo $USER1$/check_ping.py $HOSTADDRESS$ $ARG1$ $ARG2$ } services.cfg配置: define service{ use service01 host_name test service_description ping check_command check_python_ping!30!200 } 效果圖如下: |
|