#!/bin/sh
Date=`date +%F" "%H:%M:%S`
snmp="XXX"
Host="XXX"
MIB="IF-MIB::ifHCOutOctets.44 = Counter64"
while true
do
for i in `ls -l`
do
first=`snmpwalk -v 2c -c $snmp $Host $MIB |awk '{print $NF}'`
sleep 10
while true
do
last=`snmpwalk -v 2c -c $snmp $Host $MIB |awk '{print $NF}'`
byte=`echo "$last-$first" |bc`
mbps=`echo "scale=2;$byte*8/10/1000000000" |bc`
if [ $(echo "$mbps > 9" | bc ) = 1 ];then
webhook='https://oapi.dingtalk.com/robot/send?access_token=xxx'
Name='端口'
port="10g1/0/40"
function SendMsgToDingding() {
curl $webhook -H 'Content-Type: application/json' -d "
{
'msgtype': 'text',
'text': {
'content': '告警时间:$Date \n告警信息:$Name流量阈值警告 \n当前流量:${mbps}G \n$port流量超出9
G,请注意!!!'
},
'at':{
'isAtAll': false
}
}"
}
SendMsgToDingding
fi
break
done
done
done