#!/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