注:只能大概监控,通过CPU的温度间接估计机房温度异常。
#!/bin/bash
# CPU high temperature alarm
function Token(){
to=$1
subject=$2
text=$3
curl 'https://oapi.dingtalk.com/robot/send?access_token=02ff07a076d044f26bbfd7342fc91e322cbbf8eeec3f641497e5a4e197d201231' \
-H 'Content-Type: application/json' \
-d '
{"msgtype": "text",
"text": {
"content": "'"$text"'"
},
"at":{
"atMobiles": [ "'"$1"'" ],
"isAtAll": false
}
}'
}
for i in `seq 0 1`
do
temp[$i]=`sensors |grep "Physical id $i"|awk '{print $4}'|sed 's/[^0-9]//g' | cut -c 1-2`
done
High=70
Crit=$(( (${temp[0]}+${temp[1]}) / 2 ))
if [ $Crit -gt $High ];then
Token "15300000000" "高温报警" "\
时间:`date +%Y-%m-%d\ %H:%M:%S`
主机:`hostname -I| awk '{print $1}'`
信息:CPU平均温度 ${Crit}°C
阈值:当前设置为 ${High}°C
事件:机房温度可能过高!!!"
fi