#!/bin/sh
alert(){
wget "{NAME} traffic-in is ${IN}M traffic-out is ${OUT}M" -o /dev/null&
wget "{NAME}&msg= traffic-in is ${IN}M traffic-out is ${OUT}M " -o /dev/null&
}
checkbw(){
INS=`snmpwalk -v 2c -c ${PUBLIC} ${HOST} ${INSTA}.${INTERFACE}|awk -F : '{print $4}'|bc`
OUTS=`snmpwalk -v 2c -c ${PUBLIC} ${HOST} ${OUTSTA}.${INTERFACE}|awk -F : '{print $4}'|bc`
INHIST=`echo ${INS} *8|bc`
OUTHIST=`echo ${OUTS} *8|bc`
TIMEHIST=`date +%s`
sleep 1
INS=`snmpwalk -v 2c -c ${PUBLIC} ${HOST} ${INSTA}.${INTERFACE}|awk -F : '{print $4}'|bc`
OUTS=`snmpwalk -v 2c -c ${PUBLIC} ${HOST} ${OUTSTA}.${INTERFACE}|awk -F : '{print $4}'|bc`
TIMENOW=`date +%s`
TH=`echo ${TIMENOW} - ${TIMEHIST}|bc`
echo ${TH}
IN=`echo ${INS} *8|bc`
OUT=`echo ${OUTS} *8|bc`
BWINTMP=`echo ${IN} - ${INHIST}|bc`
BWOUTTMP=`echo ${OUT} - ${OUTHIST}|bc`
if [ ${TH} -eq 0 ]
then
TH=1
fi
BWIN=`echo ${BWINTMP}/${TH}|bc`
BWOUT=`echo ${BWOUTTMP}/${TH}|bc`
OUT=`echo $BWOUT/1024/1024|bc`
IN=`echo $BWIN/1024/1024|bc`
echo BWIN IS ${IN}M
echo BWOUT IS ${OUT}M
}
checkcernet(){
PUBLIC="public"
HOST="localhost"
INSTA="RFC1213-MIB::ifInOctets"
OUTSTA="RFC1213-MIB::ifOutOctets"
INTERFACE=2
NAME="test"
MAXOUT="80"
MAXIN="50"
checkbw
if [ ${IN} -ge ${MAXIN} ]
then
if [ ${IN} -ne 0 ]
then
alert
fi
fi
if [ ${OUT} -ge ${MAXOUT} ]
then
if [ ${IN} -ne 0 ]
then
alert
fi
fi
}
阅读(1356) | 评论(1) | 转发(0) |