目的: 當流量超過我所限制的值以上時,寄信警告

設定方式,在 mrtg.cfg 裡加入

ThreshDir: /tmp/thresh
ThreshMaxI[_]: 625000
#ThreshMinI[_]: 1
ThreshMaxO[_]: 625000
#ThreshMinO[_]: 1
ThreshProgI[_]: /bin/mrtg_alert_in.sh
ThreshProgO[_]: /bin/mrtg_alert_out.sh

參數中文說明可參考http://sjsmit.blogspot.com/2005/03/threshold-checkingmrtg.html

這裡我會用到的有 ThreshDir、ThreshMaxI、ThreshMaxO、ThreshProgI、ThreshProgO

當流量超過 625000 就透過 /bin/mrtg_alert_in.sh 去警告通知

thresh 會有三個值喂給 /bin/mrtg_alert_in.sh,第一個是那個設備+port、第二個是就是 625000、第三個是現在流量值

再來說明 625000 這值如何定議的

ThreshMaxI 所給的值是 bytes(大B),我們在 mrtg 圖看到的是小b

所以當我們要限超過5Mkbp時就警告的話,ThreshMaxI的值就要設定成 625000 ,

而它的換算是: (你不要用 1000去乘的話也可以用1024啦)

5Mkbps  = 5000kbps  / 8 * 1000 = 625000  bytes

/bin/mrtg_alert_in.sh 程式內容

#!/bin/bash
# =========
#
#       Mrtg圖          9752    kbps  = 1219 kbytes
#       thresh值        1219079 bytes = 1219 kbytes
#
#       限            4Mkbps  = 4000kbps  / 8 * 1000 = 500000  bytes
#       限            5Mkbps  = 5000kbps  / 8 * 1000 = 625000  bytes
#       限            6Mkbps  = 6000kbps  / 8 * 1000 = 750000  bytes
#       限            7Mkbps  = 7000kbps  / 8 * 1000 = 875000  bytes
#       限            8Mkbps  = 8000kbps  / 8 * 1000 = 1000000 bytes
#       限            9Mkbps  = 9000kbps  / 8 * 1000 = 1125000 bytes
#       限            10Mkbps = 10000kbps / 8 * 1000 = 1250000 bytes
#       限            15Mkbps = 15000kbps / 8 * 1000 = 1875000 bytes
#       限            27Mkbps = 27000kbps / 8 * 1000 = 3375000 bytes
#
#       ThreshDir: /tmp/thresh
#       ThreshMaxI[_]: 625000
#       #ThreshMinI[_]: 1
#       ThreshMaxO[_]: 625000
#       #ThreshMinO[_]: 1
#       ThreshProgI[_]: /bin/mrtg_alert_in.sh
#       ThreshProgO[_]: /bin/mrtg_alert_out.sh
#
# ===============

rm /tmp/thresh/*

target_name=$1
alert_value=$2
current_value=$3
current_value2=`echo $current_value/1000*8 | bc`

if [ `echo ${0##/*/} | cut -d_ -f3 | cut -d. -f1` = in ]; then
in_out=”流入”
elif [ `echo ${0##/*/} | cut -d_ -f3 | cut -d. -f1` = out ]; then
in_out=”流出”
fi

alert_subject=”設備 “$target_name” 超過 “$alert_value” Bytes 的 “$in_out” 上限,現流量為 “$current_value” Bytes、”$current_value2″ kbps”
admin_account=cross@ssorc.tw

cat << EOF | sendmail $admin_account
From: mrtgalert
To: $alert_admin
Subject: [MRTG 警告] $alert_subject
MIME-Version: 1.0
Content-Type: text/html; charset=big5
Content-Transfer-Encoding: 8bit

$alert_subject
EOF

 

記得 ln -s mrtg_alert_in.sh mrtg_alert_out.sh

 

Related posts 相關文章
nagios 使用 pnp4nagios 畫 rrdtool 圖,像 MRTG 圖表
More...
RRDTOOL 的 RRD 檔一些小心得,關於存的筆數
More...
我要怎麼用 RRDTOOL 來取代 MRTG 畫流量圖
More...
用 MRTG 畫 BIND DNS 的查詢量統計
More...

作者

留言

撰寫回覆或留言

發佈留言必須填寫的電子郵件地址不會公開。