#!/bin/bash
date=`date +%Y-%m-%d_%H:%M:%S`
name=`'hostname'`
nwip=`ifconfig|grep 'inet '|grep -v '127.0'|xargs|awk -F '[ :]' '{print $2}'`
for  ((;;))
do

#磁盘监控
disk_use=`df -h | grep "/dev/" | awk '{printf $5}' | sed 's/%/\n/g'`
for disk_use in $disk_use
do
if [  $disk_use -ge 1  ];then
curl -s -d '' "https://api.telegram.org/bot1758755484:AAFHvuGQ8dPQlo1rEesGmtAggT6BIBt7-xw/sendMessage?chat_id=-591414316&text=""内网IP：$nwip %0A主机名：$name %0A在$date 磁盘使用达到: $disk_use%"
fi
done

#cpu监控
cpu_average=`top -b -n 1 | grep "load" | awk '{printf $10 $11 $12 $13}'`
cpu_use=`top -b -n 1 | grep "Cpu" | awk '{printf $2}' | cut -d "." -f 1`
if [[ $cpu_use -ge 2 ]];then
curl -s -d '' "https://api.telegram.org/bot1758755484:AAFHvuGQ8dPQlo1rEesGmtAggT6BIBt7-xw/sendMessage?chat_id=-591414316&text=""内网IP：$nwip %0A 主机名：$name %0A在$date CPU 使用：$cpu_use% %0A过去1分钟、5分钟、15分钟CPU平均值为：$cpu_average" 
fi

#cpu监控2
cpu_average2=`top -b -n 1 | grep Cpu | awk '{print $8}'|cut -f 1 -d "."`
cpu_use2=`expr 100 - $cpu_average2`
if [[ $cpu_use2 -ge 2 ]];then
curl -s -d '' "https://api.telegram.org/bot1758755484:AAFHvuGQ8dPQlo1rEesGmtAggT6BIBt7-xw/sendMessage?chat_id=-591414316&text=""内网IP：$nwip %0A 主机名：$name %0A在$date CPU负载超过80% " 
fi

#内存监控
men_use=`free | awk '/Mem/{printf("%.2f\n"), $3/$2*100}' | cut -d "." -f 1`
if [ $men_use -ge 1 ];then

curl -s -d '' "https://api.telegram.org/bot1758755484:AAFHvuGQ8dPQlo1rEesGmtAggT6BIBt7-xw/sendMessage?chat_id=-591414316&text=""内网IP：$nwip %0A主机名：$name %0A在$date 内存使用： $men_use%" 
fi
done


# https://api.telegram.org/bot1758755484:AAFHvuGQ8dPQlo1rEesGmtAggT6BIBt7-xw/sendMessage?chat_id=-591414316&text=
#参考文档:  https://blog.csdn.net/tladagio/article/details/88786340
#参考文档:  https://blog.csdn.net/u014692704/article/details/97621362
#参考文档:  https://blog.csdn.net/qq_41772936/article/details/82588014
