Centos 监控CPU温度-微信报警

Posted 倔强的冬瓜

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Centos 监控CPU温度-微信报警相关的知识,希望对你有一定的参考价值。

Centos 监控CPU温度-微信报警

 

安装插件:

# yum -y install lm_sensors

(centos6,大面积yum源不可用,可以试试这个:

# centos6的yum源失效了
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
wget -O /etc/yum.repos.d/CentOS-Base.repo http://files.tttidc.com/centos6/Centos-6.repo
wget -O /etc/yum.repos.d/epel.repo http://files.tttidc.com/centos6/epel-6.repo
yum clean all
yum makecache )

检测传感器:

# sh –c “yes|sensors-detect”

获取CPU温度信息

# sensors

# sensors

coretemp-isa-0000

Adapter: ISA adapter

Physical id 0:  +75.0°C (high = +76.0°C, crit = +86.0°C)

Core 0:         +69.0°C  (high = +76.0°C, crit = +86.0°C)

Core 1:         +72.0°C  (high = +76.0°C, crit = +86.0°C)

Core 2:         +71.0°C  (high = +76.0°C, crit = +86.0°C)

Core 3:         +75.0°C  (high = +76.0°C, crit = +86.0°C)

Core 4:         +70.0°C  (high = +76.0°C, crit = +86.0°C)

Core 8:         +70.0°C  (high = +76.0°C, crit = +86.0°C)

Core 9:         +72.0°C  (high = +76.0°C, crit = +86.0°C)

Core 10:        +71.0°C (high = +76.0°C, crit = +86.0°C)

Core 11:        +71.0°C (high = +76.0°C, crit = +86.0°C)

Core 12:        +74.0°C (high = +76.0°C, crit = +86.0°C)

 

coretemp-isa-0001

Adapter: ISA adapter

Physical id 1:  +68.0°C (high = +76.0°C, crit = +86.0°C)

Core 0:         +66.0°C  (high = +76.0°C, crit = +86.0°C)

Core 1:         +66.0°C  (high = +76.0°C, crit = +86.0°C)

Core 2:         +66.0°C  (high = +76.0°C, crit = +86.0°C)

Core 3:         +63.0°C  (high = +76.0°C, crit = +86.0°C)

Core 4:         +63.0°C  (high = +76.0°C, crit = +86.0°C)

Core 8:         +62.0°C  (high = +76.0°C, crit = +86.0°C)

Core 9:         +69.0°C  (high = +76.0°C, crit = +86.0°C)

Core 10:       +66.0°C  (high = +76.0°C, crit = +86.0°C)

Core 11:        +67.0°C (high = +76.0°C, crit = +86.0°C)

Core 12:        +62.0°C (high = +76.0°C, crit = +86.0°C)

检测脚本:

# cat temp.sh

#!/bin/bash

warn=75

n=0

for i in $(sensors |egrep -v 'isa|ISA'|grep -v ^$  |awk  '{print int($(NF-6))}' )

do

   if [ ${i} -gt ${warn} ];then

      n=$(($n+1))

   fi

done

if [ $n -gt 6 ]

then

   echo "温度过高"

   /bin/bash /root/weixin.sh      1.5机房温度过高,请核实!

else

   echo "温度正常"

fi

配置计划任务:

*/3 * * * * /bin/bash /root/temp.sh

微信报警脚本:

# cat weixin.sh

#/bin/bash

CropID="wx362c9htfhff34eba"

Secret="c1z0c_36shcT6ux0n4z-h2y8EFgrKdfRDDSvXFuu-Sqk"

GURL="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$CropID&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"

function body() {

       local int AppID=1

       local UserID=$1

       local PartyID=3

       local Msg=$(echo "$@" | cut -d" " -f3-)

        printf '{\n'

       printf '\t"touser":"'"$UserID"\"",\n"

       printf '\t"toparty":"'"$PartyID"\"",\n"

       printf '\t"msgtype": "text",\n'

       printf '\t"agentid": "'" $AppID"\"",\n"

       printf '\t"text": {\n'

       printf '\t\t"content":"'"$Msg"\""\n"

       printf '\t},\n'

       printf '\t"safe":"0"\n'

       printf '}\n'

 }

/usr/bin/curl --data-ascii "$(body $1$2 $3)" $PURL

param=$(body $1 $2 $3)

NUM=`echo $param |grep 'OK'|wc -l`

#open alert sound 引发报警警报(声音)

if [[ $NUM != 1 ]] ; then

 curl -G http://18.6.22.9:8980/basic/app/voice/play?file=town.mid

fi


以上是关于Centos 监控CPU温度-微信报警的主要内容,如果未能解决你的问题,请参考以下文章

zabbix3.4实现微信报警,

配置Zabbix3.4及4.0版本通过企业微信报警(全网最详细)

可以远程查看其他电脑的温度吗?通过一台电脑远程监控多台电脑的硬盘,显卡,CPU温度,温度过高提示报警。

alertmanager报警添加企业微信监控报警

实战Nagios网络监控——Nagios 微信报警

Zabbix_监控报警无法通过微信发送信息