Module: check_mk
Branch: master
Commit: 3b630b9646e56b3615128d344c7bc257e161e661
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=3b630b9646e56b…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Nov 30 12:40:00 2018 +0100
6918 FIX Availability: Time format is not only affected by time range
In case a availability is displaying a single day time range, the times
of the single entries are formatted without date information.
In case there are annotations or downtimes that affect multiple days the
from and until columns also only showed the start or end time instead of
the date. This was some kind of misleading when trying to understand why
such a downtime matched a given period.
CMK-1353
Change-Id: Iec290d656540add153c5fa28957fcb95c46f6a01
---
.werks/6918 | 18 ++++++++++++++++++
cmk/gui/plugins/views/availability.py | 22 +++++++++++++---------
.../cmk/gui/plugins/views/test_availability.py | 19 +++++++++++++++++++
3 files changed, 50 insertions(+), 9 deletions(-)
diff --git a/.werks/6918 b/.werks/6918
new file mode 100644
index 0000000..57ad542
--- /dev/null
+++ b/.werks/6918
@@ -0,0 +1,18 @@
+Title: Availability: Time format is not only affected by time range
+Level: 1
+Component: multisite
+Compatible: compat
+Edition: cre
+Version: 1.6.0i1
+Date: 1543577667
+Class: fix
+
+In case a availability is displaying a single day time range, the times
+of the single entries are formatted without date information.
+
+In case there are annotations or downtimes that affect multiple days the
+from and until columns also only showed the start or end time instead of
+the date. This was some kind of misleading when trying to understand why
+such a downtime matched a given period.
+
+CMK-1353
diff --git a/cmk/gui/plugins/views/availability.py
b/cmk/gui/plugins/views/availability.py
index a444247..dc994a4 100644
--- a/cmk/gui/plugins/views/availability.py
+++ b/cmk/gui/plugins/views/availability.py
@@ -25,6 +25,7 @@
# Boston, MA 02110-1301 USA.
import time
+import itertools
import cmk
import cmk.gui.config as config
@@ -782,16 +783,18 @@ def get_relevant_annotations(annotations, by_host, what,
avoptions):
annos_rendered.add(id(annotation))
annos_to_render.sort(cmp=lambda a, b: cmp(a[1]["from"],
b[1]["from"]) or cmp(a[0], b[0]))
+ return annos_to_render
- # Prepare rendering of time stamps
- ts_format = "%H:%M:%S"
- if time.localtime(from_time)[:3] != time.localtime(until_time - 1)[:3]:
- ts_format = "%Y-%m-%d " + ts_format
- def render_date(ts):
- return time.strftime(ts_format, time.localtime(ts))
+def get_annotation_date_render_function(annotations, avoptions):
+ timestamps = list(
+ itertools.chain.from_iterable([(a[1]["from"], a[1]["until"])
for a in annotations] +
+ [avoptions["range"][0]]))
- return annos_to_render, render_date
+ multi_day = len(set([time.localtime(t)[:3] for t in timestamps])) > 1
+ if multi_day:
+ return cmk.render.date_and_time
+ return cmk.render.time_of_day
def _annotation_affects_time_range(annotation_from, annotation_until, from_time,
until_time):
@@ -799,8 +802,9 @@ def _annotation_affects_time_range(annotation_from, annotation_until,
from_time,
def show_annotations(annotations, av_rawdata, what, avoptions, omit_service):
- annos_to_render, render_date = get_relevant_annotations(annotations, av_rawdata,
what,
- avoptions)
+ annos_to_render = get_relevant_annotations(annotations, av_rawdata, what, avoptions)
+ render_date = get_annotation_date_render_function(annos_to_render, avoptions)
+
table.begin(title=_("Annotations"), omit_if_empty=True)
for (site_id, host, service), annotation in annos_to_render:
table.row()
diff --git a/tests/unit/cmk/gui/plugins/views/test_availability.py
b/tests/unit/cmk/gui/plugins/views/test_availability.py
index 2607ee0..993b384 100644
--- a/tests/unit/cmk/gui/plugins/views/test_availability.py
+++ b/tests/unit/cmk/gui/plugins/views/test_availability.py
@@ -1,5 +1,6 @@
import pytest
+import cmk.render
import cmk.gui.plugins.views.availability as availability
@@ -16,3 +17,21 @@ import cmk.gui.plugins.views.availability as availability
def test_relevant_annotation_times(annotation_from, annotation_until, result):
assert availability._annotation_affects_time_range(annotation_from, annotation_until,
30,
60) == result
+
+
+(a)pytest.mark.parametrize("annotation_times,result"sult", [
+ ([
+ (1543446000 + 7200, 1543446000 + 14400),
+ (1543446000 + 28800, 1543446000 + 32400),
+ ], cmk.render.time_of_day),
+ ([
+ (1543446000, 1543446000),
+ ], cmk.render.time_of_day),
+ ([(1543446000 - 3600, 1543446000 + 3600)], cmk.render.date_and_time),
+ ([(1543446000, 1543446000 + 86400)], cmk.render.date_and_time),
+ ([(1543446000 + 82800, 1543446000 + 172800)], cmk.render.date_and_time),
+])
+def test_get_annotation_date_render_function(annotation_times, result):
+ annotations = [((None, None, None), {"from": s, "until": e}) for
s, e in annotation_times]
+ assert availability.get_annotation_date_render_function(
+ annotations, {"range": ((1543446000, 1543446000 + 86399),
"bla")}) == result