IDC网络设备监控脚本-负载指标监控

#!/bin/bash
## Author Da e
## 修改对应设备 <192.168.x.x> ip 和 oid序号 自己查询 使用snmpwalk工具
webhook_url="https://open.feishu.cn/open-apis/bot/v2/hook/xxxxxxx"

##测试机器人
#webhook_url="https://open.feishu.cn/open-apis/bot/v2/hook/cb8419e6-5d30-4ab0-adf9-790027dd3d9e"

################################H3C S5800V2 交换机:<192.168.x.x>################################
# 交换机cpu负载 纯数字 单位百分比
swich_cpuused=`snmpwalk -v 2c -c <安全码>  <192.168.x.x> 1.3.6.1.4.1.25506.2.6.1.1.1.1.6.122 | awk '{print $NF}' | head -n 1`


# 交换机内存 纯数字 单位百分比
swich_memused=`snmpwalk -v 2c -c <安全码>  <192.168.x.x> 1.3.6.1.4.1.25506.2.6.1.1.1.1.8.122 | awk '{print $NF}' | head -n 1`

# 交换机磁盘剩余 纯数字 单位bytes
swich_diskfree=`snmpwalk -v 2c -c <安全码>  <192.168.x.x> 1.3.6.1.4.1.25506.2.5.1.1.4.1.1.5.7995393 | awk '{print $NF}' | head -n 1`

################################深信服  <192.168.x.x>######################################
#  磁盘使用率
_diskused_sdb1=`snmpwalk -v 2c -c <安全码>  <192.168.x.x> 1.3.6.1.4.1.35047.1.5.1.6.1 | awk '{print $NF}' |tr -d '"\%"' | head -n 1`
_diskused_sdb2=`snmpwalk -v 2c -c <安全码>  <192.168.x.x> 1.3.6.1.4.1.35047.1.5.1.6.2 | awk '{print $NF}' |tr -d '"\%"' | head -n 1`
_diskused_sdb3=`snmpwalk -v 2c -c <安全码>  <192.168.x.x> 1.3.6.1.4.1.35047.1.5.1.6.3 | awk '{print $NF}' |tr -d '"\%"' | head -n 1`
_diskused_sdb5=`snmpwalk -v 2c -c <安全码>  <192.168.x.x> 1.3.6.1.4.1.35047.1.5.1.6.4 | awk '{print $NF}' |tr -d '"\%"' | head -n 1`
_diskused_sdb6=`snmpwalk -v 2c -c <安全码>  <192.168.x.x> 1.3.6.1.4.1.35047.1.5.1.6.5 | awk '{print $NF}' |tr -d '"\%"' | head -n 1`

#   cpu使用率(5m) 
_cpuused=`snmpwalk -v 2c -c <安全码>  <192.168.x.x> 1.3.6.1.4.1.35047.1.6.2 | awk '{print $NF}' |tr -d '"\%"' | head -n 1`

#   内存剩余(mb)
_memfree=`snmpwalk -v 2c -c <安全码>  <192.168.x.x> 1.3.6.1.4.1.35047.1.4 | awk '{print $(NF-1)}' |tr -d '"\%"' | head -n 1`

################################ 深信服 AD 负载均衡 ###########################################
# AD cpu使用率(5m)
ad_cpuused=`snmpwalk -v 2c -c <安全码>  <192.168.x.x> 1.3.6.1.4.1.35047.1.9.1.4.1 | awk -F'STRING: "' '{print $2}' |head -n 1`

# AD mem使用率(5m)
ad_memused=`snmpwalk -v 2c -c <安全码>  <192.168.x.x> 1.3.6.1.4.1.35047.2.2.19.0 | awk '{print $(NF)}' |head -n 1`

# AD  磁盘使用率(5m)
ad_diskused_sda1=`snmpwalk -v 2c -c <安全码>  <192.168.x.x> 1.3.6.1.4.1.35047.1.5.1.6.1 | awk '{print $NF}' |tr -d '"\%"' | head -n 1`
ad_diskused_sda2=`snmpwalk -v 2c -c <安全码>  <192.168.x.x> 1.3.6.1.4.1.35047.1.5.1.6.2 | awk '{print $NF}' |tr -d '"\%"' | head -n 1`
ad_diskused_sda5=`snmpwalk -v 2c -c <安全码>  <192.168.x.x> 1.3.6.1.4.1.35047.1.5.1.6.3 | awk '{print $NF}' |tr -d '"\%"' | head -n 1`
ad_diskused_sda6=`snmpwalk -v 2c -c <安全码>  <192.168.x.x> 1.3.6.1.4.1.35047.1.5.1.6.4 | awk '{print $NF}' |tr -d '"\%"' | head -n 1`
ad_diskused_sda7=`snmpwalk -v 2c -c <安全码>  <192.168.x.x> 1.3.6.1.4.1.35047.1.5.1.6.5 | awk '{print $NF}' |tr -d '"\%"' | head -n 1`
ad_diskused_sda8=`snmpwalk -v 2c -c <安全码>  <192.168.x.x> 1.3.6.1.4.1.35047.1.5.1.6.6 | awk '{print $NF}' |tr -d '"\%"' | head -n 1`
ad_diskused_sda9=`snmpwalk -v 2c -c <安全码>  <192.168.x.x> 1.3.6.1.4.1.35047.1.5.1.6.7 | awk '{print $NF}' |tr -d '"\%"' | head -n 1`
ad_diskused_shm=`snmpwalk -v 2c -c <安全码>  <192.168.x.x> 1.3.6.1.4.1.35047.1.5.1.6.8 | awk '{print $NF}' |tr -d '"\%"' | head -n 1`


time=$(date '+%Y-%m-%d %H:%M:%S')
swich_diskfree_mb=$(echo "scale=2;$swich_diskfree/1024/1024" | bc)

##记录数据
echo " $time IDC监控 | 交换机指标:cpu使用率:${swich_cpuused}% 内存使用率:${swich_memused}% 磁盘剩余:${swich_diskfree_mb}MB   | 指标:cpu使用率:${_cpuused}% 内存剩余:${_memfree}MB 磁盘使用率: sdb1:${_diskused_sdb1}% sdb2:${_diskused_sdb2}% sdb3:${_diskused_sdb3}% sdb5:${_diskused_sdb1}% sdb6:${_diskused_sdb1}% | AD负载均衡指标:cpu使用率:${ad_cpuused}% 内存使用ç:${ad_memused}% 磁盘使用率: sda1:${ad_diskused_sda1}% sda2:${ad_diskused_sda2}% sda5:${ad_diskused_sda5}% sda6:${ad_diskused_sda6}% sda7:${ad_diskused_sda7}% sda8:${ad_diskused_sda8}% sda9:${ad_diskused_sda9}% shm:${ad_diskused_shm}% " >> /data/idc_snmp.log



## 判断数据
##大于等于指标
##################交换机
if [[ $(echo "$swich_cpuused >= 80" | bc -l) -eq 1 ]]
then
   message=" $time \n 交换机cpu使用率超过80% 当前指标:${swich_cpuused}% "
  
   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 "$swich_memused >= 90" | bc -l) -eq 1 ]]
then
   message=" $time \n 交换机内存使用率超过90% 当前指标:${swich_memused}% "
  
   curl -H "Content-Type: application/json" -X POST -d '{"msg_type":"text","content":{"text":"**IDC网络设备告警**\n\n'"$message"'","mention_all":false}}' $webhook_url
fi

swich_diskfree_mb_alert="100.00"
if (( $(echo "$swich_diskfree_mb < $swich_diskfree_mb_alert" | bc -l) ))
then
   message=" $time \n 交换机磁盘剩余不足500MB 当前指标:${swich_diskfree_mb}MB  "
  
   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 "$_cpuused >= 90" | bc -l) -eq 1 ]]
then
   message=" $time \n 设备cpu使用率超过80% 当前指标:${_cpuused}% "
  
   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 "$_memfree <= 100" | bc -l) -eq 1 ]]
then
   message=" $time \n 设备内存剩余小于100MB 当前指标:${_memfree}MB "
  
   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 "$_diskused_sdb1 >= 90" | bc -l) -eq 1 ]]
then
   message=" $time \n VPN设备磁盘sdb1使用率超过90% 当前指标:${_diskused_sdb1}% "
  
   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 "$_diskused_sdb2 >= 90" | bc -l) -eq 1 ]]
then
   message=" $time \n VPN设备磁盘sdb2使用率超过90% 当前指标:${_diskused_sdb2}% "
  
   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 "$_diskused_sdb3 >= 90" | bc -l) -eq 1 ]]
then
   message=" $time \n VPN设备磁盘sdb3使用率超过90% 当前指标:${_diskused_sdb3}% "
  
   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 "$_diskused_sdb5 >= 90" | bc -l) -eq 1 ]]
then
   message=" $time \n VPN设备磁盘sdb5使用率超过90% 当前指标:${_diskused_sdb5}% "
  
   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 "$_diskused_sdb6 >= 90" | bc -l) -eq 1 ]]
then
   message=" $time \n VPN设备磁盘sdb6使用率超过90% 当前指标:${_diskused_sdb6}% "
  
   curl -H "Content-Type: application/json" -X POST -d '{"msg_type":"text","content":{"text":"**IDC网络设备告警**\n\n'"$message"'","mention_all":false}}' $webhook_url
fi

##################AD负载均衡
if [[ $(echo "$ad_cpuused >= 80" | bc -l) -eq 1 ]]
then
   message=" $time \n AD设备cpu使用率超过80% 当前指标:${ad_cpuused}% "
   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 "$ad_memused >= 90" | bc -l) -eq 1 ]]
then
   message=" $time \n AD设备内存使用率超过90% 当前指标:${ad_memused}% "
  
   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 "$ad_diskused_sda1 >= 90" | bc -l) -eq 1 ]]
then
   message=" $time \n AD设备磁盘sda1使用率超过90% 当前指标:${ad_diskused_sda1}% "
  
   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 "$ad_diskused_sda2 >= 90" | bc -l) -eq 1 ]]
then
   message=" $time \n AD设备磁盘sda2使用率超过90% 当前指标:${ad_diskused_sda2}% "
  
   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 "$ad_diskused_sda5 >= 90" | bc -l) -eq 1 ]]
then
   message=" $time \n AD设备磁盘sda5使用率超过90% 当前指标:${ad_diskused_sda5}% "
  
   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 "$ad_diskused_sda6 >= 90" | bc -l) -eq 1 ]]
then
   message=" $time \n AD设备磁盘sda6使用率超过90% 当前指标:${ad_diskused_sda6}% "
  
   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 "$ad_diskused_sda7 >= 90" | bc -l) -eq 1 ]]
then
   message=" $time \n AD设备磁盘sda7使用率超过90% 当前指标:${ad_diskused_sda7}% "
  
   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 "$ad_diskused_sda8 >= 90" | bc -l) -eq 1 ]]
then
   message=" $time \n AD设备磁盘sda8使用率超过90% 当前指标:${ad_diskused_sda8}% "
  
   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 "$ad_diskused_sda9 >= 90" | bc -l) -eq 1 ]]
then
   message=" $time \n AD设备磁盘sda9使用率超过90% 当前指标:${ad_diskused_sda9}% "
  
   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 "$ad_diskused_shm >= 90" | bc -l) -eq 1 ]]
then
   message=" $time \n AD设备磁盘sdm使用率超过90% 当前指标:${ad_diskused_shm}% "
  
   curl -H "Content-Type: application/json" -X POST -d '{"msg_type":"text","content":{"text":"**IDC网络设备告警**\n\n'"$message"'","mention_all":false}}' $webhook_url
fi

你可能感兴趣的:(网络,snmp,idc)