通过代理服务器发微信告警,用shell脚本监控主机并发送告警信息到微信
#!/bin/bash
# Create for mai
# Create date 2018-03-11
# Using check host source
# Noting delete content
# Shell Option $@
# 01.獲取主機資源
Date=`date +%Y-%m-%d`
Date_time=`date "+%Y-%m-%d__%H:%M:%S"`
Disk_rate=`df -h|grep \/\$|awk -F" " '{ print $5 }'`
Disk_rate2=${Disk_rate%%%}
CPU_free=`vmstat |tail -1|awk -F" " '{print $15}'`
# 02.判斷根磁盤使用率超額
CropID='ww4730ead71a1818a6'
Secret='y4CCI-4LoiWmuqs6A5kYRpEyzhUlCveKeQ_Ik_WeEW4'
GURL="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$CropID&corpsecret=$Secret"
Gtoken=$(/usr/bin/curl -s -G $GURL | awk -F\" '{print $10}')
PURL="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$Gtoken"
if [ $Disk_rate2 -gt 90 ]
then
echo "$Date_time 磁盤使用率超額" >> /tmp/$Date.disk_rate.log
/usr/bin/curl --data-ascii '{ "touser": "$1", "toparty": "2","msgtype": "text","agentid": "1000002","text": {"content": "'獲取時間:${Date_time}'\n'磁盤使用率:${Disk_rate}'"},"safe":"0"}' $PURL
else
echo "$Date_time 磁盤使用率良好:$Disk_rate" >> /tmp/$Date.disk_rate.log
fi
# 03.判斷CPU空閑值過低
if [ $CPU_free -lt 10 ]
then
echo "$Date_time CPU空閑率少于10%" >> /tmp/$Date.CPU_free.log
/usr/bin/curl --data-ascii '{ "touser": "mai", "toparty": "2","msgtype": "text","agentid": "1000002","text": {"content": "'獲取時間:${Date_time}'\n'CPU空閑率:${CPU_free}%'"}' $PURL
else
echo "$Date_time CPU空閑率良好:$CPU_free%" >> /tmp/$Date.CPU_free.log
fi
總結
以上是生活随笔為你收集整理的通过代理服务器发微信告警,用shell脚本监控主机并发送告警信息到微信的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 人力资源知识图谱搭建及应用
- 下一篇: ei指什么_SCI、EI分别是什么意思