Module: check_mk
Branch: master
Commit: 7e7964878a92c73608cf5e91892e131a224bab51
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=7e7964878a92c7…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Wed Mar 27 19:50:49 2013 +0100
agent_vsphere: option for including data of Check_MK Agent
---
agents/special/agent_vsphere | 68 ++++++++++++++++++++-----------
checks/agent_vsphere | 7 ++-
modules/check_mk_base.py | 4 +-
web/plugins/wato/datasource_programs.py | 5 +-
4 files changed, 53 insertions(+), 31 deletions(-)
diff --git a/agents/special/agent_vsphere b/agents/special/agent_vsphere
index a9a80ba..815b01c 100755
--- a/agents/special/agent_vsphere
+++ b/agents/special/agent_vsphere
@@ -26,6 +26,7 @@
import sys
import argparse
+import socket
import inspect, pprint # FOR DEBUGGING
@@ -47,6 +48,11 @@ parser.add_argument('-D', '--direct',
action="store_true",
"we expect data about only one HostSystem to be found and
do "
"not create piggy host data for that host.")
+parser.add_argument('-a', '--agent', action="store_true",
+ help="Also retrieve data from the normal Check_MK Agent. This
makes "
+ "sense if you query a vCenter that is installed on a
Windows "
+ "host that you also want to monitor with Check_MK.")
+
parser.add_argument('--debug', action="store_true",
help="Debug mode: let Python exceptions come through")
@@ -55,13 +61,49 @@ parser.add_argument('HOST',
params = vars(parser.parse_args())
+def get_agent_info_tcp(hostname):
+ output = ""
+ try:
+ if hostname[0] in "123456789":
+ ipaddress = hostname
+ else:
+ ipaddress = socket.gethostbyname(hostname)
+ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ try:
+ s.settimeout(3.0)
+ except:
+ pass # some old Python versions lack settimeout(). Better ignore than fail
+ s.connect((ipaddress, 6556))
+ try:
+ s.setblocking(1)
+ except:
+ pass
+ output = ""
+ while True:
+ out = s.recv(4096, socket.MSG_WAITALL)
+ if out and len(out) > 0:
+ output += out
+ else:
+ break
+ s.close()
+ return output
+ except Exception, e:
+ if params["debug"]:
+ raise
+ return output
+
+error_exit = 1
+if params['agent']:
+ sys.stdout.write(get_agent_info_tcp(params["HOST"]))
+ error_exit = 0 # do not fail if vSphere fails
+
try:
from pysphere import VIServer, VIProperty, MORTypes
from pysphere.resources import VimService_services as VI
except:
sys.stderr.write("pysphere API not found. Please install and try
again.\n")
- sys.exit(1)
+ sys.exit(error_exit)
host = VIServer()
@@ -72,34 +114,12 @@ except:
if params['debug']:
raise
sys.stderr.write("Cannot connect to vSphere Server. May the wrong credentials.
Please correct and make a reinventory.\n")
- sys.exit(1)
+ sys.exit(error_exit)
print "<<<check_mk>>>"
print "Version: %s" % host.get_api_version()
print "AgentOs: %s " % host.get_server_type()
-# import inspect, pprint
-# for x in host._retrieve_properties_traversal(property_names=[], obj_type =
MORTypes.ManagedEntity):
-# print x.Obj
-# print inspect.getmembers(x)
-# sys.exit(17)
-
-# hosts = host.get_hosts()
-# pprint.pprint(inspect.getmembers(VIProperty(host, hosts.keys()[0]).hardware))
-# sys.exit(1)
-
-#for p in VIProperty(host, hosts.keys()[0]).network:
- # print host.get_resource_pools(p)
- # for n in p:
- # pprint.pprint(inspect.getmembers(p))
-
-# print p
-# print hosts
-
-
-# sys.exit(1)
-
-
def output_mors(what, properties, direct=False):
if what == "hostsystem":
diff --git a/checks/agent_vsphere b/checks/agent_vsphere
index 8b5af0e..6c310e0 100644
--- a/checks/agent_vsphere
+++ b/checks/agent_vsphere
@@ -35,14 +35,15 @@ def agent_vsphere_arguments(params, hostname, ipaddress):
args = ''
if "tcp_port" in params:
args += " -p %d" % params["tcp_port"]
- if "lower" in params:
- args += " -lower"
args += " -u " + quote_shell_string(params["user"])
args += " -s " + quote_shell_string(params["secret"])
args += " -i " + ",".join(params["infos"])
- if params.get("direct"):
+ direct = params.get("direct", False)
+ if direct:
args += ' --direct'
+ if direct == "agent":
+ args += ' --agent'
args += " " + quote_shell_string(ipaddress)
return args
diff --git a/modules/check_mk_base.py b/modules/check_mk_base.py
index 2cabeaf..1c5ae56 100755
--- a/modules/check_mk_base.py
+++ b/modules/check_mk_base.py
@@ -561,9 +561,9 @@ def get_agent_info(hostname, ipaddress, max_cache_age):
if hostname in g_broken_agent_hosts:
raise MKAgentError("")
- # If the host ist listed in datasource_programs the data from
+ # If the host is listed in datasource_programs the data from
# that host is retrieved by calling an external program (such
- # as ssh or rsy) instead of a TCP connect.
+ # as ssh or rsh or agent_vsphere) instead of a TCP connect.
commandline = get_datasource_program(hostname, ipaddress)
if commandline:
output = get_agent_info_program(commandline)
diff --git a/web/plugins/wato/datasource_programs.py
b/web/plugins/wato/datasource_programs.py
index 29e81a5..ef8d568 100644
--- a/web/plugins/wato/datasource_programs.py
+++ b/web/plugins/wato/datasource_programs.py
@@ -75,8 +75,9 @@ register_rule(group,
DropdownChoice(
title = _("Type of query"),
choices = [
- ( True, _("Queried host is a host system" ) ),
- ( False, _("Queried host is the vCenter") ),
+ ( True, _("Queried host is a host system" ) ),
+ ( False, _("Queried host is the vCenter") ),
+ ( "agent", _("Queried host is the vCenter with
Check_MK Agent installed") ),
],
default = True,
)