Search
j0ke.net Open Build Service
>
Projects
>
server:monitoring
>
nagios-plugins-snmp
> check_snmp_apc_pdu.py
Sign Up
|
Log In
Username
Password
Cancel
Overview
Repositories
Revisions
Requests
Users
Advanced
Attributes
Meta
File check_snmp_apc_pdu.py of Package nagios-plugins-snmp (Revision 28)
Currently displaying revision
28
,
show latest
#!/usr/bin/python # check_snmp_apc_pdu plugin for nagios # # checks with SNMP the power status of APC PDUs # be sure to have the required MIB (PowerNet-MIB) ready in the snmp mib path # default path is /usr/share/snmp/mibs # # Copyright Notice: GPL # # History: # # v1.0 Rouven Homann - rouven.homann@cimt-ag.de # + Initial Release # v1.1 Eddy Mulyono - eddymul@gmail.com # + Python port import os import sys from getopt import getopt errors = { "OK": 0, "WARNING": 1, "CRITICAL": 2, "UNKNOWN": 3, } progname = "check_snmp_apc_pdu" progversion = "1.1" def apc_snmp(command, oid_tail): # private.enterprises.apc.hardware.rPDU rpdu = "iso.org.dod.internet.private.enterprises.318.1.1.12" common_options = "-t %(timeout)s -OvQ -v 1 -c %(community)s %(host)s" % { "timeout": opt_T, "community": opt_C, "host": opt_H, } return os.popen("snmp" + command + " " + common_options + " " + rpdu + oid_tail).readlines() def apc_snmp_get(oid_tail): return apc_snmp("get", oid_tail)[0].strip('\n') def apc_snmp_walk(oid_tail): return apc_snmp("walk", oid_tail) def snmpconnect(): apc_info = {} try: # rPDUIdent.rPDUIdentHardwareRev: apc_info['HardwareRev'] = apc_snmp_get(".1.2.0").strip('"') # rPDUIdent.rPDUIdentFirmwareRev: apc_info['FirmwareRev'] = apc_snmp_get(".1.3.0").strip('"') # rPDUIdent.rPDUIdentModelNumber: "AP7941" apc_info['model'] = apc_snmp_get(".1.5.0").strip('"') # rPDUIdent.rPDUIdentSerialNumber: "ZA0451015777" apc_info['serial'] = apc_snmp_get(".1.6.0").strip('"') # rPDUPowerSupply.rPDUPowerSupplyDevice.rPDUPowerSupply1Status: 1 r_pdu_power_supply_status = apc_snmp_walk(".4.1") apc_info['power1'] = r_pdu_power_supply_status[0].strip('\n') if len(r_pdu_power_supply_status) == 3: apc_info['power2'] = r_pdu_power_supply_status[1].strip('\n') else: apc_info['power2'] = "3" # rPDUOutlet.rPDUOutletDevice.rPDUOutletDevNumCntrlOutlets apc_info['ports'] = apc_snmp_get(".3.1.3.0") # rPDULoadStatus.rPDULoadStatusTable.rPDULoadStatusEntry.rPDULoadStatusLoad: 155 apc_info['load'] = int(apc_snmp_get(".2.3.1.1.2.3")) / 10 # rPDULoad.rPDULoadPhaseConfig.rPDULoadPhaseConfigTable.rPDULoadPhaseConfigEntry.rPDULoadPhaseConfigNearOverloadThreshold: 18 #apc_info['warning'] = apc_snmp_get(".2.2.1.1.3.1") apc_info['warning'] = apc_snmp_get(".2.4.1.1.3.1") # rPDULoad.rPDULoadPhaseConfig.rPDULoadPhaseConfigTable.rPDULoadPhaseConfigEntry.rPDULoadPhaseConfigOverloadThreshold: 24 #apc_info['critical'] = apc_snmp_get(".2.2.1.1.4.1") apc_info['critical'] = apc_snmp_get(".2.4.1.1.4.1") except: print sys.exc_info() errorexit() return apc_info def errorexit(): print "UNKNOWN: An error occured while running snmp command, possible wrong pdu or mib not present!" sys.exit(errors['UNKNOWN']); def print_usage(): print "Usage: %(progname)s -H <Hostname> -C <Community> [-T <timeout>] [-w <warn>] [-c <crit>] [-v] [-h]" % {"progname" : progname} if opt_h: pass else: sys.exit(errors["UNKNOWN"]) def print_help(): print_revision(progname, progversion) print "Copyright (c) 2005 Rouven Homann" print print_usage() print print "-H <Hostname> = Hostname or IP-Address." print "-C <Community> = Community read password." print "-T <timeout> = Timeout in seconds." print "-v = Verbose Output." print "-h = This screen." print support() def print_revision(progname, revision): pass def support(): pass def verbose_output(apc_info): return "Hardware Revision: %(HardwareRev)s, Firmware Revision: %(FirmwareRev)s, Model: %(model)s, Serial: %(serial)s, Power1: %(power1)s, Power2: %(power2)s, Ports %(ports)s, Load %(load)dA" % apc_info if __name__ == '__main__': opt_h = verbose = opt_w = opt_H = opt_C = opt_c = None opt_T = 1 opts, args = getopt(sys.argv[1:], "Vhvw:H:C:c:T:") for o, a in opts: if o in ("-V", "--version"): print_revision(progname, progversion) sys.exit(errors["UNKNOWN"]) if o in ("-h", "--help"): opt_h = True print_help() sys.exit(errors["UNKNOWN"]) if o in ("-v", "--verbose"): verbose = True if o in ("-w", "--warning"): opt_w = a if o in ("-H", "--host"): opt_H = a if o in ("-C", "--community"): opt_C = a if o in ("-c", "--critical"): opt_c = a if o in ("-T", "--timeout"): opt_T = a if opt_H and opt_C: pass else: print_usage() apc_info = snmpconnect() critical = None if opt_c: try: critical = int(opt_c) except ValueError: critical = apc_info['critical'] else: critical = apc_info['critical'] warning = None if opt_w: try: warning = int(opt_w) except ValueError: warning = apc_info['warning'] else: warning = apc_info['warning'] r_pdu_power_supply_status = {"1": "Ok", "2": "Failed", "3": "NotPresent"} # PDU's own Powerstatus for i in ('power1', 'power2'): apc_info[i] = r_pdu_power_supply_status[apc_info[i]] ## CRITICAL if critical <= apc_info['load'] or apc_info['power1'] == "Failed" or apc_info['power2'] == "Failed": if verbose: # Verbose output print "CRITICAL: " + verbose_output(apc_info) else: # Small output if apc_info['power1'] == "NotPresent" or apc_info['power2'] == "NotPresent": print "CRITICAL: Load Critical, %(load)dA reached!" % apc_info else: print "CRITICAL: Load Critical, %(load)dA reached!, Power1: %(power1)s, Power2: %(power2)s" % apc_info sys.exit(errors['CRITICAL']) ## WARNING elif warning <= apc_info['load'] < critical: if verbose: # Verbose output print "WARNING: " + verbose_output(apc_info) else: # Small output if apc_info['power1'] == "NotPresent" or apc_info['power2'] == "NotPresent": print "WARNING: Load Warning, %(load)dA reached!" % apc_info else: print "WARNING: Load Warning, %(load)dA reached!, Power1: %(power1)s, Power2: %(power2)s" % apc_info sys.exit(errors['WARNING']) ## OK elif apc_info['load'] < warning and apc_info['power1'] != "Failed" and apc_info['power2'] != "Failed": if verbose: # Verbose output print "OK: " + verbose_output(apc_info) else: # Small output if apc_info['power1'] == "NotPresent" or apc_info['power2'] == "NotPresent": print "OK: Load %(load)dA" % apc_info else: print "OK: Load %(load)dA, Power1: %(power1)s, Power2: %(power2)s" % apc_info sys.exit(errors['OK']) ## UNKNOWN else: print "UNKNOWN: An error occurred while running snmp command, check MIB and oids" print apc_info sys.exit(errors['UNKNOWN'])