#!/usr/bin/python # Nagios script : checking APC USV # Copyright 2010 by Joerg Stephan johe DOT stephan AT googlemail.com # from pysnmp.entity.rfc3413.oneliner import cmdgen, ntforg from pysnmp.proto.api import v2c import sys import getopt STATE_OK = 0 STATE_WARNING = 1 STATE_CRIT = 2 CurrentState = 0 RetString = 'Temperatur: ' messbegin = 15 Warningstart = 28 Criticalstart = 30 port1 = 1,3,6,1,4,1,14848,2,1,2,1,4,1 port2 = 1,3,6,1,4,1,14848,2,1,2,1,4,2 port3 = 1,3,6,1,4,1,14848,2,1,2,1,4,3 port4 = 1,3,6,1,4,1,14848,2,1,2,1,4,4 PortList = [port1, port2, port3, port4] count = 0 Communitystring = '' if (len(Communitystring) < 1) : print "warning: community string may not be empty" if (len(sys.argv) < 2) : print "Usage ./check_apc.py " sys.exit(-1) testHost = sys.argv[1] for Port in PortList : errorIndication, errorStatus, errorIndex, varBinds = cmdgen.CommandGenerator().getCmd( cmdgen.CommunityData('test', Communitystring, 0), cmdgen.UdpTransportTarget((testHost, 161)), (Port)) if (len(varBinds) == 0) : print "Status is CRITICAL - Host not replying" sys.exit(2) Var = varBinds[0][1] RetString += ' #' + str(count) + ': ' + str(Var) + 'C' count += 1 if (Var > Warningstart) : CurrentState = 1 if (Var > Criticalstart) : CurrentState = 2 if (CurrentState == 0) : print 'Status is OK - ' + RetString sys.exit(0) if (CurrentState == 1) : print 'Status is WARNING - ' + RetString sys.exit(1) if (CurrentState == 2) : print 'Status is CRITICAL - ' + RetString sys.exit(2)