Module: check_mk
Branch: master
Commit: 78ac8f172c9585377c61e484d96145f86e37ed2f
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=78ac8f172c9585…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Thu Sep 3 17:03:31 2015 +0200
local: slight update of error handling
---
checks/local | 17 ++++++++++++-----
modules/discovery.py | 2 +-
2 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/checks/local b/checks/local
index ee63afc..28a7cf5 100644
--- a/checks/local
+++ b/checks/local
@@ -84,6 +84,7 @@ def local_compute_state(perfdata):
return worst, texts
+
def inventory_local(info):
inventory = []
# Lines with P do not need to supply a text
@@ -91,16 +92,17 @@ def inventory_local(info):
if len(line) >= 4 or len(line) == 3 and line[0] == 'P':
inventory.append( (line[1], None) )
else:
- raise MKGeneralException("Invalid local check output: %s" % line)
+ raise MKGeneralException("Invalid local check output: %s" % "
".join(line))
return inventory
+
def check_local(item, params, info):
for line in info:
# Ignore invalid lines, tolerate bugs in local checks
# of unexperienced users
if len(line) >= 2 and line[1] == item:
if not (len(line) >= 4 or (len(line) == 3 and line[0] == 'P')):
- return 3, "Invalid local check output: %s" % line
+ return 3, "Incomplete line in local check output: %s" % "
".join(line)
statechar = line[0]
perftxt = line[2]
@@ -114,19 +116,24 @@ def check_local(item, params, info):
values = valuetxt.split(';')
perfdata.append(tuple( [varname] + values ))
except ValueError:
- return 3, "Invalid local check output: %s" % line
+ return 3, "Invalid performance data %s in local check output
%s" % \
+ (perftxt, " ".join(line))
if statechar == 'P':
state, texts = local_compute_state(perfdata)
if output:
texts = [output] + texts
output = ", ".join(texts)
else:
- state = int(statechar)
+ try:
+ state = int(statechar)
+ except:
+ return 3, "Invalid state %s in local check output %s: must be P,
0, 1, 2 or 3" % \
+ (statechar, " ".join(line))
+
if state not in range(0, 4):
output += ", local check has sent invalid state %d" %
state
state = 3
return (state, output, perfdata)
- return (3, "Check output not found in local checks")
check_info["local"] = {
diff --git a/modules/discovery.py b/modules/discovery.py
index 35217cf..844e300 100644
--- a/modules/discovery.py
+++ b/modules/discovery.py
@@ -513,7 +513,7 @@ def discover_check_type(hostname, ipaddress, check_type, use_caches,
on_error):
except Exception, e:
if on_error != "ignore":
- warning(" Exception in discovery function of check type %s" %
check_type)
+ warning(" Exception in discovery function of check type
'%s'." % check_type)
if on_error == "raise":
raise
return []