Module: check_mk
Branch: master
Commit: 32dc33df48e4734f8aa39a527a684af089b0b3c8
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=32dc33df48e473…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Jul 28 16:24:38 2014 +0200
#1064 FIX Fixed rare issue with WATO communication in distributed setups (different OS versions)
In distributed setups where the python versions differ, especially the remote site is older
than Python 2.5 and the central site is newer than this, it might happen that the communication
between these both sites is not possible anymore since werk #0984 (2014-06-23 / 1.2.5i4).
This commit makes the communication work again with older python versions. This has been tested
with Python 2.4. It might also work with python 2.3 - but is untested yet.
---
.werks/1064 | 13 +++++++++++++
ChangeLog | 3 +++
web/htdocs/wato.py | 50 +++++++++++++++++++++++++++++++++++++++++++-------
3 files changed, 59 insertions(+), 7 deletions(-)
diff --git a/.werks/1064 b/.werks/1064
new file mode 100644
index 0000000..f8bd111
--- /dev/null
+++ b/.werks/1064
@@ -0,0 +1,13 @@
+Title: Fixed rare issue with WATO communication in distributed setups (different OS versions)
+Level: 1
+Component: wato
+Version: 1.2.5i6
+Date: 1406557188
+Class: fix
+
+In distributed setups where the python versions differ, especially the remote site is older
+than Python 2.5 and the central site is newer than this, it might happen that the communication
+between these both sites is not possible anymore since werk #0984 (2014-06-23 / 1.2.5i4).
+
+This commit makes the communication work again with older python versions. This has been tested
+with Python 2.4. It might also work with python 2.3 - but is untested yet.
diff --git a/ChangeLog b/ChangeLog
index 5f92d9f..36b3588 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,9 @@
Checks & Agents:
* 1051 FIX: tcp_conn_stats: fix missing performance data...
+ WATO:
+ * 1064 FIX: Fixed rare issue with WATO communication in distributed setups (different OS versions)...
+
1.2.5i5:
Core & Setup:
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index e203f14..451cc8d 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -16994,17 +16994,53 @@ def validate_all_hosts(hostnames, force_all = False):
import base64
try:
import ast
-except:
- ast = None
+ literal_eval = ast.literal_eval
+except ImportError:
+ # Python <2.5 compatibility
+ try:
+ from compiler import parse
+ import compiler.ast
+ def literal_eval(node_or_string):
+ _safe_names = {'None': None, 'True': True, 'False': False}
+
+ if isinstance(node_or_string, basestring):
+ node_or_string = parse(node_or_string, mode='eval')
+ if isinstance(node_or_string, compiler.ast.Expression):
+ node_or_string = node_or_string.node
+
+ def _convert(node):
+ if isinstance(node, compiler.ast.Const) and isinstance(node.value,
+ (basestring, int, float, long, complex)):
+ return node.value
+ elif isinstance(node, compiler.ast.Tuple):
+ return tuple(map(_convert, node.nodes))
+ elif isinstance(node, compiler.ast.List):
+ return list(map(_convert, node.nodes))
+ elif isinstance(node, compiler.ast.Dict):
+ return dict((_convert(k), _convert(v)) for k, v
+ in node.items)
+ elif isinstance(node, compiler.ast.Name):
+ if node.name in _safe_names:
+ return _safe_names[node.name]
+ elif isinstance(node, compiler.ast.UnarySub):
+ return -_convert(node.expr)
+ raise ValueError('malformed string')
+
+ return _convert(node_or_string)
+ except:
+ literal_eval = None
def mk_eval(s):
- if ast and not config.wato_legacy_eval:
- return ast.literal_eval(base64.b64decode(s))
- else:
- return pickle.loads(base64.b64decode(s))
+ try:
+ if literal_eval and not config.wato_legacy_eval:
+ return literal_eval(base64.b64decode(s))
+ else:
+ return pickle.loads(base64.b64decode(s))
+ except:
+ raise MKGeneralException(_('Unable to parse provided data: %s') % html.attrencode(repr(s)))
def mk_repr(s):
- if ast and not config.wato_legacy_eval:
+ if literal_eval and not config.wato_legacy_eval:
return base64.b64encode(repr(s))
else:
return base64.b64encode(pickle.dumps(s))