Module: check_mk
Branch: master
Commit: 12254f12e9580ed5eda22e021f41dc013888de96
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=12254f12e9580e…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Jun 16 17:38:42 2017 +0200
Livestatus queries: Table not found now raises a MKLivestatusTableNotFoundError()
exception
Change-Id: I3f155a1e9415ea68e0977b86b5bad1f49dd2fd11
---
livestatus/api/python/livestatus.py | 18 ++++++++++++++++++
web/htdocs/sites.py | 2 +-
web/plugins/sidebar/shipped.py | 3 ++-
3 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/livestatus/api/python/livestatus.py b/livestatus/api/python/livestatus.py
index 63a95cb..fd51baf 100644
--- a/livestatus/api/python/livestatus.py
+++ b/livestatus/api/python/livestatus.py
@@ -71,6 +71,9 @@ class MKLivestatusNotFoundError(MKLivestatusException):
def __str__(self):
return "No matching entries found for query %s" % str(self.parameter)
+class MKLivestatusTableNotFoundError(MKLivestatusException):
+ pass
+
# We need some unique value here
NO_DEFAULT = lambda: None
@@ -336,12 +339,18 @@ class BaseConnection:
length = int(resp[4:15].lstrip())
except:
raise MKLivestatusSocketError("Malformed output. Livestatus TCP
socket might be unreachable.")
+
data = self.receive_data(length)
+
if code == "200":
try:
return ast.literal_eval(data)
except:
raise MKLivestatusSocketError("Malformed output")
+
+ elif code == "404":
+ raise MKLivestatusTableNotFoundError("Not Found (%s): %s" %
(code, data.strip()))
+
else:
raise MKLivestatusQueryError("%s: %s" % (code, data.strip()))
@@ -365,6 +374,9 @@ class BaseConnection:
else:
raise MKLivestatusSocketError(str(e))
+ except MKLivestatusTableNotFoundError:
+ raise
+
except Exception, e:
raise MKLivestatusSocketError("Unhandled exception: %s" % e)
@@ -709,6 +721,12 @@ class MultiSiteConnection(Helpers):
if self.prepend_site:
r = [ [sitename] + l for l in r ]
result += r
+ #except MKLivestatusTableNotFoundError:
+ # # In case of multi site queries it may happen that one site knows a
table and
+ # # another site does not have this table because it runs an older
version.
+ # # Don't mark the site as dead site in such a case.
+ # pass
+
except Exception, e:
self.deadsites[sitename] = {
"exception" : e,
diff --git a/web/htdocs/sites.py b/web/htdocs/sites.py
index a216496..837423d 100644
--- a/web/htdocs/sites.py
+++ b/web/htdocs/sites.py
@@ -186,7 +186,7 @@ def _get_enabled_and_disabled_sites():
def update_site_states_from_dead_sites():
# Get exceptions in case of dead sites
- for site_id, deadinfo in _live.dead_sites().items():
+ for site_id, deadinfo in live().dead_sites().items():
status_host_state = deadinfo.get("status_host_state")
_update_site_status(site_id, {
"exception" : deadinfo["exception"],
diff --git a/web/plugins/sidebar/shipped.py b/web/plugins/sidebar/shipped.py
index 54d0200..6cbcffa 100644
--- a/web/plugins/sidebar/shipped.py
+++ b/web/plugins/sidebar/shipped.py
@@ -1258,7 +1258,8 @@ def render_master_control():
html.close_td()
html.close_tr()
- html.close_table()
+ html.close_table()
+
if not config.is_single_local_site():
html.end_foldable_container()