Module: check_mk
Branch: master
Commit: df527c33c484b5b952fa644ce639c8033be503c8
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=df527c33c484b5…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Mon Apr 29 15:12:21 2013 +0200
esx_vsphere_vm: skip CPU check if VM is powered off
---
checks/esx_vsphere_vm | 6 +++++-
modules/check_mk_base.py | 7 +++++--
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/checks/esx_vsphere_vm b/checks/esx_vsphere_vm
index 8c9df6f..59e4bef 100644
--- a/checks/esx_vsphere_vm
+++ b/checks/esx_vsphere_vm
@@ -179,7 +179,11 @@ def inventory_esx_vsphere_vm_cpu(info):
return [(None, None)]
def check_esx_vsphere_vm_cpu(_no_item, _no_params, info):
- data = esx_vsphere_vm_convert(info)
+ data = esx_vsphere_vm_convert(info)
+ # VMs that are currently down do not have this entry
+ if 'summary.quickStats.overallCpuUsage' not in data:
+ raise MKCounterWrapped("", "No information about CPU usage. VM is
probably powered off.")
+
usage_mhz = int(data['summary.quickStats.overallCpuUsage'][0])
cpus = int(data['config.hardware.numCPU'][0])
return 0, "demand is %.3f Ghz, %d virtual CPUs" % (usage_mhz / 1000.0,
cpus), [ ("demand", usage_mhz) ]
diff --git a/modules/check_mk_base.py b/modules/check_mk_base.py
index 4bcb900..6bd27d6 100755
--- a/modules/check_mk_base.py
+++ b/modules/check_mk_base.py
@@ -121,7 +121,10 @@ class MKCounterWrapped(Exception):
self.name = countername
self.reason = reason
def __str__(self):
- return '%s: %s' % (self.name, self.reason)
+ if self.name:
+ return '%s: %s' % (self.name, self.reason)
+ else:
+ return self.reason
class MKAgentError(Exception):
def __init__(self, reason):
@@ -1063,7 +1066,7 @@ def do_all_checks_on_host(hostname, ipaddress, only_check_types =
None):
# any check result in that case:
except MKCounterWrapped, e:
if opt_verbose:
- print "Counter wrapped, not handled by check, ignoring this
check result: %s" % e
+ print "Cannot compute check result: %s" % e
dont_submit = True
except Exception, e:
result = (3, "invalid output from agent, invalid check parameters or
error in implementation of check %s. Please set <tt>debug_log</tt> to a
filename in <tt>main.mk</tt> for enabling exception logging." %
checkname)