Module: check_mk
Branch: master
Commit: 247c8365c623183d9a085e6b3f33f9cb0a946f85
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=247c8365c62318…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Thu Apr 25 11:41:30 2013 +0200
vsphere objects: show running state and running on
---
agents/special/agent_vsphere | 60 +++++++++++++++++++-----------------------
checks/esx_vsphere_objects | 16 ++++++++++-
2 files changed, 42 insertions(+), 34 deletions(-)
diff --git a/agents/special/agent_vsphere b/agents/special/agent_vsphere
index 70b2fcc..f8bc46b 100755
--- a/agents/special/agent_vsphere
+++ b/agents/special/agent_vsphere
@@ -176,6 +176,9 @@ except:
print "<<<check_mk>>>"
print "Version: %s" % host.get_api_version()
print "AgentOs: %s " % host.get_server_type()
+
+# Prepare list of all hosts systems
+all_hosts = host.get_hosts()
def debug(x):
pprint.pprint(inspect.getmembers(x))
@@ -221,27 +224,6 @@ def dump_list(l, indent):
print indent + "%d:" % nr
dump(v, indent + " ")
-
-pm = host.get_performance_manager()
-# h = host.get_hosts()
-# x = pm.get_entity_counters(h.keys()[0])
-# print x
-# sys.exit(0)
-
-# print h
-# for name, mor in h.items():
-# debug(mor)
-# x = pm.get_entity_counters(mor)
-# debug(x)
-# p = VIProperty(host, name)
-# debug(p.network[0].summary)
-#
-# # debug(p.network[0].summary.network.value)
-# # dump_list(p.network, "")
-# # debug(p)
-
-# sys.exit(0)
-
# List of counters:
# 'cpu.coreUtilization': 20,
# 'cpu.costop': 27,
@@ -413,7 +395,7 @@ pm = host.get_performance_manager()
def output_hostsystem_counters():
pm = host.get_performance_manager()
- for mor, name in host.get_hosts().items():
+ for mor, name in all_hosts.items():
if not opt_direct:
print '<<<<%s>>>>' % name
print '<<<esx_vsphere_counters:sep(124)>>>'
@@ -500,9 +482,6 @@ def output_mors(what, properties, direct=False):
# Convert property value using specified conversion function
data[p.Name] = properties[p.Name](p.Val)
- # Remember the total list of output objects. We will put this into
- # a special section
- object_collection.append((what, data["name"]))
name = data["name"].split()[0] # get rid of comment
# Output multiplexed Check_MK Agent output (new in version 1.2.3i1)
@@ -515,12 +494,23 @@ def output_mors(what, properties, direct=False):
print '<<<esx_vsphere_%s>>>' %
(what.replace('virtualmachine', 'vm'))
items = data.items()
items.sort()
+ running_on = ''
+ power_state = ''
for name, value in items:
if type(value) == tuple:
sections.append(value)
else:
+ if name == 'runtime.host':
+ running_on = value
+ elif name == 'runtime.powerState':
+ power_state = value
print '%s %s' % (name, value)
+ # Remember the total list of output objects. We will put this into
+ # a special section
+ object_collection.append([what, data["name"], running_on,
power_state])
+
+
# pprint.pprint(sections)
for section_name, section_lines in sections:
print '<<<%s>>>' % section_name
@@ -573,6 +563,9 @@ def conv_numeric_sensor_info(value):
# return pprint.pformat(inspect.getmembers(value))
+def conv_host(value):
+ return all_hosts.get(value)
+
if "datastore" in mortypes:
output_datastores()
@@ -611,11 +604,11 @@ if "hostsystem" in mortypes:
# we get is summary.runtime.powerState
if "virtualmachine" in mortypes:
output_mors("virtualmachine", {
- "name": str,
- "guestHeartbeatStatus": str,
- "summary.quickStats.overallCpuUsage": str,
- "summary.quickStats.overallCpuDemand": str,
- "summary.quickStats.uptimeSeconds": str,
+ "name": str,
+ "guestHeartbeatStatus": str,
+ "summary.quickStats.overallCpuUsage": str,
+ "summary.quickStats.overallCpuDemand": str,
+ "summary.quickStats.uptimeSeconds": str,
"summary.quickStats.overallCpuUsage": str,
"summary.quickStats.overallCpuDemand": str,
@@ -640,13 +633,14 @@ if "virtualmachine" in mortypes:
#"config.hardware.guestId": str,
#"config.hardware.uuid": str,
- "summary.runtime.powerState": str,
+ "runtime.powerState": str,
+ "runtime.host" : conv_host,
})
print "<<<<>>>>"
print "<<<esx_vsphere_objects:sep(9)>>>"
-for what, name in object_collection:
- print "%s\t%s" % (what, name)
+for entry in object_collection:
+ print "\t".join(entry)
host.disconnect()
diff --git a/checks/esx_vsphere_objects b/checks/esx_vsphere_objects
index 61d8db5..311c70a 100644
--- a/checks/esx_vsphere_objects
+++ b/checks/esx_vsphere_objects
@@ -50,10 +50,24 @@ def inventory_esx_vsphere_objects(info):
def check_esx_vsphere_objects(item, _no_params, info):
for line in info:
if vsphere_object_names[line[0]] + " " + line[1] == item:
- return 0, "information about this object present"
+ running_on = line[2]
+ power_state = line[3]
+ if power_state == "poweredOn":
+ state = 0
+ elif power_state == "poweredOff":
+ state = 1
+ elif power_state == "suspended":
+ state = 1
+ else:
+ state = 3
+ infotext = "power state: %s" % power_state
+ if running_on:
+ infotext += ', running on [%s]' % running_on
+ return state, infotext
what = item.split()[0]
name = item.split()[1]
+
if what == "VM":
return 3, "Virtual machine %s is missing" % name
else: