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()
Module: check_mk
Branch: master
Commit: f88eda79a20768f79dae7793c7d906463fa4a8a2
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=f88eda79a20768…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Jun 16 17:07:10 2017 +0200
4758 FIX Fixed site status and master control snapin not displaying states of sites
The master control snapin was hiding sites with communication errors completely.
It is now displaying a box with the occured error message.
The site status snapin was showing the site, but displaying a site as "online"
while it was reported as "dead" by the livestatus connection. This appeared when
an error was found in a query, for example when a queried table does not exist.
Change-Id: I44aa10019a7b78fa381bdb3ebac1719c4ab22576
---
.werks/4758 | 16 ++++++++++++++++
web/htdocs/sites.py | 21 +++++++++++++--------
web/plugins/sidebar/shipped.py | 15 +++++++++++++++
3 files changed, 44 insertions(+), 8 deletions(-)
diff --git a/.werks/4758 b/.werks/4758
new file mode 100644
index 0000000..500f81c
--- /dev/null
+++ b/.werks/4758
@@ -0,0 +1,16 @@
+Title: Fixed site status and master control snapin not displaying states of sites
+Level: 2
+Component: multisite
+Class: fix
+Compatible: compat
+Edition: cre
+State: unknown
+Version: 1.5.0i1
+Date: 1497625512
+
+The master control snapin was hiding sites with communication errors completely.
+It is now displaying a box with the occured error message.
+
+The site status snapin was showing the site, but displaying a site as "online"
+while it was reported as "dead" by the livestatus connection. This appeared when
+an error was found in a query, for example when a queried table does not exist.
diff --git a/web/htdocs/sites.py b/web/htdocs/sites.py
index 3c22398..a216496 100644
--- a/web/htdocs/sites.py
+++ b/web/htdocs/sites.py
@@ -166,14 +166,9 @@ def _connect_multiple_sites():
})
_live.set_prepend_site(False)
- # Get exceptions in case of dead sites
- for site_id, deadinfo in _live.dead_sites().items():
- shs = deadinfo.get("status_host_state")
- _update_site_status(site_id, {
- "exception" : deadinfo["exception"],
- "status_host_state" : shs,
- "state" : _status_host_state_name(shs),
- })
+ # TODO(lm): Find a better way to make the Livestatus object trigger the update
+ # once self.deadsites is updated.
+ update_site_states_from_dead_sites()
def _get_enabled_and_disabled_sites():
@@ -189,6 +184,16 @@ def _get_enabled_and_disabled_sites():
return enabled_sites, 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():
+ status_host_state = deadinfo.get("status_host_state")
+ _update_site_status(site_id, {
+ "exception" : deadinfo["exception"],
+ "status_host_state" : status_host_state,
+ "state" : _status_host_state_name(status_host_state),
+ })
+
def _status_host_state_name(shs):
if shs == None:
diff --git a/web/plugins/sidebar/shipped.py b/web/plugins/sidebar/shipped.py
index 902f357..bf5c5ef 100644
--- a/web/plugins/sidebar/shipped.py
+++ b/web/plugins/sidebar/shipped.py
@@ -482,9 +482,13 @@ def render_sitestatus():
if config.is_multisite():
html.open_table(cellspacing=0, class_="sitestate")
+ sites.update_site_states_from_dead_sites()
+
for sitename, sitealias in config.sorted_sites():
site = config.site(sitename)
+
state = sites.state(sitename, {})
+
if state.get("state") == None:
state = "missing"
text = _("Missing site")
@@ -1239,6 +1243,17 @@ def render_master_control():
if not config.is_single_local_site():
html.end_foldable_container()
+ # Also show the dead sites
+ for site_id, site_status in sorted(sites.live().dead_sites().items()):
+ if not config.is_single_local_site():
+ sitealias = config.site(site_id)["alias"]
+ html.begin_foldable_container("master_control", site_id, True, sitealias)
+
+ html.show_error(site_status["exception"])
+
+ if not config.is_single_local_site():
+ html.end_foldable_container()
+
sidebar_snapins["master_control"] = {
"title" : _("Master Control"),