Module: check_mk
Branch: master
Commit: 0719ea0aab1099c23e0ee7c7cb574387e5155ebf
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=0719ea0aab1099…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Nov 30 11:52:15 2018 +0100
6917 FIX Availability: Not using all relevant annotations
The availability timeline was not respecting all relevant annotations
in the case where the annotations were not starting an ending in the
current availability time range.
For example annotations that ended after the current availability range were
not used.
CMK-1353
Change-Id: I9050f9a5d61d58fe29458f36ccaf608c6baf5779
---
.werks/6917 | 17 +++++++++++++++++
cmk/gui/plugins/views/availability.py | 8 ++++++--
tests/unit/cmk/gui/plugins/views/test_availability.py | 18 ++++++++++++++++++
3 files changed, 41 insertions(+), 2 deletions(-)
diff --git a/.werks/6917 b/.werks/6917
new file mode 100644
index 0000000..dee0337
--- /dev/null
+++ b/.werks/6917
@@ -0,0 +1,17 @@
+Title: Availability: Not using all relevant annotations
+Level: 1
+Component: multisite
+Compatible: compat
+Edition: cre
+Version: 1.6.0i1
+Date: 1543574937
+Class: fix
+
+The availability timeline was not respecting all relevant annotations
+in the case where the annotations were not starting an ending in the
+current availability time range.
+
+For example annotations that ended after the current availability range were
+not used.
+
+CMK-1353
diff --git a/cmk/gui/plugins/views/availability.py
b/cmk/gui/plugins/views/availability.py
index 6cd313a..a444247 100644
--- a/cmk/gui/plugins/views/availability.py
+++ b/cmk/gui/plugins/views/availability.py
@@ -775,8 +775,8 @@ def get_relevant_annotations(annotations, by_host, what, avoptions):
site_host_svc = site_host[0], site_host[1], service # service can be
None
for annotation in annotations.get(site_host_svc, []):
- if (annotation["from"] >= from_time and
annotation["from"] <= until_time) or \
- (annotation["until"] >= from_time and
annotation["until"] <= until_time):
+ if _annotation_affects_time_range(annotation["from"],
annotation["until"],
+ from_time, until_time):
if id(annotation) not in annos_rendered:
annos_to_render.append((site_host_svc, annotation))
annos_rendered.add(id(annotation))
@@ -794,6 +794,10 @@ def get_relevant_annotations(annotations, by_host, what, avoptions):
return annos_to_render, render_date
+def _annotation_affects_time_range(annotation_from, annotation_until, from_time,
until_time):
+ return not (annotation_until < from_time or annotation_from > until_time)
+
+
def show_annotations(annotations, av_rawdata, what, avoptions, omit_service):
annos_to_render, render_date = get_relevant_annotations(annotations, av_rawdata,
what,
avoptions)
diff --git a/tests/unit/cmk/gui/plugins/views/test_availability.py
b/tests/unit/cmk/gui/plugins/views/test_availability.py
new file mode 100644
index 0000000..2607ee0
--- /dev/null
+++ b/tests/unit/cmk/gui/plugins/views/test_availability.py
@@ -0,0 +1,18 @@
+import pytest
+
+import cmk.gui.plugins.views.availability as availability
+
+
+(a)pytest.mark.parametrize("annotation_from,annotation_until,result"sult", [
+ (40, 50, True),
+ (10, 70, True),
+ (10, 30, True),
+ (10, 40, True),
+ (40, 60, True),
+ (40, 70, True),
+ (10, 20, False),
+ (61, 70, False),
+])
+def test_relevant_annotation_times(annotation_from, annotation_until, result):
+ assert availability._annotation_affects_time_range(annotation_from, annotation_until,
30,
+ 60) == result