#!/usr/bin/env python
#====================================================================
# What's this ?
#====================================================================
# Script designed for nagios
# Air conditioning alarm testing
# Tested with Nagios 2.9 Python 2.3.4 "DHADR 0261" lenox unit
# should work with any Air conditioning unit supporting pcoweb
#
# pCOweb integrated in lexnox Unit
# General information: pcoweb@carel.com
# if needed : Used Mib decription : CAREL-ahu_pco_v18.MIB
#
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#====================================================================
import commands,getopt,time,os,string,syslog,sys
def main():
STATE_OK = 0
STATE_WARNING = 1
STATE_CRITICAL = 2
STATE_UNKNOWN = 3
if len(sys.argv) != 2:
sys.exit("Check if AC pcoweb contains alarm \n\nUsage : check_pcoweb.py AC_hostname")
AC_ip = sys.argv[1]
# lenox/pcoweb using a web interface to serve alarms
# This script is using a personal "self made" summary html page. You need to push this page to your AC unit
# provided with this pluggin.
#getting the alarm page results
cmd = " export http_proxy=; curl -s %s.mydomain.com/http/alarm_summary.html | grep : " %AC_ip
message = ''
nb_err_warn = 0
nb_err_crit = 0
cmd_output = os.popen(cmd)
ligne = cmd_output.readlines()
if len(ligne) == 0:
print "CRITICAL: %s test impossible" %AC_ip
sys.exit(STATE_CRITICAL)
# Parsing alarms
for cmd_word in ligne:
# Alarms are tagged in the summary page with "c" for critical, "w" for warning
if cmd_word.find("1:c") != -1:
nb_err_crit = nb_err_crit + 1
message = message + "crit:" + cmd_word.split("
")[0].split(":")[0] + " - "
else:
if cmd_word.find("1:w") != -1:
nb_err_warn = nb_err_warn + 1
message = message + "warn:" + cmd_word.split("
")[0].split(":")[0] + " - "
if nb_err_crit > 0:
print "CRITICAL:%s : " %AC_ip , "Number of Critical : ", nb_err_crit ," - msg : " , message
sys.exit(STATE_CRITICAL)
elif nb_err_warn > 0:
print "WARNING:%s : " %AC_ip , "Number of warning : ", nb_err_warn ," - msg : " , message
sys.exit(STATE_WARNING)
else:
print "%s is OK - no alarm " %AC_ip
sys.exit(STATE_OK)
main()