Module: check_mk
Branch: master
Commit: efd9c05bba54c4e487c9d6dfd807d07b6fd67586
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=efd9c05bba54c4…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Thu Jan 9 15:16:31 2014 +0100
Make handling of spaces in hostnames of ESX configurable
Cherry picked. Feature was in 1.2.4 but not in the master branch
Conflicts:
agents/special/agent_vsphere
---
agents/special/agent_vsphere | 25 ++++++++++++++++++++-----
checks/agent_vsphere | 3 +++
web/plugins/wato/check_parameters.py | 9 ---------
web/plugins/wato/datasource_programs.py | 12 +++++++++++-
4 files changed, 34 insertions(+), 15 deletions(-)
diff --git a/agents/special/agent_vsphere b/agents/special/agent_vsphere
index 6e0a836..5076949 100755
--- a/agents/special/agent_vsphere
+++ b/agents/special/agent_vsphere
@@ -55,6 +55,12 @@ soapdata_list = [
]
+def convert_hostname(h):
+ if opt_spaces == "cut":
+ return h.split()[0]
+ else:
+ return h.replace(" ", "_")
+
# List of predefined SOAP requests
# ( [{used_by_object}], {internal_id}, {SOAP telegram} )
@@ -158,12 +164,16 @@ OPTIONS:
-c, --dump-counters Simply dumping out all available counters and their
values.
This mode is meant for debugging and diagnostic
purposes.
+ -S, --spaces HOW How to handle spaces in hostnames. "cut": cut
everyting
+ after the first space, "underscore": replace
with
+ underscores. Default is "underscore".
+
""")
-short_options = 'hi:u:s:Dat:H:cPp:'
+short_options = 'hi:u:s:Dat:H:cPp:S:'
long_options = [
'help', 'user=', 'secret=', 'direct',
'agent', 'debug', 'modules=', 'timeout=',
'hostname=',
- 'dump-counters', 'tracefile=', "pysphere",
"port=",
+ 'dump-counters', 'tracefile=', "pysphere",
"port=", "spaces=",
]
opt_debug = False
@@ -176,6 +186,7 @@ opt_hostname = None
opt_skip_placeholder_vm = False
opt_pysphere = False
opt_tracefile = None
+opt_spaces = "underscore"
error = None
error_exit = 1
@@ -219,11 +230,15 @@ for o,a in opts:
opt_hostname = a
elif o in [ '-c', '--dump-counters' ]:
opt_dump_counters = True
+ elif o in [ '-S', '--spaces']:
+ if a not in [ "cut", "underscore" ]:
+ usage()
+ sys.exit(1)
+ opt_spaces = a
elif o in [ '-h', '--help' ]:
usage()
sys.exit(0)
-
# vCenter only supports the classical slow vSphere agent (based on pysphere)
# Also we do not support ESX 4.1 (yet).
if not opt_direct or opt_pysphere:
@@ -583,7 +598,7 @@ if not error:
for key in sorted(vms.keys()):
data = vms[key]
if data.get("name"):
- print "<<<<%s>>>>" %
data.get("name").replace(" ", "_")
+ print "<<<<%s>>>>" %
convert_hostname(data.get("name"))
print "<<<esx_vsphere_vm>>>"
entries = list(data.items())
entries.sort()
@@ -606,7 +621,7 @@ if not error:
for key in sorted(vms.keys()):
data = vms[key]
running_on = hostsystem_name.get(data.get("runtime.host"),
data.get("runtime.host"))
- print "virtualmachine\t%s\t%s\t%s" %
(data.get("name").replace(" ", "_"), running_on,
data.get("runtime.powerState"))
+ print "virtualmachine\t%s\t%s\t%s" %
(convert_hostname(data.get("name")), running_on,
data.get("runtime.powerState"))
except Exception, e:
if opt_debug:
diff --git a/checks/agent_vsphere b/checks/agent_vsphere
index c917b39..878d2c9 100644
--- a/checks/agent_vsphere
+++ b/checks/agent_vsphere
@@ -50,6 +50,9 @@ def agent_vsphere_arguments(params, hostname, ipaddress):
if params.get("skip_placeholder_vms", True):
args += " -P"
+ if "spaces" in params:
+ args += ' --spaces %s' % params["spaces"]
+
if "timeout" in params:
args += ' --timeout %d' % params["timeout"]
diff --git a/web/plugins/wato/check_parameters.py b/web/plugins/wato/check_parameters.py
index ba1fc47..1386eb4 100644
--- a/web/plugins/wato/check_parameters.py
+++ b/web/plugins/wato/check_parameters.py
@@ -3221,15 +3221,6 @@ register_check_parameters(
None, None
)
-# register_check_parameters(
-# subgroup_virt,
-# "esx_hostsystems",
-# _("Available HostSystems in ESX cluster"),
-# None,
-# "first",
-# False,
-# )
-
register_check_parameters(
subgroup_hardware,
diff --git a/web/plugins/wato/datasource_programs.py
b/web/plugins/wato/datasource_programs.py
index 7b40e19..97c55de 100644
--- a/web/plugins/wato/datasource_programs.py
+++ b/web/plugins/wato/datasource_programs.py
@@ -97,6 +97,16 @@ register_rule(group,
title = _("Retrieve information about..."),
)
),
+ ( "spaces",
+ DropdownChoice(
+ title = _("Spaces in hostnames"),
+ choices = [
+ ( "underscore", _("Replace with
underscores") ),
+ ( "cut", _("Cut everything after first
space") ),
+ ],
+ default = "underscore",
+ )
+ ),
( "direct",
DropdownChoice(
title = _("Type of query"),
@@ -138,7 +148,7 @@ register_rule(group,
help = _("This rule selects the vSphere agent instead of the normal Check_MK
Agent "
"and allows monitoring of VMWare ESX via the vSphere API. You can
configure "
"your connection settings here."),
- forth = lambda a: dict([("skip_placeholder_vms", True),
("use_pysphere" , False)] + a.items())
+ forth = lambda a: dict([("skip_placeholder_vms", True),
("use_pysphere" , False), ("spaces", "underscore")] +
a.items())
),
factory_default = FACTORY_DEFAULT_UNUSED, # No default, do not use setting if no rule
matches
match = 'first')