bash
#!/bin/bash
## Author Da e
## 修改对应设备<192.168.x.x> <安全码> 和oid序号 自己查询 使用snmpwalk工具
##修改webhook机器人告警地址
webhook_url="https://open.feishu.cn/open-apis/bot/v2/hook/xxxxxxxxxxxxxxxxx"
# VPN上行流量(纯数字)kb
vpnupflow=`snmpwalk -v 2c -c <安全码> <192.168.x.x> 1.3.6.1.4.1.35047.2.10.8 | awk '{print $(NF-2)}'|grep -oP '\d+\.\d+'`
# VPN下行流量(纯数字)kb
vpndownflow=`snmpwalk -v 2c -c <安全码> <192.168.x.x> 1.3.6.1.4.1.35047.2.10.9 | awk '{print $(NF-2)}'|grep -oP '\d+\.\d+'`
# AD上行流量(纯数字)MB
adupflow=`snmpwalk -v 2c -c <安全码> <192.168.x.x> 1.3.6.1.4.1.35047.2.2.5.0 | awk -F'STRING: ' '{print $2}' | awk '{print $1}' |tr -d '\"'`
# AD下行流量(纯数字)MB
addownflow=`snmpwalk -v 2c -c <安全码> <192.168.x.x> 1.3.6.1.4.1.35047.2.2.6.0 | awk -F'STRING: ' '{print $2}' | awk '{print $1}' |tr -d '\"'`
##转换单位
adupflowkb=$(echo "$adupflow * 1024" | bc -l)
addownflowkb=$(echo "$addownflow * 1024" | bc -l)
#echo $adupflowkb $addownflowkb
time=$(date '+%Y-%m-%d %H:%M:%S')
message=" $time \n VPN上行流量${vpnupflow}kb VPN下行流量${vpndownflow}kb\n AD上行流量${adupflow}MB AD下行流量${addownflow}MB"
echo "$time | IDC流量监控 | VPN上行流量${vpnupflo}kb VPN下行流量${vpndownflow}kb | AD上行流量${adupflow}MB AD下行流量${addownflow}MB" >> /data/idc_flow.log
if [[ $(echo "$vpnupflow <= 10" | bc -l) -eq 1 ]]
then
message=" $time \n vpn设备上行设备流小于10kb 当前指标:${vpnupflow}kb "
echo $message
curl -H "Content-Type: application/json" -X POST -d '{"msg_type":"text","content":{"text":"**IDC网络设备告警**\n\n'"$message"'","mention_all":false}}' $webhook_url
fi
if [[ $(echo "$vpndownflow <= 10" | bc -l) -eq 1 ]]
then
message=" $time \n vpn设备上行设备流小于10kb 当前指标:${vpndownflow}kb "
echo $message
curl -H "Content-Type: application/json" -X POST -d '{"msg_type":"text","content":{"text":"**IDC网络设备告警**\n\n'"$message"'","mention_all":false}}' $webhook_url
fi
if [[ $(echo "$adupflowkb <= 10" | bc -l) -eq 1 ]]
then
message=" $time \n AD设备上行设备流小于10kb 当前指标:${adupflowkb}kb "
echo $message
curl -H "Content-Type: application/json" -X POST -d '{"msg_type":"text","content":{"text":"**IDC网络设备告警**\n\n'"$message"'","mention_all":false}}' $webhook_url
fi
if [[ $(echo "$adupflowkb <= 10" | bc -l) -eq 1 ]]
then
message=" $time \n vpn设备上行设备流小于10kb 当前指标:${adupflowkb}kb "
echo $message
curl -H "Content-Type: application/json" -X POST -d '{"msg_type":"text","content":{"text":"**IDC网络设备告警**\n\n'"$message"'","mention_all":false}}' $webhook_url
fi