Module: check_mk
Branch: master
Commit: d8afdf11fba39bffd21d2e652908ee1be67e1a0b
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=d8afdf11fba39b…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Sep 16 17:38:01 2016 +0200
livestatus_status: refactored parse function
---
checks/livestatus_status | 27 +++++++++++++--------------
1 file changed, 13 insertions(+), 14 deletions(-)
diff --git a/checks/livestatus_status b/checks/livestatus_status
index 8d50d4c..48ebf63 100644
--- a/checks/livestatus_status
+++ b/checks/livestatus_status
@@ -49,19 +49,19 @@ factory_settings["livestatus_status_default_levels"] = {
def parse_livestatus_status(info):
parsed = {}
- n = 0
- while n < len(info):
- site = info[n][0][1:-1]
- if n == len(info) - 1 or info[n+1][0].startswith('['):
- # Handle the case if the check running in cluster
- if site not in parsed.keys():
- parsed[site] = None # Site is down
- n += 1
- else:
- headers = info[n+1]
- values = info[n+2]
- parsed[site] = dict(zip(headers, values))
- n += 3
+ site, headers = None, None
+ for line in info:
+ if line and line[0][0] == "[" and line[0][-1] == "]":
+ site = line[0][1:-1]
+ parsed[site] = None # Site is marked as down until overwritten later
+
+ elif site:
+ if headers == None:
+ headers = line
+ else:
+ parsed[site] = dict(zip(headers, line))
+ headers = None
+
return parsed
@@ -69,7 +69,6 @@ def inventory_livestatus_status(parsed):
return [ (site, {}) for (site, status) in parsed.items() if status != None ]
-
def check_livestatus_status(item, params, parsed):
if item not in parsed:
return