Skip to content

Commit

Permalink
Update to newer pywbem exception call
Browse files Browse the repository at this point in the history
  • Loading branch information
Napsty committed Feb 14, 2025
1 parent 99f409b commit 6e1e1df
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions check_esxi_hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@
import re
import json
from optparse import OptionParser,OptionGroup
from packaging.version import Version

version = '20250214'

Expand Down Expand Up @@ -741,6 +742,16 @@ def handler(signum, frame):
verboseoutput("Connection to "+hosturl)
wbemclient = pywbem.WBEMConnection(hosturl, (user,password), NS, no_verification=True)

# Backward compatibility for pywbem <= 1.0.0
if Version(pywbemversion) >= Version("1.0.0"):
verboseoutput("pywbem is 1.0.0 or newer")
import pywbem._cim_operations as PywbemCimOperations
import pywbem._cim_http as PywbemCimHttp
else:
verboseoutput("pywbem is older than 1.0.0")
import pywbem.cim_operations as PywbemCimOperations
import pywbem.cim_http as PywbemCimHttp

# Add a timeout for the script. When using with Nagios, the Nagios timeout cannot be < than plugin timeout.
if on_windows == False and timeout > 0:
signal.signal(signal.SIGALRM, handler)
Expand All @@ -758,7 +769,7 @@ def handler(signum, frame):
if vendor=='auto':
try:
c=wbemclient.EnumerateInstances('CIM_Chassis')
except pywbem._cim_operations.CIMError as args:
except PywbemCimOperations.CIMError as args:
if ( args[1].find('Socket error') >= 0 ):
print("UNKNOWN: {}".format(args))
sys.exit (ExitUnknown)
Expand All @@ -771,7 +782,7 @@ def handler(signum, frame):
GlobalStatus = ExitUnknown
print("UNKNOWN: {}".format(args))
sys.exit (GlobalStatus)
except pywbem._cim_http.AuthError as arg:
except PywbemCimHttp.AuthError as arg:
verboseoutput("Global exit set to UNKNOWN")
GlobalStatus = ExitUnknown
print("UNKNOWN: Authentication Error")
Expand All @@ -793,7 +804,7 @@ def handler(signum, frame):
verboseoutput("Check classe "+classe)
try:
instance_list = wbemclient.EnumerateInstances(classe)
except pywbem._cim_operations.CIMError as args:
except PywbemCimOperations.CIMError as args:
if ( args[1].find('Socket error') >= 0 ):
print("UNKNOWN: {}".format(args))
sys.exit (ExitUnknown)
Expand All @@ -806,7 +817,7 @@ def handler(signum, frame):
GlobalStatus = ExitUnknown
print("UNKNOWN: {}".format(args))
sys.exit (GlobalStatus)
except pywbem._cim_http.AuthError as arg:
except PywbemCimHttp.AuthError as arg:
verboseoutput("Global exit set to UNKNOWN")
GlobalStatus = ExitUnknown
print("UNKNOWN: Authentication Error")
Expand Down

0 comments on commit 6e1e1df

Please sign in to comment.