Module: check_mk
Branch: master
Commit: 0ea33c707cd57c12c0acf3c8f77a7a59e367b199
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=0ea33c707cd57c…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Sat Dec 1 22:23:27 2018 +0100
Prepare for splitting up check_parameters.py by check groups
* The very large check_parameters.py is a problem for the check development
workflow. On one hand it slows down editor features and on the other
it complicates building MKP packages of individual developments.
* Each checkgroup parameters should now be put to a dedicated module in
cmk.gui.plugins.wato.check_parameters.
* The existing rules and parameters have been moved to the unsorted.py
file. These will be moved to dedicated files soon.
CMK-1302
Change-Id: I054e138e53152aaf982f2d3ae6d312d9fcd3284a
---
cmk/gui/plugins/wato/__init__.py | 2 +
cmk/gui/plugins/wato/check_parameters/__init__.py | 28 +++++
.../wato/check_parameters/brocade_optical.py | 58 +++++++++
.../wato/check_parameters/fortinet_signatures.py | 76 ++++++++++++
.../wato/check_parameters/huawei_osn_laser.py | 65 ++++++++++
cmk/gui/plugins/wato/check_parameters/mtr.py | 90 ++++++++++++++
.../wato/check_parameters/palo_alto_sessions.py | 53 ++++++++
.../unsorted.py} | 137 ---------------------
.../cmk/gui/plugins/wato/test_check_parameters.py | 4 +-
tests/unit/cmk/gui/test_watolib.py | 16 +--
10 files changed, 382 insertions(+), 147 deletions(-)
Diff: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commitdiff;h=0ea33c707c…
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", [
+ ([
+ (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
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", [
+ (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