Module: check_mk
Branch: master
Commit: 503aeca1219aba489a6815464dd598bbffb9fd54
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=503aeca1219aba…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Tue Dec 20 12:50:53 2016 +0100
4005 agent_activemq: now able to provide BasicAuth credentials
You can now set the username and password if your ActiveMQ Server requires
Basic-Authentication.
Furthermore a typo has been fixed, which marks this werk as incompatible.
The item name has changed from <i>Actice_MQ</i> to
<i>Active_MQ</i>, so you need
to start a new service discovery for these hosts.
Change-Id: Id1ca93aed32dd6c941f4143bbffa378b9ee32e09
---
.werks/4005 | 14 ++++
ChangeLog | 2 +
agents/special/agent_activemq | 113 +++++++++++++++++++++++++-------
checks/agent_activemq | 25 +++++--
web/plugins/wato/datasource_programs.py | 41 ++++++++----
5 files changed, 153 insertions(+), 42 deletions(-)
diff --git a/.werks/4005 b/.werks/4005
new file mode 100644
index 0000000..a9f1235
--- /dev/null
+++ b/.werks/4005
@@ -0,0 +1,14 @@
+Title: agent_activemq: now able to provide BasicAuth credentials
+Level: 1
+Component: checks
+Compatible: incomp
+Version: 1.4.0i4
+Date: 1482234481
+Class: feature
+
+You can now set the username and password if your ActiveMQ Server requires
Basic-Authentication.
+
+Furthermore a typo has been fixed, which marks this werk as incompatible.
+The item name has changed from <i>Actice_MQ</i> to
<i>Active_MQ</i>, so you need
+to start a new service discovery for these hosts.
+
diff --git a/ChangeLog b/ChangeLog
index 6bd394c..b4dc714 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,8 @@
Checks & Agents:
* 4104 veeam_tapejobs: New check to monitor Veeam tape jobs
* 4170 local: local check is now clusteraware. Best or worst state in cluster mode
can be configured...
+ * 4005 agent_activemq: now able to provide BasicAuth credentials...
+ NOTE: Please refer to the migration notes!
* 4171 FIX: perle_psmu: fixed value error...
* 4172 FIX: smart.temp: fixed discovery and check function...
* 4173 FIX: if.include: ignore some more keys in 'Network interfaces and switch
ports' rule which are only used for interface grouping
diff --git a/agents/special/agent_activemq b/agents/special/agent_activemq
index 36799bc..63bb3ff 100755
--- a/agents/special/agent_activemq
+++ b/agents/special/agent_activemq
@@ -24,37 +24,100 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
-from lxml import etree
+import getopt
import sys
+import requests
+from requests.auth import HTTPBasicAuth
+import xml.etree.ElementTree as ET
+
+
+def usage():
+ print "Usage:"
+ print "agent_activemq --servername {servername} --port {port} [--piggyback]
[--username {username} --password {password}]\n"
+
+short_options = ""
+long_options = [ "piggyback", "servername=", "port=",
"username=", "password=" ]
+
+try:
+ opts, args = getopt.getopt(sys.argv[1:], short_options, long_options)
+except getopt.GetoptError, err:
+ usage()
+ sys.stderr.write("%s\n" % err)
+ sys.exit(1)
+
+opt_servername = None
+opt_port = None
+opt_username = None
+opt_password = None
+opt_piggyback_mode = False
+
+
+for o,a in opts:
+ if o in [ '--piggyback' ]:
+ opt_piggyback_mode = True
+ elif o in [ '--servername' ]:
+ opt_servername = a
+ elif o in [ '--port' ]:
+ opt_port = a
+ elif o in [ '--username' ]:
+ opt_username = a
+ elif o in [ '--password' ]:
+ opt_password = a
+
+if not opt_servername or not opt_port:
+ usage()
+ sys.exit(1)
+
+url = "http://%s:%s/admin/xml/queues.jsp" % (opt_servername, opt_port)
+
+auth = None
+if opt_username:
+ auth = HTTPBasicAuth(opt_username, opt_password)
+
+data = []
+try:
+ response = requests.get(url, auth = auth)
+ if response.status_code == 401:
+ raise Exception("Unauthorized")
+
+ xml = response.text
+ data = ET.fromstring(xml)
+except Exception, e:
+ sys.stderr.write("Unable to connect. Credentials might be incorrect: %s\n"
% e)
+ sys.exit(1)
-if len(sys.argv) > 3:
- piggyback_mode = True
-else:
- piggyback_mode = False
-address = "http://%s:%s/admin/xml/queues.jsp" % (sys.argv[1], sys.argv[2])
attributes = [ 'size', 'consumerCount', 'enqueueCount',
'dequeueCount' ]
-data = etree.parse(address).getroot()
count = 0
-if not piggyback_mode:
- print "<<<mq_queues>>>"
-for line in data:
- count += 1
- if piggyback_mode:
- print "<<<<%s>>>>" % line.get('name')
- print "<<<mq_queues>>>"
- print "[[%s]]" % line.get('name')
- stats = line.findall('stats')
- values = ""
- for job in attributes:
- values +="%s " % stats[0].get(job)
- print values
-
-if piggyback_mode:
- print "<<<<>>>>"
- print "<<<local>>>"
- print "0 Actice_MQ - Found %s Queues in total" % count
+output_lines = []
+def add_output(line):
+ output_lines.append(line)
+
+try:
+ if not opt_piggyback_mode:
+ add_output("<<<mq_queues>>>")
+
+ for line in data:
+ count += 1
+ if opt_piggyback_mode:
+ add_output("<<<<%s>>>>" %
line.get('name'))
+ add_output("<<<mq_queues>>>")
+ add_output("[[%s]]" % line.get('name'))
+ stats = line.findall('stats')
+ values = ""
+ for job in attributes:
+ values +="%s " % stats[0].get(job)
+ add_output(values)
+
+ if opt_piggyback_mode:
+ add_output("<<<<>>>>")
+ add_output("<<<local>>>")
+ add_output("0 Active_MQ - Found %s Queues in total" % count)
+except Exception, e: # Probably an IndexError
+ sys.stderr.write("Unable to process data. Returned data might be incorrect:
%r" % e)
+ sys.exit(1)
+print "\n".join(output_lines)
diff --git a/checks/agent_activemq b/checks/agent_activemq
index 6c8e2ce..d55299c 100644
--- a/checks/agent_activemq
+++ b/checks/agent_activemq
@@ -24,12 +24,27 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
-#( "Hostname", Port, PiggyMode)
+# Legacy style
+#( "Hostname", Port, [PiggyMode])
def agent_activemq_arguments(params, hostname, ipaddress):
- if len(params[2]) == 0:
- return "%s %s" % (params[0], params[1])
- else:
- return "%s %s 1" % (params[0], params[1])
+ if isinstance(params, tuple):
+ new_params = {}
+ new_params["servername"] = params[0]
+ new_params["port"] = params[1]
+ if params[2] and "piggybag" in params[2]: # yes, piggybag..
+ new_params["use_piggyback"] = params[1]
+ params = new_params
+
+ args = "--servername %s" %
quote_shell_string(params["servername"])
+ args += " --port %s" %
quote_shell_string(str(params["port"]))
+ if params.get("use_piggyback"):
+ args += " --piggyback"
+
+ if "basicauth" in params:
+ args += " --username %s" %
quote_shell_string(params["basicauth"][0])
+ args += " --password %s" %
quote_shell_string(params["basicauth"][1])
+
+ return args
special_agent_info['activemq'] = agent_activemq_arguments
diff --git a/web/plugins/wato/datasource_programs.py
b/web/plugins/wato/datasource_programs.py
index ea39929..7d76904 100644
--- a/web/plugins/wato/datasource_programs.py
+++ b/web/plugins/wato/datasource_programs.py
@@ -320,25 +320,42 @@ register_rule(group,
"<tt>~/share/check_mk/agents/special</tt>."),
match = 'first')
+def transform_activemq(value):
+ if not isinstance(value, tuple):
+ return value
+
+ new_value = {}
+ new_value["servername"] = value[0]
+ new_value["port"] = value[1]
+ new_value["use_piggyback"] = "piggybag" in value[2] #
piggybag...
+ return new_value
+
+
register_rule(group,
"special_agents:activemq",
- Tuple(
+ Transform(
+ Dictionary(
+ elements = [
+ ("servername", TextAscii(title=_("Server
Name"))),
+ ("port", Integer(title=_("Port Number"),
default_value=8161)),
+ ("use_piggyback", Checkbox(title=_("Use Piggyback"),
label=_("Enable"))),
+ ("basicauth", Tuple(title=_("BasicAuth settings
(optional)"),
+ elements = [
+ TextAscii(title=_("Username")),
+ Password(title=_("Password"))
+ ]
+ )
+ )
+ ],
+ optional_keys = ["basicauth"]
+ ),
title = _("Apache ActiveMQ queues"),
- help = _( "Configure the Server Address and the Portnumber of the target
server"),
- elements = [
- TextAscii(title = _("Server Name")),
- Integer( title = _("Port Number"), default_value=8161 ),
- ListChoice(
- choices = [
- ("piggybag", _("Run in piggyback mode")),
- ],
- allow_empty = True
- )
- ]
+ forth = transform_activemq
),
factory_default = Rulespec.FACTORY_DEFAULT_UNUSED, # No default, do not use setting
if no rule matches
match = "first")
+
register_rule(group,
"special_agents:emcvnx",
Dictionary(