当前位置: > Linux服务器 > 监控工具 >

CentOS下nagios监控机房温度

时间:2014-09-09 18:51来源:linux.it.net.cn 作者:it

自己公司机房,空调用得烂,没有联动,没有通电自开机。经历过晚上电路切换拉闸事件。等知道的时候进去完全就一锅炉房。
曲线救国方式,用交换机的温度来判断空调是否断电。
1、expect交互登录交换机读取温度值

[root@nagios opt]# cat 123.exp
#!/usr/bin/expect -f
set user user
set passwd password
spawn telnet 192.168.0.254
expect "Username:"
send -- "$user\r"
expect "Password:"
send -- "$passwd\r"
expect ""
send -- "dis env\r"
expect ""
send -- "quit\r"
expect eof

2、添加一个nagios监控脚本

[root@nagios opt]# cat /usr/local/nagios/libexec/check_temp
#!/bin/bash
expect /opt/123.exp >/opt/123.log
temp=`awk '/hotspot/ {print $3}' /opt/123.log`
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3

if [ "$#" == "4" ]

then

#Set variables
arg=${4}
w=$2
c=$4

if [ $temp -ge $w -a $temp -lt $c ]

then

echo "Warning :Room temperature $temp°C "
exitstatus=$STATE_WARNING

elif [ $temp -ge $c ]
then

echo "Critical :Room temperature $temp°C"
exitstatus=$STATE_CRITICAL

else

echo "OK :Room temperature $temp°C."

exitstatus=$STATE_OK
fi

fi

exit $exitstatus

3、添加command

[root@nagios opt]# tail -5 /usr/local/nagios/etc/objects/commands.cfg
# 'check_temp' command definition
define command{
command_name check_temp
command_line $USER1$/check_temp -w $ARG1$ -c $ARG2$
}

4、修改nrpe.cfg

[root@nagios opt]# grep "temp" /usr/local/nagios/etc/nrpe.cfg
command[check_temp]=/usr/local/nagios/libexec/check_temp -w 30 -c 33

5、添加监控项目

[root@nagios opt]# tail -6 /usr/local/nagios/etc/objects/localhost.cfg
define service{
use generic-service
host_name localhost
service_description check_temp
check_command check_nrpe!check_temp
}

<a data-cke-saved-href="http://www.xmydlinux.org/wp-content/uploads/2014/02/11.jpg" href="http://www.xmydlinux.org/wp-content/uploads/2014/02/11.jpg" class="cboxElement" rel="example4" 773"="" style="text-decoration: none; color: rgb(1, 150, 227);">

(责任编辑:IT)
------分隔线----------------------------