Module: check_mk
Branch: master
Commit: 14d8dbca7bb2f68cb0c18adc1c45c7c46fe664d1
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=14d8dbca7bb2f6…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Mar 28 14:28:37 2019 +0100
7331 FIX Fixed decreased performance in host / service views since 1.5.0p5
When using the HW/SW inventory the performance of views, especially in
distributed setups with slower responding sites, could be decreased
significantly because the GUI performed too many livestatus requests in the
background.
This was caused by werk #6594 which was added in 1.5.0p5.
CMK-1861
Change-Id: If4c7b04a09b516706dab20968d46bdfbd7e4c4d5
---
.werks/7331 | 16 ++++++++++++++++
cmk/gui/plugins/views/inventory.py | 24 ++++++++++++++++++------
2 files changed, 34 insertions(+), 6 deletions(-)
diff --git a/.werks/7331 b/.werks/7331
new file mode 100644
index 0000000..f29d031
--- /dev/null
+++ b/.werks/7331
@@ -0,0 +1,16 @@
+Title: Fixed decreased performance in host / service views since 1.5.0p5
+Level: 1
+Component: multisite
+Class: fix
+Compatible: compat
+Edition: cre
+State: unknown
+Version: 1.6.0i1
+Date: 1553774075
+
+When using the HW/SW inventory the performance of views, especially in
+distributed setups with slower responding sites, could be decreased
+significantly because the GUI performed too many livestatus requests in the
+background.
+
+This was caused by werk #6594 which was added in 1.5.0p5.
diff --git a/cmk/gui/plugins/views/inventory.py b/cmk/gui/plugins/views/inventory.py
index 5bd54e9..24edb67 100644
--- a/cmk/gui/plugins/views/inventory.py
+++ b/cmk/gui/plugins/views/inventory.py
@@ -36,7 +36,7 @@ import cmk.gui.sites as sites
import cmk.gui.utils as utils
import cmk.gui.inventory as inventory
from cmk.gui.i18n import _
-from cmk.gui.globals import html
+from cmk.gui.globals import html, current_app
from cmk.gui.htmllib import HTML
from cmk.gui.valuespec import Checkbox, Hostname
from cmk.gui.exceptions import MKUserError
@@ -1696,11 +1696,7 @@ def _create_view_enabled_check_func(invpath, is_history=False):
# FIXME In order to decide whether this view is enabled
# do we really need to load the whole tree?
- if is_history:
- struct_tree = inventory.load_filtered_inventory_tree(hostname)
- else:
- row = inventory.get_status_data_via_livestatus(context.get("site"), hostname)
- struct_tree = inventory.load_filtered_and_merged_tree(row)
+ struct_tree = _get_struct_tree(is_history, hostname, context.get("site"))
if not struct_tree:
return False
@@ -1720,6 +1716,22 @@ def _create_view_enabled_check_func(invpath, is_history=False):
return _check_view_enabled
+def _get_struct_tree(is_history, hostname, site_id):
+ struct_tree_cache = current_app.g.setdefault("struct_tree_cache", {})
+ cache_id = (is_history, hostname, site_id)
+ if cache_id in struct_tree_cache:
+ return struct_tree_cache[cache_id]
+
+ if is_history:
+ struct_tree = inventory.load_filtered_inventory_tree(hostname)
+ else:
+ row = inventory.get_status_data_via_livestatus(site_id, hostname)
+ struct_tree = inventory.load_filtered_and_merged_tree(row)
+
+ struct_tree_cache[cache_id] = struct_tree
+ return struct_tree
+
+
# Now declare Multisite views for a couple of embedded tables
declare_invtable_view(
"invswpac",
Module: check_mk
Branch: master
Commit: ac5d1624756bf814bb88b3e1001c961ba9245ab4
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ac5d1624756bf8…
Author: Ronny Bruska <rb(a)mathias-kettner.de>
Date: Thu Mar 21 09:09:33 2019 +0100
7203 FIX agent_prism: Fixed handling of informational messages
We have seen informational messages in format:
{dev_type} drive {dev_name} on host {ip_address} has the following problems: {err_msg}
In order to handle such cases, we now deal with this message format differently.
Change-Id: I52ef1fcae1cae5d9ee558b0fd5fd51bf16524828
---
.werks/7203 | 15 +++++++++++
agents/special/agent_prism | 9 ++++++-
checks/prism_alerts | 13 +++++++---
.../checks/generictests/datasets/prism_alerts.py | 30 ++++++++++++----------
4 files changed, 50 insertions(+), 17 deletions(-)
diff --git a/.werks/7203 b/.werks/7203
new file mode 100644
index 0000000..3a83238
--- /dev/null
+++ b/.werks/7203
@@ -0,0 +1,15 @@
+Title: agent_prism: Fixed handling of informational messages
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.6.0i1
+Date: 1553155607
+Class: fix
+
+We have seen informational messages in format:
+{dev_type} drive {dev_name} on host {ip_address} has the following problems: {err_msg}
+
+In order to handle such cases, we now deal with this message format differently.
+
+
diff --git a/agents/special/agent_prism b/agents/special/agent_prism
index 65ac76c..ea51c52 100755
--- a/agents/special/agent_prism
+++ b/agents/special/agent_prism
@@ -164,7 +164,14 @@ def output_alerts(opener, headers):
# actual values are stored in context_values, the keys in
# context_types
context = zip(entity['contextTypes'], entity['contextValues'])
- message = entity['message'].format(**dict(context))
+ # We have seen informational messages in format:
+ # {dev_type} drive {dev_name} on host {ip_address} has the following problems: {err_msg}
+ # In this case the keys have no values so we can not assign it to the message
+ # To handle this, we output a message without assigning the keys
+ try:
+ message = entity['message'].format(**dict(context))
+ except KeyError:
+ message = entity['message']
writer.writerow([entity['createdTimeStampInUsecs'], message, entity['severity']])
diff --git a/checks/prism_alerts b/checks/prism_alerts
index e7b3baf..be79ce2 100644
--- a/checks/prism_alerts
+++ b/checks/prism_alerts
@@ -40,7 +40,8 @@ def check_prism_alerts(__no_item, __no_params, parsed):
return {'kInfo': (0, 0), 'kWarning': (1, 1), 'kCritical': (3, 2)}.get(name, (2, 3))
if len(parsed) == 0:
- return 0, "No alerts"
+ yield 0, "No alerts"
+ return
# sort messages by severity, then timestamp, both reversed
# this way the first element should be the newest among those
@@ -49,8 +50,14 @@ def check_prism_alerts(__no_item, __no_params, parsed):
parsed, key=lambda x: (severity(x['severity'][0]), x['timestamp']), reverse=True)
sever = row_sorted[0]
time_str = time.strftime("%c", time.localtime(int(sever['timestamp']) / 1000000))
- return severity(sever['severity'])[1], "%d alerts, Last worst on %s: \"%s\"" %\
- (len(row_sorted), time_str, sever['message'])
+ yield severity(sever['severity'])[1], "%d alerts" % len(row_sorted)
+
+ message = sever['message']
+ if "has the following problems" in message:
+ state = 1
+ else:
+ state = 0
+ yield state, "Last worst on %s: \"%s\"" % (time_str, message)
check_info['prism_alerts'] = {
diff --git a/tests/unit/checks/generictests/datasets/prism_alerts.py b/tests/unit/checks/generictests/datasets/prism_alerts.py
index 7b46263..41fe6d1 100644
--- a/tests/unit/checks/generictests/datasets/prism_alerts.py
+++ b/tests/unit/checks/generictests/datasets/prism_alerts.py
@@ -1,19 +1,23 @@
# yapf: disable
+
+
checkname = 'prism_alerts'
-info = [
- ['timestamp', 'message', 'severity'],
- [
- '1456749413140000',
- 'DIMM fault detected on host 172.25.209.110. The node is running with 384 GB whereas 512 GB was installed.',
- 'kCritical'
- ], ['1456749413150000', 'Some warning message.', 'kWarning'],
- ['1456749413160000', 'Some info message.', 'kInfo']
-]
+
+info = [['timestamp', 'message', 'severity'],
+ ['1456749413140000',
+ 'DIMM fault detected on host 172.25.209.110. The node is running with 384 GB whereas 512 GB was installed.',
+ 'kCritical'],
+ ['1456749413150000', 'Some warning message.', 'kWarning'],
+ ['1456749413160000', 'Some info message.', 'kInfo']]
+
discovery = {'': [(None, None)]}
-checks = {
- '': [(None, {}, [(0, '3 alerts, Last worst on Mon Feb 29 13:36:53 2016: "Some info message."',
- [])])]
-}
+
+checks = {'': [(None,
+ {},
+ [(0, '3 alerts', []),
+ (0,
+ 'Last worst on Mon Feb 29 13:36:53 2016: "Some info message."',
+ [])])]}
\ No newline at end of file