Module: check_mk
Branch: master
Commit: 193a15fc38c566254759cabe6dae7b936fba4118
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=193a15fc38c566…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Mar 21 09:45:37 2019 +0100
Fix inefficient event history filtering by event ID
Queries for specific event IDs were not optimized for the event history
queries which are issues e.g. by the GUI when clicking on the detail
page of one event.
This is only the first part of the fix, the second part will be added in
a separate commit for the livestatus code.
Change-Id: I991fa8d9c1c4d06316f7a4fb1b03e99aedd6c204
---
cmk/ec/history.py | 26 +++++++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)
diff --git a/cmk/ec/history.py b/cmk/ec/history.py
index 417c7d6..36ef2e2 100644
--- a/cmk/ec/history.py
+++ b/cmk/ec/history.py
@@ -73,7 +73,7 @@ class History(object):
def get(self, query):
if self._config['archive_mode'] == 'mongodb':
return _get_mongodb(self, query)
- return _get_files(self, query)
+ return _get_files(self, logger, query)
def housekeeping(self):
if self._config['archive_mode'] == 'mongodb':
@@ -408,15 +408,22 @@ def _expire_logfiles(settings, config, logger, lock_history, flush):
logger.exception("Error expiring log files: %s" % e)
-def _get_files(history, query):
+def _get_files(history, logger, query):
filters, limit = query.filters, query.limit
history_entries = []
if not history._settings.paths.history_dir.value.exists():
return []
- # Optimization: use grep in order to reduce amount
- # of read lines based on some frequently used filters.
+ logger.debug("Filters: %r", filters)
+ logger.debug("Limit: %r", limit)
+
+ # Be aware: The order here is important. It must match the order of the fields
+ # in the history file entries (See get_event_history_from_file). The fields in
+ # the file are currectly in the same order as StatusTableHistory.columns.
+ #
+ # Please note: Keep this in sync with livestatus/src/TableEventConsole.cc.
grepping_filters = [
+ 'event_id',
'event_text',
'event_comment',
'event_host',
@@ -428,6 +435,13 @@ def _get_files(history, query):
'event_ipaddress',
'event_core_host',
]
+
+ # Optimization: use grep in order to reduce amount of read lines based on
+ # some frequently used filters.
+ #
+ # It's ok if the filters don't match 100% accurately on the right lines. If in
+ # doubt, you can output more lines than necessary. This is only a kind of
+ # prefiltering.
greptexts = []
for column_name, operator_name, _predicate, argument in filters:
# Make sure that the greptexts are in the same order as in the
@@ -435,14 +449,16 @@ def _get_files(history, query):
try:
nr = grepping_filters.index(column_name)
if operator_name in ['=' '~~']:
- greptexts.append((nr, argument))
+ greptexts.append((nr, str(argument)))
except Exception:
pass
greptexts.sort()
greptexts = [x[1] for x in greptexts]
+ logger.debug("Texts for grep: %r", greptexts)
time_filters = [f for f in filters if f[0].split("_")[-1] == "time"]
+ logger.debug("Time filters: %r", time_filters)
# We do not want to open all files. So our strategy is:
# look for "time" filters and first apply the filter to
Module: check_mk
Branch: master
Commit: d1ad475ab4ce3304bfd663806d7315a73d60fc7b
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=d1ad475ab4ce33…
Author: Tom Baerwinkel <tb(a)mathias-kettner.de>
Date: Wed Mar 20 15:34:10 2019 +0100
7067 SEC mail: escape notification context
The notification context which contains e.g. the host name
and the service description is now escaped properly, i.e.
'<' is replaced by '<' and so on. Only the HTML section
which can be specified in the options of a notification
rule is not escaped.
Change-Id: I80fe51fb3866527286f474aa569d13b9940e1561
---
.werks/7067 | 14 ++++++++++++++
cmk/notification_plugins/mail.py | 3 ++-
cmk/notification_plugins/utils.py | 11 +++++++++--
tests/unit/cmk/notifications/test_utils.py | 27 +++++++++++++++++++++++++++
4 files changed, 52 insertions(+), 3 deletions(-)
diff --git a/.werks/7067 b/.werks/7067
new file mode 100644
index 0000000..433c64f
--- /dev/null
+++ b/.werks/7067
@@ -0,0 +1,14 @@
+Title: mail: escape notification context
+Level: 1
+Component: notifications
+Compatible: compat
+Edition: cre
+Version: 1.6.0i1
+Date: 1553092068
+Class: security
+
+The notification context which contains e.g. the host name
+and the service description is now escaped properly, i.e.
+'<' is replaced by '<' and so on. Only the HTML section
+which can be specified in the options of a notification
+rule is not escaped.
diff --git a/cmk/notification_plugins/mail.py b/cmk/notification_plugins/mail.py
index fe10317..bb84828 100644
--- a/cmk/notification_plugins/mail.py
+++ b/cmk/notification_plugins/mail.py
@@ -915,6 +915,7 @@ def main():
hosts = set([])
for context in contexts:
context.update(parameters)
+ utils.html_escape_context(context)
txt, html, att = construct_content(context)
content_txt += txt
content_html += html
@@ -926,10 +927,10 @@ def main():
# Use the single context subject in case there is only one context in the bulk
if len(contexts) > 1:
subject = utils.get_bulk_notification_subject(contexts, hosts)
-
else:
# gather all options from env
context = utils.collect_context()
+ utils.html_escape_context(context)
content_txt, content_html, attachments = construct_content(context)
mailto = context['CONTACTEMAIL']
subject = context['SUBJECT']
diff --git a/cmk/notification_plugins/utils.py b/cmk/notification_plugins/utils.py
index 209584f..4089785 100644
--- a/cmk/notification_plugins/utils.py
+++ b/cmk/notification_plugins/utils.py
@@ -94,7 +94,14 @@ def cmk_links(context):
return None, None
-def replace_variable_context(template, context):
+def html_escape_context(context):
+ unescaped_variables = {'PARAMETER_INSERT_HTML_SECTION'}
+ for variable, value in context.iteritems():
+ if variable not in unescaped_variables:
+ context[variable] = html_escape(value)
+
+
+def add_debug_output(template, context):
ascii_output = ""
html_output = "<table class=context>\n"
elements = context.items()
@@ -114,7 +121,7 @@ def substitute_context(template, context):
# Debugging of variables. Create content only on demand
if "$CONTEXT_ASCII$" in template or "$CONTEXT_HTML$" in template:
- template = replace_variable_context(template, context)
+ template = add_debug_output(template, context)
if re.search(r"\$[A-Z_][A-Z_0-9]*\$", template):
# Second pass to replace nested variables inside e.g. SERVICENOTESURL
diff --git a/tests/unit/cmk/notifications/test_utils.py b/tests/unit/cmk/notifications/test_utils.py
index e0bfbd7..955e3d8 100644
--- a/tests/unit/cmk/notifications/test_utils.py
+++ b/tests/unit/cmk/notifications/test_utils.py
@@ -88,3 +88,30 @@ def test_get_bulk_notification_subject(context, hosts, result):
def test_api_endpoint_url(monkeypatch, value, result):
monkeypatch.setattr('cmk.utils.password_store.extract', lambda x: 'http://secret.host')
assert utils.retrieve_from_passwordstore(value) == result
+
+
+(a)pytest.mark.parametrize(
+ "input_context,expected_context",
+ [
+ # If not explicitly allowed as unescaped...
+ (
+ {
+ 'PARAMETER_INSERT_HTML_SECTION': '<h1>Important</h1>'
+ },
+ {
+ 'PARAMETER_INSERT_HTML_SECTION': '<h1>Important</h1>'
+ },
+ ),
+ # ... all variables should be escaped
+ (
+ {
+ 'SERVICEOUTPUT': '<h1>Important</h1>'
+ },
+ {
+ 'SERVICEOUTPUT': '<h1>Important</h1>'
+ },
+ ),
+ ])
+def test_escape_context(input_context, expected_context):
+ utils.html_escape_context(input_context)
+ assert input_context == expected_context
Module: check_mk
Branch: master
Commit: f0b0e880a297abec57ab2a0eea91efe8479fcbe9
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=f0b0e880a297ab…
Author: Konstantin Büttner <kb(a)mathias-kettner.de>
Date: Wed Mar 20 16:38:58 2019 +0100
6987 FIX Queries to event history with time filters no longer skip files with non-ASCII characters in the first line
An encoding issue would lead to queries as used by the event history to skip files with non-ASCII characters
in the first line, leading to events archived in that file's timerange to be omitted. This has been fixed.
Change-Id: I671b681205e5076b17a6049dc6f5b41c4b589c25
---
.werks/6987 | 12 ++++++++++++
cmk/ec/history.py | 2 +-
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/.werks/6987 b/.werks/6987
new file mode 100644
index 0000000..294c488
--- /dev/null
+++ b/.werks/6987
@@ -0,0 +1,12 @@
+Title: Event history: Fix incomplete information when using time filters (eg. Recent Events view)
+Level: 2
+Component: ec
+Class: fix
+Compatible: compat
+Edition: cre
+State: unknown
+Version: 1.6.0i1
+Date: 1553095186
+
+An encoding issue would lead to queries as used by the event history to skip files with non-ASCII characters
+in the first line, leading to events archived in that file's timerange to be omitted. This has been fixed.
diff --git a/cmk/ec/history.py b/cmk/ec/history.py
index 9eaea61..20e3193 100644
--- a/cmk/ec/history.py
+++ b/cmk/ec/history.py
@@ -569,7 +569,7 @@ def _unsplit(s):
def _get_logfile_timespan(path):
try:
- with path.open() as f:
+ with path.open(encoding="utf-8") as f:
first_entry = float(f.readline().split('\t', 1)[0])
last_entry = path.stat().st_mtime
return first_entry, last_entry
Module: check_mk
Branch: master
Commit: 59a1172b56672d430349bdd9268d166b784d4b18
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=59a1172b56672d…
Author: Florian Kromer <fk(a)mathias-kettner.de>
Date: Tue Mar 19 16:29:07 2019 +0100
7194 FIX ceph_df: Support new output format
Dependent on the version of ceph the output format differs w.r.t. how the size
of used storage is represented. This werk adds support for all known formats.
Change-Id: Ieff7abb199b30c78da7616d3ecea6ef1b8bdcdd1
---
.werks/7194 | 11 +
checks/ceph_df | 29 +-
.../checks/generictests/datasets/ceph_df_new.py | 727 +++++++++++++++++++++
.../datasets/ceph_df_new_whitespaces.py | 118 ++++
.../checks/generictests/datasets/ceph_df_old.py | 338 ++++++++++
tests/unit/checks/test_ceph_df.py | 16 +
6 files changed, 1236 insertions(+), 3 deletions(-)
Diff: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commitdiff;h=59a1172b56…
Module: check_mk
Branch: master
Commit: f366d2cf27a955010d6bd48ec547d314503649ef
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=f366d2cf27a955…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Wed Mar 20 15:12:28 2019 +0100
6968 FIX Fixed CMC crashes caused by a race condition
Activating a new configuration during a long-running query for graph data
could lead to a CMC crash because of an internal race condition. This has
been fixed.
Change-Id: I590b1b44da579d6783665432c5d6c1f6f71559d5
---
.werks/6968 | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/.werks/6968 b/.werks/6968
new file mode 100644
index 0000000..f306341
--- /dev/null
+++ b/.werks/6968
@@ -0,0 +1,12 @@
+Title: Fixed CMC crashes caused by a race condition
+Level: 2
+Component: core
+Compatible: compat
+Edition: cee
+Version: 1.6.0i1
+Date: 1553090873
+Class: fix
+
+Activating a new configuration during a long-running query for graph data
+could lead to a CMC crash because of an internal race condition. This has
+been fixed.