#!/usr/bin/env python # # Copyright 2010, Pall Sigurdsson # # This script 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 3 of the License, or # (at your option) any later version. # # This script 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, see . # About this script # # This script will check the status of a remote Lenovo System x server # # * fork the code from check_lenovo_flex.py # * changed the name to check_lenovo_imm.py # * added cpu, storage and memory # * added critical judgement for power and fans # * support python2.7 and python3.5 # # No real need to change anything below here version="1.0" ok=0 warning=1 critical=2 unknown=3 not_present = -1 exit_status = -1 state = {} state[not_present] = "Not Present" state[ok] = "OK" state[warning] = "Warning" state[critical] = "Critical" state[unknown] = "Unknown" longserviceoutput="\n" perfdata="" summary="" all_critical_info="" sys_health_msg="" sudo=False from sys import exit from sys import argv from sys import exc_info from os import getenv,putenv,environ from os import path, sep import subprocess from distutils.log import Log # Init log level to infor log = Log(2) printf = log.info import warnings warnings.filterwarnings("ignore") # Parse some Arguments from optparse import OptionParser parser = OptionParser() parser.add_option("-m","--mode", dest="mode", help="Which check mode is in use (all, power,cpu,storage,temperature,fans,voltage,memory)", default="all") parser.add_option("-H","--host", dest="host", help="Hostname or IP address of the host to check") parser.add_option("-w","--warning", dest="warning_threshold", help="Warning threshold", type="int", default=None) parser.add_option("-c","--critical", type="int", dest="critical_threshold", help="Critical threshold", default=None) parser.add_option("-e","--exclude", dest="exclude", help="Exclude specific object", default=None) parser.add_option("-v","--snmp_version", dest="snmp_version", help="SNMP Version to use (1, 2c or 3)", default="1") parser.add_option("-u","--snmp_username", dest="snmp_username", help="SNMP username (only with SNMP v3)", default=None) parser.add_option("-C","--snmp_community", dest="snmp_community", help="SNMP Community (only with SNMP v1|v2c)", default=None) parser.add_option("-p","--snmp_apassword", dest="snmp_apassword", help="SNMP authentication password (only with SNMP v3)", default=None) parser.add_option("-a","--snmp_aprotocol", dest="snmp_aprotocol", help="SNMP authentication protocol (SHA only with SNMP v3)", default=None) parser.add_option("-x","--snmp_ppassword", dest="snmp_ppassword", help="SNMP privacy password (only with SNMP v3)", default=None) parser.add_option("-X","--snmp_pprotocol", dest="snmp_pprotocol", help="SNMP privacy protocol AES||DES (only with SNMP v3)", default=None) parser.add_option("-l","--snmp_security_level", dest="snmp_seclevel", help="SNMP security level (only with SNMP v3) (noAuthNoPriv|authNoPriv|authPriv)", default=None) ## timeout, 1 means the timeout is 6 seconds, so we can set the time to 0.5(3s), 10(1minutes) parser.add_option("-t","--snmp_timeout", dest="snmp_timeout", help="Timeout in seconds for SNMP", default=5) parser.add_option("-d","--debug", dest="debug", help="Enable debugging (for troubleshooting)", action="store_true", default=False) (opts,args) = parser.parse_args() if opts.host == None: parser.error("Hostname (-H) is required.") if opts.mode == None: parser.error("Mode (--mode) is required.") snmp_options = "" def set_snmp_options(): global snmp_options if opts.snmp_version is not None: snmp_options = snmp_options + " -v%s" % opts.snmp_version if opts.snmp_version == "3": if opts.snmp_username is None: parser.error("--snmp_username required with --snmp_version=3") if opts.snmp_seclevel is None: parser.error("--snmp_security_level required with --snmp_version=3") if opts.snmp_seclevel == "noAuthNoPriv": snmp_options = snmp_options + " -l %s -u %s " % (opts.snmp_seclevel,opts.snmp_username) if opts.snmp_seclevel == "authNoPriv": if opts.snmp_apassword is None: parser.error("--snmp_apassword required with --snmp_version=3") if opts.snmp_aprotocol is None: parser.error("--snmp_aprotocol required with --snmp_version=3") snmp_options = snmp_options + " -l %s -u %s -a %s -A %s " % (opts.snmp_seclevel,opts.snmp_username,opts.snmp_aprotocol,opts.snmp_apassword) if opts.snmp_seclevel == "authPriv": if opts.snmp_pprotocol is None: parser.error("--snmp_pprotocol required with --snmp_version=3") if opts.snmp_ppassword is None: parser.error("--snmp_ppassword required with --snmp_version=3") if opts.snmp_apassword is None: parser.error("--snmp_apassword required with --snmp_version=3") if opts.snmp_aprotocol is None: parser.error("--snmp_aprotocol required with --snmp_version=3") snmp_options = snmp_options + " -l %s -u %s -a %s -A %s -x %s -X %s " % (opts.snmp_seclevel,opts.snmp_username,opts.snmp_aprotocol,opts.snmp_apassword,opts.snmp_pprotocol,opts.snmp_ppassword) else: if opts.snmp_community is None: parser.error("--snmp_community is required with --snmp_version=1|2c") snmp_options = snmp_options + " -c %s " % opts.snmp_community snmp_options += " -t %s " % (opts.snmp_timeout) def error(errortext): printf ("* Error: %s" % errortext) exit(unknown) def debug( debugtext ): if opts.debug: printf (debugtext) def nagios_status( newStatus ): global exit_status exit_status = max(exit_status, newStatus) return exit_status '''runCommand: Runs command from the shell prompt. Exit Nagios style if unsuccessful''' def runCommand(command): debug( "Executing: %s" % command ) proc = subprocess.Popen(command.split(), stdout=subprocess.PIPE,stderr=subprocess.PIPE,universal_newlines=True) stdout, stderr = proc.communicate('through stdin to stdout') if proc.returncode > 0: if proc.returncode == 1: # timeout printf ("server %s is not accessible at the moment" % opts.host) debug ("Error %s: %s\n command was: '%s'" % (proc.returncode,stderr.strip(),command)) debug("results: %s" % (stdout.strip() ) ) if proc.returncode == 127: # File not found, lets print path path=getenv("PATH") printf ("Check if your path is correct %s" % (path)) if stderr.find('Password:') == 0 and command.find('sudo') == 0: printf ("Check if user is in the sudoers file") if stderr.find('sorry, you must have a tty to run sudo') == 0 and command.find('sudo') == 0: printf ("Please remove 'requiretty' from /etc/sudoers") exit(unknown) else: return stdout def end(): global summary global longserviceoutput global perfdata global exit_status common_info = get_common_info() printf ("%s - %s | %s" % (state[exit_status], common_info + summary,perfdata)) printf (longserviceoutput) if exit_status < 0: exit_status = unknown exit(exit_status) def all_modules_end(): global all_critical_info global longserviceoutput global perfdata global exit_status global sys_health_msg common_info = get_common_info() printf ("%s - %s | %s" % (state[exit_status], common_info + all_critical_info,perfdata)) printf (sys_health_msg) if exit_status < 0: exit_status = unknown exit(exit_status) def add_perfdata(text): global perfdata text = text.strip() perfdata = perfdata + " %s " % (text) def add_long(text): global longserviceoutput longserviceoutput = longserviceoutput + text + '\n' def add_summary(text): global summary summary = summary + text def add_all_critical_info(text): global all_critical_info all_critical_info = all_critical_info + text def snmpget(oid): snmpgetcommand = "snmpget %s %s %s" % (snmp_options,opts.host,oid) output = runCommand(snmpgetcommand) oid,result = output.strip().split(' = ', 1) resultType,resultValue = result.split(': ',1) if resultType == 'STRING': # strip quotes of the string resultValue = resultValue[1:-1] return resultValue # snmpwalk -v3 -u v3get mgmt-rek-proxy-p02 -A proxy2011 -l authNoPriv 1.3.6.1.4.1.15497 def snmpwalk(base_oid): snmpwalkcommand = "snmpwalk %s %s %s" % (snmp_options, opts.host, base_oid) output = runCommand(snmpwalkcommand + " " + base_oid) return output def getTable(base_oid): myTable = {} output = snmpwalk(base_oid) for line in output.split('\n'): tmp = line.strip().split(' = ', 1) if len(tmp) == 2: oid,result = tmp else: result = result + tmp[0] # continue tmp = result.split(': ',1) if len(tmp) > 1: resultType,resultValue = tmp[0],tmp[1] else: resultType = None resultValue = tmp[0] if resultType == 'STRING': # strip quotes of the string resultValue = resultValue[1:-1] index = oid.strip().split('.') column = int(index.pop()) row = int(index.pop()) #if not myTable.has_key(column): myTable[column] = {} if column not in myTable: myTable[column] = {} myTable[column][row] = resultValue return myTable def format_info(tip_info, item_value): ret_format_info = "" for i in tip_info.keys(): if "" == item_value[i]: continue ret_format_info += tip_info[i] + item_value[i].strip() + "; " return ret_format_info def check_power(): #BASE OID # #IMM OID # # #PWR Mod OID # Integrated Management Module mib for SNMP: table contains power inventory information. Rack system only. powers = getTable('.1.3.6.1.4.1.2.3.51.3.1.11.2') index = 1 # powerIndex exists = 2 # powerFruName partnum = 3 # powerPartNumber details = 4 # powerFRUNumber serialnum = 5 # powerFRUSerialNumber status = 6 # powerHealthStatus tip_map = {2:"Name:", 3:"Part Number:", 4:"FRU Number:", 5:"Serial Number:"} num_ok = 0 for i in powers.values(): myIndex = i[index] myStatus = i[status] myDetails = i[details] myExists = i[exists] if myIndex == opts.exclude: continue if myStatus == "Normal": num_ok = num_ok + 1 elif myStatus == "Warning": nagios_status(warning) add_summary( '"%s" status "%s". ' % (myExists,myStatus) ) else: nagios_status(critical) add_summary( '"%s" status "%s".' % (myExists, myStatus) ) detail_info = format_info(tip_map, i) add_long('Power "%s" status "%s". %s' % (myIndex, myStatus, detail_info) ) add_summary( "%s out of %s power are healthy" % (num_ok, len(powers) ) ) if num_ok < len(powers): add_all_critical_info("%s out of %s power are healthy; " % (num_ok, len(powers))) nagios_status(ok) def check_fans(): #BASE OID # #IMM OID # # #PWR Mod OID #Integrated Management Module mib for SNMP: fan table fans = getTable('.1.3.6.1.4.1.2.3.51.3.1.3.2') fanIndex,fanDescr,fanSpeed,fanNonRecovLimitHigh,fanCritLimitHigh,fanNonCritLimitHigh,fanNonRecovLimitLow,fanCritLimitLow,fanNonCritLimitLow,fanHealthStatus = (1,2,3,4,5,6,7,8,9,10) num_ok = 0 tip_map = {2:"Name:", 3:"Speed:", 8:"Low Critical Limit speed:"} for i in fans.values(): myIndex = i[fanIndex] myStatus = i[fanHealthStatus] myDescr = i[fanDescr] if myIndex == opts.exclude: continue if myStatus == "Normal" or myStatus == "Unknown": num_ok = num_ok + 1 elif myStatus == "Warning": nagios_status(warning) add_summary( 'Fan "%s" status "%s". %s. ' % (myIndex,myStatus,myDescr) ) else: nagios_status(critical) add_summary( 'Fan "%s" status "%s". %s. ' % (myIndex, myStatus,myDescr) ) detail_info = format_info(tip_map, i) add_long('Fan "%s" status "%s". %s ' % (myIndex,myStatus, detail_info)) if "offline" != i[fanSpeed].lower(): add_perfdata("%s Speed(%%of Max.)=%s;" % (i[fanDescr], i[fanSpeed][0:i[fanSpeed].find("%")+1])) else: add_perfdata("%s Speed(%%of Max.)=0%%;" % i[fanDescr]) add_summary( "%s out of %s fans are healthy" % (num_ok, len(fans) ) ) if num_ok < len(fans): add_all_critical_info("%s out of %s fans are healthy; " % (num_ok, len(fans))) nagios_status(ok) def check_systemhealth(): #Integrated Management Module mib for SNMP: status of system health for the system in which the XCC resides systemhealthstat = snmpget('1.3.6.1.4.1.2.3.51.3.1.4.1.0') index,severity,description = (1,2,3) global sys_health_msg # Check overall health if systemhealthstat == '255': nagios_status(ok) add_summary("Server health: OK. ") elif systemhealthstat == "2": nagios_status(warning) add_summary("Non-Critical Error. ") elif systemhealthstat == "4": nagios_status(critical) add_summary("System-Level Error. ") elif systemhealthstat == "0": nagios_status(critical) add_summary("Critical. ") else: nagios_status(unknown) add_summary("Server health unknown (oid 1.3.6.1.4.1.2.3.51.3.1.4.1.0 returns %s). " % systemhealthstat) if systemhealthstat == "2" or systemhealthstat == "4" or systemhealthstat == "0": summary = getTable('1.3.6.1.4.1.2.3.51.3.1.4.2') for row in summary.values(): if row[severity] == 'Good': nagios_status(ok) elif row[severity] == 'Warning': nagios_status(warning) else: nagios_status(critical) text_row_description = row[description] # text_row_description = text_row_description.replace(" ", "") # text_row_description = text_row_description.decode("hex") #add_summary( "[%s] %s " % (row[severity], text_row_description) ) add_long( "*[%s] %s " % (row[severity], text_row_description) ) sys_health_msg += "*[%s] %s \n" % (row[severity], text_row_description) def check_temperature(): # set some sensible defaults if opts.warning_threshold is None: opts.warning_threshold = 28 if opts.critical_threshold is None: opts.critical_threshold = 35 #BASE OID # #IMM OID # # #Temp OID #Integrated Management Module mib for SNMP : temperature measurement information. temperatures = getTable("1.3.6.1.4.1.2.3.51.3.1.1.2") tempIndex,tempDescr,tempReading,tempNominalReading,tempNonRecovLimitHigh,tempCritLimitHigh,tempNonCritLimitHigh,tempNonRecovLimitLow,tempCritLimitLow,tempNonCritLimitLow,tempHealthStatus = (1,2,3,4,5,6,7,8,9,10,11) num_ok = 0 tip_map = {2:"Name:", 3:"Measured Temperature:", 4:"Nominal Temperature:", 5:"non-recoverable limit:", 6:"critical limit:"} for i in temperatures.values(): myIndex = i[tempIndex] myStatus = i[tempHealthStatus] myDetails = i[tempDescr] myTemp = i[tempReading] myTempCritLimitHigh = i[tempCritLimitHigh] if myTempCritLimitHigh == "N/A": myTempCritLimitHigh = "" myTempNonCritLimitHigh = i[tempNonCritLimitHigh] if myTempNonCritLimitHigh == "N/A": myTempNonCritLimitHigh = "" if myIndex == opts.exclude: continue if myStatus != "Normal": nagios_status(warning) add_summary( 'Temparature "%s" status "%s". %s. ' % (myIndex,myStatus,myDetails) ) else: num_ok = num_ok + 1 detail_info = format_info(tip_map, i) add_long('Temperature "%s" status "%s". %s' % (myIndex,myStatus, detail_info) ) add_perfdata("%s(degrees C)=%s;" % (i[tempDescr], i[tempNominalReading])) add_summary( "%s out of %s temperature are healthy" % (num_ok, len(temperatures) ) ) if num_ok < len(temperatures): add_all_critical_info("%s out of %s temperature are healthy; " % (num_ok, len(temperatures))) nagios_status(ok) def check_voltage(): #Integrated Management Module mib for SNMP : voltage measurement information. voltages = getTable(".1.3.6.1.4.1.2.3.51.3.1.2.2") voltIndex,voltDescr,voltReading,voltNominalReading,voltNonRecovLimitHigh,voltCritLimitHigh,voltNonCritLimitHigh,voltNonRecovLimitLow,voltCritLimitLow,voltNonCritLimitLow,voltHealthStatus = (1,2,3,4,5,6,7,8,9,10,11) tip_map = {2:"Name:", 3:"Measured Voltage:", 4:"Nominal Voltage:", 6:"High Critical limit:", 9:"Low Critical Limit:"} num_ok = 0 for i in voltages.values(): myIndex = i[voltIndex] myStatus = i[voltHealthStatus] myDescr = i[voltDescr] myVolt = i[voltReading] myVoltCritLimitHigh = i[voltCritLimitHigh] if myVoltCritLimitHigh == "N/A": myVoltCritLimitHigh = "" myVoltNonCritLimitHigh = i[voltNonCritLimitHigh] if myVoltNonCritLimitHigh == "N/A": myVoltNonCritLimitHigh = "" if myIndex == opts.exclude: continue if myStatus != "Normal": nagios_status(warning) add_summary( 'Voltage "%s" status "%s". %s. ' % (myIndex,myStatus,myDescr) ) else: num_ok = num_ok + 1 detail_info = format_info(tip_map, i) add_long('Voltage "%s" status "%s". %s' % (myIndex,myStatus, detail_info)) add_perfdata("%s Reading=%sV;" % (myDescr, myVolt)) add_summary( "%s out of %s voltages are healthy" % (num_ok, len(voltages) ) ) if num_ok < len(voltages): add_all_critical_info("%s out of %s voltages are healthy; " % (num_ok, len(voltages))) nagios_status(ok) def check_cpu(): #Integrated Management Module mib for SNMP: System CPU VPD cpus = getTable("1.3.6.1.4.1.2.3.51.3.1.5.20.1") cpuVpdIndex,cpuVpdDescription,cpuVpdSpeed,cpuVpdIdentifier,cpuVpdType,cpuVpdFamily,cpuVpdCores,cpuVpdThreads,cpuVpdVoltage,cpuVpdDataWidth,cpuVpdHealthStatus,cpuVpdCpuModel = (1,2,3,4,5,6,7,8,9,10,11,12) num_ok = 0 tip_map = {2:"Name:", 3:"Speed:", 5:"Type:", 6:"Family:", 7:"Number of Cores:", 9:"Voltage(mV):", 10:"Data Width(bits):", 12:"Model:"} for i in cpus.values(): myIndex = i[cpuVpdIndex] myStatus = i[cpuVpdHealthStatus] myDescr = i[cpuVpdDescription] if myIndex == opts.exclude: continue if myStatus == "Normal": num_ok = num_ok + 1 elif myStatus == "Warning": nagios_status(warning) else: nagios_status(critical) detail_info = format_info(tip_map, i) add_long('"%s" status "%s". %s' % (myDescr, myStatus, detail_info) ) add_summary('%s out of %s CPUs are healthy.' % (num_ok, len(cpus)) ) if num_ok < len(cpus): add_all_critical_info('%s out of %s CPUs are healthy; ' % (num_ok, len(cpus)) ) nagios_status(ok) def check_storage(): #Integrated Management Module mib for SNMP: disk module inventory channel disks = getTable(".1.3.6.1.4.1.2.3.51.3.1.12") diskIndex,diskFruName,diskHealthStatus = (1,2,3) num_ok = 0 check_raid() for i in disks.values(): myIndex = i[diskIndex] myFruName = i[diskFruName] myStatus = i[diskHealthStatus] if myIndex == opts.exclude: continue if myStatus == "Normal": num_ok = num_ok + 1 elif myStatus == "Warning": nagios_status(warning) else: nagios_status(critical) add_long('Physical Disk "%s" status "%s". ' % (myFruName, myStatus)) add_summary('%s out of %s disks are healthy.' % (num_ok, len(disks)) ) if num_ok < len(disks): add_all_critical_info('%s out of %s disks are healthy; ' % (num_ok, len(disks))) nagios_status(ok) def check_raid(): try: add_long("-------------RAID Controller information------") check_raid_controller() check_raid_controller_firmware() check_raid_volume() add_long("-------------Drive in RAID Controller---------") check_raid_drive() check_raid_drive_firmware() add_long("-------------Pyhsical Drive List--------------") except: debug("Failed in getting raid info") def check_raid_controller(): try: #Integrated Management Module mib for SNMP : Local Storage RAID Controller information raid_ctrl = getTable(".1.3.6.1.4.1.2.3.51.3.1.13.1.2") raidCtrlIndex = (1) tip_map = {2:"Name:", 4:"Firmware Version:", 6:"Manufacture:", 7:"UUID:", 9:"Type:", 10:"Serial Number:", 11:"FRU Number:", 12:"Part No.:", 38:"Drives List:"} for i in raid_ctrl.values(): myIndex = i[raidCtrlIndex] detail_info = format_info(tip_map, i) add_long ("RAID Ctrl %s: %s" % (myIndex, detail_info)) except: debug("Failed in getting raid controller") def check_raid_controller_firmware(): try: #Integrated Management Module mib for SNMP: Logic Storage RAID Controller Firmware information. raid_ctrl_firmware = getTable(".1.3.6.1.4.1.2.3.51.3.1.13.1.4") tip_map = {5:"Firmware Manfacture:", 7:"Firmware Release Data:"} for i in raid_ctrl_firmware.values(): myIndex = i[1] detail_info = format_info(tip_map, i) add_long ("RAID Ctrl %s: %s" % (myIndex, detail_info)) except: debug("Failed in getting raid controller firmware") def check_raid_drive(): try: #Integrated Management Module mib for SNMP : RAID Drive Information raid_drive = getTable(".1.3.6.1.4.1.2.3.51.3.1.13.1.3") tip_map = {2:"Drive Name:", 3:"Product Name:", 4:"state:", 5:"Slot No.:", 7:"Disk Type:", 8:"Media Type:", 9:"Speed:", 10:"Current Temperature:", 12:"Capacity:", 13:"Manufacture:", 17:"Serial No.:", 18:"FRU No.:", 19:"Part No.:"} for i in raid_drive.values(): myIndex = i[1] detail_info = format_info(tip_map, i) add_long ("%s" % (detail_info)) except: debug("Failed in getting raid drive") def check_raid_drive_firmware(): try: #Integrated Management Module mib for SNMP : Logic Storage RAID Drive Firmware information raid_drive_firmware = getTable(".1.3.6.1.4.1.2.3.51.3.1.13.1.5") tip_map = {3:"Name:" ,6:"Firmware Version:"} for i in raid_drive_firmware.values(): myIndex = i[1] detail_info = format_info(tip_map, i) add_long ("%s" % ( detail_info)) except: debug("Failed in getting raid drive firmware") def check_raid_volume(): try: #Integrated Management Module mib for SNMP : Logic Storage RAID Volume information. raid_volume = getTable(".1.3.6.1.4.1.2.3.51.3.1.13.1.7") tip_map = {3:"RAID Ctrl:", 2:"Volume Name:", 4:"Status:", 5:"Capacity:"} for i in raid_volume.values(): myIndex = i[1] detail_info = format_info(tip_map, i) add_long ("%s" % (detail_info)) except: debug("Failed in getting raid volume") def check_memory(): #Integrated Management Module mib for SNMP: system Memory VPD information memory = getTable("1.3.6.1.4.1.2.3.51.3.1.5.21") memoryVpdIndex,memoryVpdDescription,memoryVpdPartNumber,memoryVpdFRUSerialNumber,memroyVpdManufactureDate,memoryVpdType,memoryVpdSize,memoryHealthStatus,memoryConfigSpeed,memoryRatedSpeed,memoryLenovoPartNumber = (1,2,3,4,5,6,7,8,9,10,11) num_ok = 0 tip_map = {2:"Name:", 3:"Part Number:", 4:"Serial Number:", 5:"Manufacture Date:", 6:"Type:", 7:"Size:", 9:"Config Speed:", 9:"Rated Speed:"} for i in memory.values(): myIndex = i[memoryVpdIndex] myStatus = i[memoryHealthStatus] myDescr = i[memoryVpdDescription] if myIndex == opts.exclude: continue if myStatus == "Normal": num_ok = num_ok + 1 elif myStatus == "Warning": nagios_status(warning) else: nagios_status(critical) detail_info = format_info(tip_map, i) add_long('"%s" status "%s". %s' % (myDescr, myStatus, detail_info)) add_summary('%s out of %s memory are healthy.' % (num_ok, len(memory)) ) if num_ok < len(memory): add_all_critical_info('%s out of %s memory are healthy; ' % (num_ok, len(memory)) ) nagios_status(ok) def get_common_info(): machineproductname="" machinetype="" machinemode="" machinesn="" try: # Integrated Management Module mib for SNMP : Machine VPD information machineproductname = snmpget('.1.3.6.1.4.1.2.3.51.3.1.5.2.1.5.0') machinetype = snmpget('.1.3.6.1.4.1.2.3.51.3.1.5.2.1.1.0') machinemode = snmpget('.1.3.6.1.4.1.2.3.51.3.1.5.2.1.2.0') machinesn = snmpget('.1.3.6.1.4.1.2.3.51.3.1.5.2.1.3.0') except: debug("Failed in get common info") common_info = 'System: "%s"; MTM: "%s%s"; SN: "%s"; ' % (machineproductname.strip(), machinetype.strip(), machinemode.strip(), machinesn.strip()) return common_info def check_all_modules(): check_power() check_temperature() check_fans() check_voltage() check_cpu() check_storage() check_memory() check_systemhealth() if __name__ == '__main__': try: set_snmp_options() if opts.mode == 'all': check_all_modules() #check_raid() elif opts.mode == 'power': check_power() elif opts.mode == 'temperature': check_temperature() elif opts.mode == 'fans': check_fans() elif opts.mode == 'voltage': check_voltage() elif opts.mode == 'cpu': check_cpu() elif opts.mode == 'storage': check_storage() elif opts.mode == 'memory': check_memory() else: parser.error("%s is not a valid option for --mode" % opts.mode) except: #printf ("Unhandled exception while running script " ) infor = exc_info() debug ("%s : %s" % (infor[0], infor[1])) exit(unknown) if opts.mode == 'all': all_modules_end() else: end()