Module: check_mk
Branch: master
Commit: 9eaa9c84cc0e62f225c5224ca6021f5266d226dc
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=9eaa9c84cc0e62…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Jul 24 11:42:42 2015 +0200
Cleaned up: autocheck items are handled as unicode strings
---
modules/check_mk.py | 20 +-------------------
modules/discovery.py | 19 ++++++++++++++++++-
2 files changed, 19 insertions(+), 20 deletions(-)
diff --git a/modules/check_mk.py b/modules/check_mk.py
index a100a12..1998b62 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -34,12 +34,6 @@
import os, sys, socket, time, getopt, glob, re, stat, py_compile, urllib, inspect
import subprocess, fcntl
-# Hack needed to fix UnicodeWarning in in_servicematcher_list(). This
-# can be removed once the encoding of autocheck's items are handled correctly
-# as unicode strings
-import warnings
-warnings.simplefilter("error", UnicodeWarning)
-
# These variable will be substituted at 'make dist' time
check_mk_version = '(inofficial)'
@@ -2000,19 +1994,7 @@ def in_extraconf_servicelist(servicelist, service):
def in_servicematcher_list(service_matchers, item):
for negate, func in service_matchers:
- try:
- result = func(item)
- except (UnicodeDecodeError, UnicodeWarning), e:
- # FIXME: items in autochecks might contain umlauts, the strings
- # are saved as UTF-8 encoded ascii strings. should be saved as
- # unicode strings in this case or at least converted after reading.
- try:
- result = func(item.decode('utf-8'))
- except:
- if opt_debug:
- raise
- result = False
-
+ result = func(item)
if result:
return not negate
diff --git a/modules/discovery.py b/modules/discovery.py
index 3ceb7fa..35217cf 100644
--- a/modules/discovery.py
+++ b/modules/discovery.py
@@ -496,6 +496,12 @@ def discover_check_type(hostname, ipaddress, check_type, use_caches,
on_error):
(hostname,
check_type, repr(entry)))
continue
+ # Check_MK 1.2.7i3 defines items to be unicode strings. Convert non unicode
+ # strings here seamless. TODO remove this conversion one day and replace it
+ # with a validation that item needs to be of type unicode
+ if type(item) == str:
+ item = decode_incoming_string(item)
+
description = service_description(check_type, item)
# make sanity check
if len(description) == 0:
@@ -810,6 +816,10 @@ def read_autochecks_of(hostname, world="config"):
if len(entry) == 4: # old format where hostname is at the first place
entry = entry[1:]
check_type, item, parameters = entry
+ # With Check_MK 1.2.7i3 items are now defined to be unicode strings. Convert
+ # items from existing autocheck files for compatibility. TODO remove this one
day
+ if type(item) == str:
+ item = decode_incoming_string(item)
autochecks.append((check_type, item, compute_check_parameters(hostname,
check_type, item, parameters)))
return autochecks
@@ -887,7 +897,14 @@ def parse_autochecks_file(hostname):
raise Exception("Invalid number of parts: %d" % len(parts))
checktypestring, itemstring, paramstring = parts
- table.append((eval(checktypestring), eval(itemstring), paramstring))
+
+ item = eval(itemstring)
+ # With Check_MK 1.2.7i3 items are now defined to be unicode strings. Convert
+ # items from existing autocheck files for compatibility. TODO remove this one
day
+ if type(item) == str:
+ item = decode_incoming_string(item)
+
+ table.append((eval(checktypestring), item, paramstring))
except:
if opt_debug:
raise