Module: check_mk
Branch: master
Commit: cfd57987ff83f3712428e97cdc4e9199529e14e9
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=cfd57987ff83f3…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Thu Apr 13 11:33:58 2017 +0200
4585 FIX juniper_trpz_aps_sessions: Fixed crashes if access point is not reachable or no
values could be calculated
Change-Id: I9ea6063bba30a6584b17e0daa9ee77a08855abba
---
.werks/4586 | 11 ++++
checks/juniper_trpz_aps | 28 +++++----
checks/juniper_trpz_aps_sessions | 129 ++++++++++++++++++++++-----------------
3 files changed, 101 insertions(+), 67 deletions(-)
diff --git a/.werks/4586 b/.werks/4586
new file mode 100644
index 0000000..f98410c
--- /dev/null
+++ b/.werks/4586
@@ -0,0 +1,11 @@
+Title: juniper_trpz_aps_sessions: Fixed crashes if access point is not reachable or no
values could be calculated
+Level: 1
+Component: checks
+Class: fix
+Compatible: compat
+Edition: cre
+State: unknown
+Version: 1.5.0i1
+Date: 1492075527
+
+
diff --git a/checks/juniper_trpz_aps b/checks/juniper_trpz_aps
index e3c5bfa..6367fa0 100644
--- a/checks/juniper_trpz_aps
+++ b/checks/juniper_trpz_aps
@@ -24,31 +24,35 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
+
def inventory_juniper_trpz_aps(info):
return [ (None, None) ]
+
def check_juniper_trpz_aps(_no_item, _no_params, info):
- total_aps = 0
+ total_aps = 0
total_sessions = 0
- message = ""
+ infotexts = []
for node, aps, sessions in info:
# Are we a cluster?
+ message = ""
if node != None:
- message += "%s: " % node
+ message += "[%s] " % node
- total_aps += int(aps)
+ total_aps += int(aps)
total_sessions += int(sessions)
- message += "%s access points online, %s sessions - " % (aps, sessions)
-
- if message.endswith(' - '):
- message = message[:-3]
+ message += "Online access points: %s, Sessions: %s" % \
+ (aps, sessions)
+ infotexts.append(message)
if len(info) > 1:
- infotext = "Total: %d access points, %d sessions (%s)" % (total_aps,
total_sessions, message)
- else:
- infotext = message
+ infotexts = ["Total: %d access points, Sessions: %d" % \
+ (total_aps, total_sessions)] + infotexts
+
+ return 0, ", ".join(infotexts), [
+ ('ap_devices_total', total_aps),
+ ("total_sessions", total_sessions)]
- return 0, infotext, [ ('ap_devices_total', total_aps),
("total_sessions", total_sessions) ]
check_info["juniper_trpz_aps"] = {
"check_function" : check_juniper_trpz_aps,
diff --git a/checks/juniper_trpz_aps_sessions b/checks/juniper_trpz_aps_sessions
index aac0cdf..e16fa15 100644
--- a/checks/juniper_trpz_aps_sessions
+++ b/checks/juniper_trpz_aps_sessions
@@ -55,30 +55,31 @@
# }
def parse_juniper_trpz_aps_sessions(info):
- access_points, radios = info
parsed = {}
- for node, end_oid, status, name in access_points:
- # 10 means that that accesspoint is located on the
- # other cluster part. Use custered_services to see all APs
- if int(status) != 10:
- name = name.replace('AP-','')
- parsed[name] = {
- 'node_info' : node,
- 'end_oid' : end_oid,
- 'status' : int(status),
- 'radios' : {},
- }
-
- for data in radios:
- radio_oid, radio_number = data[1].rsplit('.', 1)
- for ap_name, ap_data in parsed.items():
- if radio_oid == parsed[ap_name]['end_oid']:
- ap_data['radios'][radio_number] = {
- 'counters' : map(int, data[2:-2]),
- 'sessions' : int(data[-2]),
- 'noise_floor' : int(data[-1]),
+ for access_points, radios in zip(info[::2], info[1::2]):
+ for node, end_oid, status, name in access_points:
+ # 10 means that that accesspoint is located on the
+ # other cluster part. Use clustered_services to see all APs
+ if int(status) != 10:
+ name = name.replace('AP-','')
+ parsed.setdefault(name, {})
+ parsed[name].setdefault(node, {})
+ parsed[name][node] = {
+ 'end_oid' : end_oid,
+ 'status' : int(status),
+ 'radios' : {},
}
+ for data in radios:
+ radio_oid, radio_number = data[1].rsplit('.', 1)
+ for ap_name, ap_data in parsed.items():
+ if radio_oid == ap_data.get(data[0], {}).get('end_oid'):
+ ap_data[data[0]]['radios'][radio_number] = {
+ 'counters' : data[2:-2],
+ 'sessions' : data[-2],
+ 'noise_floor' : data[-1],
+ }
+
return parsed
@@ -102,39 +103,53 @@ def check_juniper_trpz_aps_sessions(item, _no_params, parsed):
10 : (0, "redundant"),
20 : (2, "conn outage"),
}
- state, ap_status = ap_states[parsed[item]['status']]
-
- if parsed[item]["node_info"] is not None:
- node_info = " (on node %s)" % parsed[item]["node_info"]
- else:
- node_info = ""
- yield state, "Status: %s%s" % (ap_status, node_info)
- now = time.time()
- ap_rates = [0, 0, 0, 0, 0, 0, 0, 0, 0]
- ap_sessions = 0
+ infotexts = []
+ state = 0
+ data = parsed[item]
+ now = time.time()
+ ap_rates = [0, 0, 0, 0, 0, 0, 0, 0, 0]
+ ap_sessions = 0
noise_floor_radios = []
- for radio_number, radio_data in parsed[item]['radios'].items():
- noise_floor_radios.append( radio_data['noise_floor'] )
- ap_sessions += radio_data['sessions']
-
- radio_rates = []
- for nr, counter in enumerate(radio_data['counters']):
- radio_rate = get_rate("juniper_trpz_aps_sessions.%s.%s.%d" \
- % (item, radio_number, nr), now, counter)
- radio_rates.append(radio_rate)
- ap_rates[nr] += radio_rate
-
- infotext = ("Radio %s: Input: %s/s, Output: %s/s, " + \
- "%d errors, %d resets, %d retries, %d sessions, noise: %d
dBm") % \
- ( radio_number,
- get_bytes_human_readable(radio_rates[5]),
- get_bytes_human_readable(radio_rates[1] + radio_rates[3]),
- radio_rates[6], radio_rates[7], radio_rates[8],
- radio_data['sessions'],
radio_data['noise_floor'] )
-
- yield 0, infotext
+ for node, ap_data in data.items():
+ node_info = ""
+ if node is not None:
+ node_info += "[%s] " % node
+
+ state, state_readable = ap_states[ap_data['status']]
+ infotexts.append("%sStatus: %s" % (node_info, state_readable))
+
+ for radio_number, radio_data in ap_data['radios'].items():
+ try:
+ radio_data_noise_floor = int(radio_data['noise_floor'])
+ noise_floor_radios.append(radio_data_noise_floor)
+ except:
+ radio_data_noise_floor = "None"
+
+ try:
+ radio_data_sessions = int(radio_data['sessions'])
+ ap_sessions += radio_data_sessions
+ except:
+ radio_data_sessions = "None"
+
+ radio_rates = [0, 0, 0, 0, 0, 0, 0, 0, 0]
+ for nr, counter in enumerate(radio_data['counters']):
+ try:
+ radio_rate =
get_rate("juniper_trpz_aps_sessions.%s.%s.%d" \
+ % (item, radio_number, nr), now, int(counter))
+ radio_rates.append(radio_rate)
+ ap_rates[nr] += radio_rate
+ except:
+ pass
+
+ infotexts.append(("Radio %s: Input: %s/s, Output: %s/s, " + \
+ "Errors: %d, Resets: %d, Retries: %d, Sessions:
%s, Noise: %s dBm") % \
+ ( radio_number,
+ get_bytes_human_readable(radio_rates[5]),
+ get_bytes_human_readable(radio_rates[1] +
radio_rates[3]),
+ radio_rates[6], radio_rates[7], radio_rates[8],
+ radio_data_sessions, radio_data_noise_floor ))
perfdata = [
("if_out_unicast", ap_rates[0]),
@@ -146,11 +161,15 @@ def check_juniper_trpz_aps_sessions(item, _no_params, parsed):
("wlan_physical_errors", ap_rates[6]),
("wlan_resets", ap_rates[7]),
("wlan_retries", ap_rates[8]),
- ("total_sessions", ap_sessions),
- ("noise_floor", max(noise_floor_radios)),
- ]
+ ("total_sessions", ap_sessions), ]
+ if noise_floor_radios:
+ perfdata.append(("noise_floor", max(noise_floor_radios)))
+
+ yield state, ", ".join(infotexts)
+ return
- yield 0, "", perfdata
+ else:
+ yield 1, "Access point not reachable"
check_info["juniper_trpz_aps_sessions"] = {