Module: check_mk
Branch: master
Commit: 1e635bc6e0b180f270e32a169e4089a02c3fb02c
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=1e635bc6e0b180…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Wed Dec 4 14:42:08 2013 +0100
The vCenter agent is now also able to handle the option -p
---
.werks/238 | 1 -
agents/special/agent_vsphere | 3 +-
agents/special/agent_vsphere.pysphere | 47 +++++++++++++++++++++++++------
checks/agent_vsphere | 5 ++--
web/plugins/wato/datasource_programs.py | 3 +-
5 files changed, 43 insertions(+), 16 deletions(-)
diff --git a/.werks/238 b/.werks/238
index 2bbe504..6aa4f15 100644
--- a/.werks/238
+++ b/.werks/238
@@ -8,6 +8,5 @@ Class: feature
When using a Site Recovery Manager (SRM) some of the virtualmachines are only
used as fallback. The new agent_vsphere option -p allows to suppress any output
regarding placeholder vms.
-Right now this option only works when querying a host system.
Placeholder vms are identified by not having an assigned VirtualDisk Device.
The option is also configurable via the WATO rule "Check state of VMWare ESX via
vSphere"
diff --git a/agents/special/agent_vsphere b/agents/special/agent_vsphere
index f99d9a5..94a4f44 100755
--- a/agents/special/agent_vsphere
+++ b/agents/special/agent_vsphere
@@ -129,11 +129,10 @@ OPTIONS:
-s SECRET, --secret SECRET Secret/Password for vSphere login
-D, --direct Assume a directly queried host system (no vCenter). In
This we expect data about only one HostSystem to be
- Found and do not create piggy host data for that host.
+ found and do not create piggy host data for that host.
-p, Skip placeholder virtualmachines. These backup vms are
created
by the Site Recovery Manager (SRM) and are identified by
not
having any assigned virtual disks.
- Found and do not create piggy host data for that host.
-H, --hostname Specify a hostname. This is neccessary if this is
different from HOST. It is being used when outputting
the hosts power state.
diff --git a/agents/special/agent_vsphere.pysphere
b/agents/special/agent_vsphere.pysphere
index 45402e7..658037c 100755
--- a/agents/special/agent_vsphere.pysphere
+++ b/agents/special/agent_vsphere.pysphere
@@ -53,6 +53,9 @@ OPTIONS:
-D, --direct Assume a directly queried host system (no vCenter). In
This we expect data about only one HostSystem to be
Found and do not create piggy host data for that host.
+ -p, Skip placeholder virtualmachines. These backup vms are
created
+ by the Site Recovery Manager (SRM) and are identified by
not
+ having any assigned virtual disks.
-H, --hostname Specify a hostname. This is neccessary if this is
different from HOST. It is being used in --direct
mode as the name of the host system when outputting
@@ -79,7 +82,7 @@ OPTIONS:
""")
-short_options = 'hi:u:s:Dat:H:c'
+short_options = 'hi:u:s:Dat:H:cp'
long_options = [
'help', 'user=', 'secret=', 'direct',
'agent', 'debug', 'modules=', 'timeout=',
'hostname=',
'dump-counters', 'profile'
@@ -91,12 +94,13 @@ except getopt.GetoptError, err:
sys.stderr.write("%s\n" % err)
sys.exit(1)
-opt_debug = False
-opt_direct = False
-opt_agent = False
-opt_dump_counters = False
-opt_timeout = 60
-opt_hostname = None
+opt_debug = False
+opt_direct = False
+opt_agent = False
+opt_dump_counters = False
+opt_timeout = 60
+opt_hostname = None
+opt_skip_placeholder_vm = False
g_profile = None
g_profile_path = "vsphere_profile.out"
@@ -117,6 +121,8 @@ for o,a in opts:
opt_direct = True
elif o in [ '-a', '--agent' ]:
opt_agent = True
+ elif o in [ '-p' ]:
+ opt_skip_placeholder_vm = True
elif o in [ '-u', '--user' ]:
user = a
elif o in [ '-s', '--secret' ]:
@@ -547,6 +553,27 @@ def output_mors(what, properties, direct=False):
if not mors:
return
+ # Filter placeholder virtual machines
+ if obj_type == MORTypes.VirtualMachine and opt_skip_placeholder_vm:
+ used_mors = []
+ for mor in mors:
+ found_virtual_disk = False
+ for p in mor.PropSet:
+ if p.Name == "config.hardware.device":
+ try:
+ devices = p.Val.get_element_VirtualDevice()
+ for entry in devices:
+ if entry.typecode.type == ('urn:vim25',
'VirtualDisk'):
+ found_virtual_disk = True
+ break
+ except:
+ # If this property fails it is something different -> let it
pass
+ found_virtual_disk = True
+ break
+ if found_virtual_disk:
+ used_mors.append(mor)
+ mors = used_mors
+
for mor in mors:
sections = []
count += 1
@@ -609,7 +636,7 @@ def output_datastores():
property_names += [
"summary.maintenanceMode",
]
-
+
# print inspect.getmembers(MORTypes)
print "<<<esx_vsphere_datastores:sep(%d)>>>" %
ord('\t')
for mor in host._retrieve_properties_traversal(property_names=property_names,
obj_type=MORTypes.Datastore):
@@ -699,7 +726,7 @@ vm_propertys = {
"summary.quickStats.overallCpuDemand": str,
"summary.quickStats.staticCpuEntitlement": str,
"summary.quickStats.distributedCpuEntitlement": str,
-
+
# Memory
"summary.quickStats.guestMemoryUsage": str,
"summary.quickStats.hostMemoryUsage": str,
@@ -715,6 +742,8 @@ vm_propertys = {
# Virtual machine configuration
"config.hardware.memoryMB": str,
"config.hardware.numCPU": str,
+ "config.hardware.device": lambda x: "unused", # unused in
check
+ # we need it to determine placeholder
vms
#"config.hardware.hwVersion": str,
#"config.hardware.guestId": str,
#"config.hardware.uuid": str,
diff --git a/checks/agent_vsphere b/checks/agent_vsphere
index d6843b2..afb7462 100644
--- a/checks/agent_vsphere
+++ b/checks/agent_vsphere
@@ -46,8 +46,9 @@ def agent_vsphere_arguments(params, hostname, ipaddress):
args += ' --agent'
elif direct:
args += ' --direct --hostname ' + quote_shell_string(hostname)
- if params.get("skip_placeholder_vms"):
- args += " -p"
+
+ if params.get("skip_placeholder_vms"):
+ args += " -p"
if "timeout" in params:
args += ' --timeout %d' % params["timeout"]
diff --git a/web/plugins/wato/datasource_programs.py
b/web/plugins/wato/datasource_programs.py
index 42aaaf5..e84830a 100644
--- a/web/plugins/wato/datasource_programs.py
+++ b/web/plugins/wato/datasource_programs.py
@@ -103,8 +103,7 @@ register_rule(group,
FixedValue(True, title = _("Skip placeholder VMs"),
totext="",
help = _("Placeholder VMs are created by the Site Recovery
Manager(SRM) and act as backup "
"virtual machines in case the default vm is
unable to start. This option tells the "
- "vsphere agent to exclude placeholder vms in its
output. This option only works "
- "when querying a host system"
+ "vsphere agent to exclude placeholder vms in its
output."
))
),
( "direct",