全站最帅😎
发布于 2021-02-25 / 1674 阅读
0
0

Centos7下磁盘空间监测企业微信报警脚本

使用企业微信报警

#!/bin/bash

function sendmsg() {
CorpID="替换成自己的"
Secret="替换成自己的"
agentid=替换成自己的

GURL="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$CorpID&corpsecret=$Secret"
Gtoken=$(/usr/bin/curl -s -G $GURL|awk -F\" '{print $10}')

#echo $Gtoken
PURL="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$Gtoken"

Ip=$(ip addr show eth0 |grep -w inet |awk '{print $2}' |awk -F '/' '{print $1}')
Hostname=$(hostname)

/usr/bin/curl --data-ascii '{
"toparty": "6",
"msgtype": "text",
"agentid": "1000006",
"text": {"content": "'"警告: 磁盘$1占用已超过$2\n主机: $Hostname\n日期: $(date +%F-%T)\n地址: $Ip"'":"0",
"enable_id_trans": 0,
"enable_duplicate_check": 0,
"duplicate_check_interval": 1800
}' $PURL >/dev/null 2>&1
}


DEV=`df -hP | grep '^/dev/*' | cut -d' ' -f1 | sort`
for I in $DEV
do dev=`df -Ph | grep $I | awk '{print $1}'`
size=`df -Ph | grep $I | awk '{print $2}'`
used=`df -Ph | grep $I | awk '{print $3}'`
free=`df -Ph | grep $I | awk '{print $4}'`
rate=`df -Ph | grep $I | awk '{print $5}'`
mount=`df -Ph | grep $I | awk '{print $6}'`
# echo -e "$I:\tsize:$size\tused:$used\tfree:$free\trate:$rate\tmount:$mount"  >> "./disk.log"
# F=`echo $rate | awk -F% '{print $1}'` >> "./disk.log"
F=`echo $rate | awk -F% '{print $1}'`
if [ $F -ge 90 ]
then
    sendmsg $I $rate
fi
done

评论