nagios plugin shell 自定義,並可以被rrdtool+pnp4nagios 繪畫

Current Status:

 OK  


(for 0d 1h 57m 28s)Status

Information:  USERS OK - 3 users currently logged in

Performance Data:   users=3;5;10;0  #### 些數據控制繪圖信息,和繪圖數據生成

Current Attempt:1/4  (HARD state)

Last Check Time:03212014 17:46:11

Check Type:ACTIVE

Check Latency / Duration:0.129 / 0.030 seconds

Next Scheduled Check:  03-21-2014 17:56:11

Last State Change:03212014 15:56:11

Last Notification:N/A (notification 0)

xxxxxx.........




### 自定義插件要想輸出如下信息

Status Information:0 , w=70 c=160
Performance Data:users=70;160;0;114

必須在腳本的輸出結果爲 : 0 , w=70 c=160 | users=70;160;0;114

其中'|' 作爲數據的分隔位置。

示例腳本,只是繪圖完測試檢測,可定義修改使用

#/bin/bash
# Date  xxx
# Author  xx
# Description check the nagios pulgin shell uageage
Useage_help="$0 [-w|--warn number ][ -c |--critical number] "
Warning=0
Critical=0
STAT_OK=0
STAT_WARNING=1
STAT_CRITICAL=2
STAT_UNKNOW=3
process=`/bin/ps -ef | /usr/bin/wc -l `
while [ -n "$1" ]
    do
            case $1 in
                -w|--warn)
                 shift
                 Warning=$1
                ;;
               -c|--critical)
                shift
                Critical=$1
                ;;
                *)
                echo "$Useage_help"
                exit 1
                ;;
            esac
        shift
    done
#echo "Warning = $Warning , Critical = $Critical"
###    aa  | bb
# aa : Status Information
# bb : Performance Data
echo "$STAT_OK , w=$Warning c=$Critical | users=$Warning;$Critical;0;$process"



調用方法與系統自帶的一致。

腳格式參照:http://os.51cto.com/art/201103/249956.htm


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章