Search
j0ke.net Open Build Service
>
Projects
>
server:monitoring
:
icinga
:
production
>
nagios-plugins-vmware-esxi
> check_esxi_wbem.py
Sign Up
|
Log In
Username
Password
Cancel
Overview
Repositories
Revisions
Requests
Users
Advanced
Attributes
Meta
File check_esxi_wbem.py of Package nagios-plugins-vmware-esxi
#!/usr/bin/python # -*- coding: UTF-8 -*- # # Script for checking global health of host running VMware ESX/ESXi # # Licence : GNU General Public Licence (GPL) http://www.gnu.org/ # Pre-req : pywbem # #@--------------------------------------------------- #@ History #@--------------------------------------------------- #@ Date : 20080820 #@ Author : David Ligeret #@ Reason : Initial release #@--------------------------------------------------- #@ Date : 20080821 #@ Author : David Ligeret #@ Reason : Add verbose mode #@--------------------------------------------------- #@ Date : 20090219 #@ Author : Joshua Daniel Franklin #@ Reason : Add try/except to catch AuthError and CIMError #@--------------------------------------------------- #@ Date : 20100202 #@ Author : Branden Schneider #@ Reason : Added HP Support (HealthState) #@--------------------------------------------------- #@ Date : 20100512 #@ Author : Claudio Kuenzler www.claudiokuenzler.com #@ Reason : Combined different versions (Joshua and Branden) #@ Reason : Added hardware type switch (dell or hp) #@--------------------------------------------------- #@ Date : 20100626/28 #@ Author : Samir Ibradzic www.brastel.com #@ Reason : Added basic server info #@ Reason : Wanted to have server name, serial number & bios version at output #@ Reason : Set default return status to Unknown #@--------------------------------------------------- import sys import time import pywbem NS = 'root/cimv2' # define classes to check 'OperationStatus' instance ClassesToCheck = [ 'OMC_SMASHFirmwareIdentity', 'CIM_Chassis', 'CIM_ComputerSystem', 'CIM_NumericSensor', 'CIM_Memory', 'CIM_Processor', 'CIM_RecordLog', 'OMC_DiscreteSensor', 'OMC_Fan', 'OMC_PowerSupply', 'VMware_StorageExtent', 'VMware_Controller', 'VMware_StorageVolume', 'VMware_Battery', 'VMware_SASSATAPort' ] # define exit codes ExitOK = 0 ExitWarning = 1 ExitCritical = 2 ExitUnknown = 3 def verboseoutput(message, verbose) : if verbose == 1: print "%s %s" % (time.strftime("%Y%m%d %H:%M:%S"), message) # check input arguments if len(sys.argv) < 5: sys.stderr.write('Usage : ' + sys.argv[0] + ' hostname user password system [verbose]\n') sys.stderr.write('Example : ' + sys.argv[0] + ' https://myesxi:5989 root password dell verbose\n') sys.exit(1) verbose = 0 if len(sys.argv) > 5 : if sys.argv[5] == "verbose" : verbose = 1 # connection to host verboseoutput("Connection to "+sys.argv[1], verbose) wbemclient = pywbem.WBEMConnection(sys.argv[1], (sys.argv[2], sys.argv[3]), NS) # run the check for each defined class GlobalStatus = ExitUnknown server_info = "" bios_info = "" ExitMsg = "" for classe in ClassesToCheck : verboseoutput("Check classe "+classe, verbose) try: instance_list = wbemclient.EnumerateInstances(classe) except pywbem.cim_operations.CIMError,args: verboseoutput("Unknown CIM Error: %s" % args, verbose) except pywbem.cim_http.AuthError,arg: verboseoutput("GLobal exit set to CRITICAL", verbose) GlobalStatus = ExitCritical ExitMsg = " : Authentication Error! " else: GlobalStatus = ExitOK for instance in instance_list : elementName = instance['ElementName'] verboseoutput("Element Name = "+elementName, verbose) # BIOS & Server info if instance['ElementName'] == 'System BIOS' : bios_info = instance[u'Name'] + ': ' \ + instance[u'VersionString'] + ' ' \ + str(instance[u'ReleaseDate'].datetime.date()) if instance['ElementName'] == 'Chassis' : server_info = instance[u'Manufacturer'] + ' ' \ + instance[u'Model'] + ' s/n: ' \ + instance[u'SerialNumber'] # HP Check if sys.argv[4] == "hp" : if instance['HealthState'] is not None : elementStatus = instance['HealthState'] verboseoutput("Element HealthState = %d" % elementStatus, verbose) interpretStatus = { 0 : ExitOK, # Unknown 5 : ExitOK, # OK 10 : ExitWarning, # Degraded 15 : ExitWarning, # Minor 20 : ExitCritical, # Major 25 : ExitCritical, # Critical 30 : ExitCritical, # Non-recoverable Error }[elementStatus] if (interpretStatus == ExitCritical) : verboseoutput("GLobal exit set to CRITICAL", verbose) GlobalStatus = ExitCritical ExitMsg += " CRITICAL : %s " % elementName if (interpretStatus == ExitWarning and GlobalStatus != ExitCritical) : verboseoutput("GLobal exit set to WARNING", verbose) GlobalStatus = ExitWarning ExitMsg += " WARNING : %s " % elementName # Dell Check if sys.argv[4] == "dell" : if instance['OperationalStatus'] is not None : elementStatus = instance['OperationalStatus'][0] verboseoutput("Element Op Status = %d" % elementStatus, verbose) interpretStatus = { 0 : ExitOK, # Unknown 1 : ExitCritical, # Other 2 : ExitOK, # OK 3 : ExitWarning, # Degraded 4 : ExitWarning, # Stressed 5 : ExitWarning, # Predictive Failure 6 : ExitCritical, # Error 7 : ExitCritical, # Non-Recoverable Error 8 : ExitWarning, # Starting 9 : ExitWarning, # Stopping 10 : ExitCritical, # Stopped 11 : ExitOK, # In Service 12 : ExitWarning, # No Contact 13 : ExitCritical, # Lost Communication 14 : ExitCritical, # Aborted 15 : ExitOK, # Dormant 16 : ExitCritical, # Supporting Entity in Error 17 : ExitOK, # Completed 18 : ExitOK, # Power Mode 19 : ExitOK, # DMTF Reserved 20 : ExitOK # Vendor Reserved }[elementStatus] if (interpretStatus == ExitCritical) : verboseoutput("GLobal exit set to CRITICAL", verbose) GlobalStatus = ExitCritical ExitMsg += " CRITICAL : %s " % elementName if (interpretStatus == ExitWarning and GlobalStatus != ExitCritical) : verboseoutput("GLobal exit set to WARNING", verbose) GlobalStatus = ExitWarning ExitMsg += " WARNING : %s " % elementName if GlobalStatus == ExitOK : print "OK - Server: %s %s" % (server_info, bios_info) elif GlobalStatus == ExitUnknown : print "UNKNOWN" + ExitMsg else: print "%s - Server: %s %s" % (ExitMsg, server_info, bios_info) sys.exit (GlobalStatus)