Module: check_mk
Branch: master
Commit: 9cca2bc36f46592775d3030e3dd23d6f81f6f034
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=9cca2bc36f4659…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Mon Mar 6 07:33:50 2017 +0100
4481 FIX websphere_mq_channels: fixed incomplete info handling, ie. ValueError: need more
than 2 values to unpack
Change-Id: Ic922abb439e5f2d4476c3d5eed4995dfb1dbe99f
---
.werks/4481 | 11 +++++
checks/websphere_mq_channels | 104 ++++++++++++++++++++++++++-----------------
2 files changed, 74 insertions(+), 41 deletions(-)
diff --git a/.werks/4481 b/.werks/4481
new file mode 100644
index 0000000..1043326
--- /dev/null
+++ b/.werks/4481
@@ -0,0 +1,11 @@
+Title: websphere_mq_channels: fixed incomplete info handling, id. ValueError: need more
than 2 values to unpack
+Level: 1
+Component: checks
+Class: fix
+Compatible: compat
+Edition: cre
+State: unknown
+Version: 1.4.0b4
+Date: 1488781558
+
+
diff --git a/checks/websphere_mq_channels b/checks/websphere_mq_channels
index 92bfe9e..a050f52 100644
--- a/checks/websphere_mq_channels
+++ b/checks/websphere_mq_channels
@@ -24,6 +24,8 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
+
+# Anzahl_Message Channelname MaxMessages_Moeglich Status"
# <<<websphere_mq_channels>>>
# 0 CHANNEL(C000052.C000051) 5000 Unknown
# 0 CHANNEL(C000052.CATSOS.03) 5000 RUNNING
@@ -35,7 +37,7 @@
# 0 CHANNEL(C000052.SV2098742.T1) 5000 Unknown
-websphere_mq_channels_default_levels = {
+factory_settings["websphere_mq_channels_default_levels"] = {
'message_count': ( 900, 1000 ),
'status': {
'RUNNING': 0,
@@ -44,50 +46,70 @@ websphere_mq_channels_default_levels = {
}
-def inventory_websphere_mq_channels(info):
- return [ ( x[1], 'websphere_mq_channels_default_levels' ) for x in info ]
+def parse_websphere_mq_channels(info):
+ parsed = {}
+ for line in info:
+ if len(line) == 2:
+ messages, max_messages = 0, 0
+ channel_name = line[0]
+ channel_status = line[1]
+ elif len(line) == 4:
+ messages = int(line[0])
+ channel_name = line[1]
+ max_messages = int(line[2])
+ channel_status = line[3]
+ else:
+ continue
+
+ parsed.setdefault(channel_name, {
+ "messages" : messages,
+ "max_messages" : max_messages,
+ "channel_status" : channel_status,
+ })
+ return parsed
+
+
+def inventory_websphere_mq_channels(parsed):
+ for channel_name in parsed:
+ yield channel_name, {}
-def check_websphere_mq_channels(item, params, info):
+def check_websphere_mq_channels(item, params, parsed):
if isinstance(params, tuple):
- params = {
- 'message_count' : params,
- 'status' :
websphere_mq_channels_default_levels['status'],
- }
-
- item_found = False
- for messages, channel, max_messages, status in info:
- if channel == item:
- item_found = True
- messages = saveint(messages)
- max_messages = saveint(max_messages)
- infotext = "%d/%d messages" % (messages, max_messages)
- state = 0
-
- if params['message_count']:
- warn, crit = params['message_count']
- if messages >= crit:
- state = 2
- elif messages >= warn:
- state = 1
- if state:
- infotext += " (warn crit at %d/%d messages)" % (warn,
crit)
- else:
- warn, crit = (None, None)
-
- yield state, infotext, [('messages', messages, warn, crit, 0,
max_messages)]
-
- state = params['status'].get(status,
params['status'].get('other', 2))
- yield state, "Channel status: %s" % status, []
-
- if not item_found:
- raise MKCounterWrapped("Login into database failed")
+ params = {'message_count': params,
+ 'status':
websphere_mq_channels_default_levels['status']}
+
+ if item in parsed:
+ data = parsed[item]
+ messages = data["messages"]
+ max_messages = data["max_messages"]
+ channel_status = data["channel_status"]
+
+ state = params['status'].get(channel_status,
params['status'].get('other', 2))
+ yield state, "Channel status: %s" % channel_status, []
+
+ infotext = "%d/%d messages" % (messages, max_messages)
+ state = 0
+ if params['message_count']:
+ warn, crit = params['message_count']
+ if messages >= crit:
+ state = 2
+ elif messages >= warn:
+ state = 1
+ if state > 0:
+ infotext += " (warn crit at %d/%d messages)" % (warn, crit)
+ else:
+ warn, crit = None, None
+ yield state, infotext, [('messages', messages, warn, crit, 0,
max_messages)]
check_info["websphere_mq_channels"] = {
- "inventory_function" : inventory_websphere_mq_channels,
- "check_function" : check_websphere_mq_channels,
- "service_description" : "MQ Channel %s",
- "has_perfdata" : True,
- "group" : "websphere_mq",
+ "parse_function" : parse_websphere_mq_channels,
+ "check_function" : check_websphere_mq_channels,
+ "inventory_function" : inventory_websphere_mq_channels,
+ "service_description" : "MQ Channel %s",
+ "has_perfdata" : True,
+ "default_levels_variable" :
"websphere_mq_channels_default_levels",
+ "group" : "websphere_mq",
}
+