Module: check_mk
Branch: master
Commit: 4d938b56adfbb7890fb48227d573e6b41f88e43d
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=4d938b56adfbb7…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Sep 20 13:31:37 2018 +0200
Timeperiod excludes are now sorted
CMK-522
Change-Id: I3eb5c2b4ffc82afd52932edd4d381f97095aff74
---
cmk/gui/wato/pages/timeperiods.py | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/cmk/gui/wato/pages/timeperiods.py b/cmk/gui/wato/pages/timeperiods.py
index 696c3d8..8978e28 100644
--- a/cmk/gui/wato/pages/timeperiods.py
+++ b/cmk/gui/wato/pages/timeperiods.py
@@ -784,10 +784,12 @@ class ModeEditTimeperiod(WatoMode):
We offer the list of all other timeperiods - but only those that do not exclude the current
timeperiod (in order to avoid cycles)"""
other_tps = []
+
for tpname, tp in self._timeperiods.items():
if not self._timeperiod_excludes(tpname):
other_tps.append((tpname, tp.get("alias") or tpname))
- return other_tps
+
+ return sorted(other_tps, key=lambda a: a[1].lower())
def _timeperiod_excludes(self, tpa_name):
Module: check_mk
Branch: master
Commit: e2a1e6c1edc77677dd3d0a83bbb1d05597c8d6f1
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=e2a1e6c1edc776…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Sep 20 13:23:02 2018 +0200
Configuring equal times for all weekdays is now easier
Instead of setting the same time ranges for each weekday it is now
possible to select "Same times for all week days". Then it is only
needed to configure the time range once for all.
CMK-522
Change-Id: Ibc83f9d42968be90ab8a125e86d40623779dd289
---
cmk/gui/wato/pages/timeperiods.py | 77 ++++++++++++++++++++++++++++++++-------
1 file changed, 64 insertions(+), 13 deletions(-)
diff --git a/cmk/gui/wato/pages/timeperiods.py b/cmk/gui/wato/pages/timeperiods.py
index cce9403..696c3d8 100644
--- a/cmk/gui/wato/pages/timeperiods.py
+++ b/cmk/gui/wato/pages/timeperiods.py
@@ -55,6 +55,7 @@ from cmk.gui.valuespec import (
ValueSpec,
TimeofdayRange,
ListChoice,
+ CascadingDropdown,
)
from cmk.gui.plugins.wato import (
@@ -679,15 +680,7 @@ class ModeEditTimeperiod(WatoMode):
size = 80,
validate = self._validate_alias,
)),
- ("weekdays", Dictionary(
- title = _("Weekdays"),
- help = _("For each weekday you can setup no, one or several "
- "time ranges in the format <tt>23:39</tt>, in which the time period "
- "should be active."),
- elements = self._weekday_elements(),
- optional_keys = None,
- indent = False,
- )),
+ ("weekdays", self._vs_weekdays()),
("exceptions", self._vs_exceptions()),
("exclude", self._vs_exclude()),
],
@@ -709,6 +702,24 @@ class ModeEditTimeperiod(WatoMode):
raise MKUserError("alias", message)
+ def _vs_weekdays(self):
+ return CascadingDropdown(
+ title = _("Active time range"),
+ help = _("For each weekday you can setup no, one or several "
+ "time ranges in the format <tt>23:39</tt>, in which the time period "
+ "should be active."),
+ choices = [
+ ("whole_week", _("Same times for all weekdays"), MultipleTimeRanges(
+ )),
+ ("day_specific", _("Weekday specific times"), Dictionary(
+ elements = self._weekday_elements(),
+ optional_keys = None,
+ indent = False,
+ )),
+ ],
+ )
+
+
def _weekday_elements(self):
elements = []
for tp_id, tp_title in cmk.defines.weekdays_by_name():
@@ -851,8 +862,7 @@ class ModeEditTimeperiod(WatoMode):
vs_spec = {
"name": self._name,
"alias": tp_spec.get("alias", ""),
- "weekdays": { day: map(self._time_range_to_valuespec, tp_spec.get(day, []))
- for day in defines.weekday_ids() },
+ "weekdays": self._weekdays_to_valuespec(tp_spec),
"exclude": tp_spec.get("exclude", []),
"exceptions": sorted(exceptions),
}
@@ -860,6 +870,22 @@ class ModeEditTimeperiod(WatoMode):
return vs_spec
+ def _weekdays_to_valuespec(self, tp_spec):
+ if self._has_same_time_specs_during_whole_week(tp_spec):
+ return ("whole_week", map(self._time_range_to_valuespec, tp_spec.get("monday", [])))
+
+ return ("day_specific", { day: map(self._time_range_to_valuespec, tp_spec.get(day, []))
+ for day in defines.weekday_ids() })
+
+
+ def _has_same_time_specs_during_whole_week(self, tp_spec):
+ """Put the time ranges of all weekdays into a set to reduce the duplicates to see whether
+ or not all days have the same time spec and return True if they have the same."""
+ unified_time_ranges = set([ tuple(tp_spec.get(day, []))
+ for day in defines.weekday_ids() ])
+ return len(unified_time_ranges) == 1
+
+
def _time_range_to_valuespec(self, time_range):
"""Convert a time range specification to valuespec format
e.g. ("00:30", "10:17") -> ((0,30),(10,17))"""
@@ -880,10 +906,35 @@ class ModeEditTimeperiod(WatoMode):
if vs_spec["exclude"]:
tp_spec["exclude"] = vs_spec["exclude"]
- for day, time_ranges in vs_spec["weekdays"].items() + vs_spec["exceptions"]:
+ tp_spec.update(self._exceptions_from_valuespec(vs_spec))
+ tp_spec.update(self._weekdays_from_valuespec(vs_spec))
+
+ return tp_spec
+
+
+ def _exceptions_from_valuespec(self, vs_spec):
+ tp_spec = {}
+ for exception_name, time_ranges in vs_spec["exceptions"]:
if time_ranges:
- tp_spec[day] = map(self._time_range_from_valuespec, time_ranges)
+ tp_spec[exception_name] = map(self._time_range_from_valuespec, time_ranges)
+ return tp_spec
+
+
+ def _weekdays_from_valuespec(self, vs_spec):
+ weekday_ty, weekday_values = vs_spec["weekdays"]
+ if weekday_ty == "whole_week":
+ # produce a data structure equal to the "day_specific" structure
+ weekday_values = { day: weekday_values for day in defines.weekday_ids() }
+
+ elif weekday_ty != "day_specific":
+ raise NotImplementedError()
+
+ tp_spec = {}
+ for day in defines.weekday_ids():
+ time_specs = map(self._time_range_from_valuespec, weekday_values[day])
+ if time_specs:
+ tp_spec[day] = time_specs
return tp_spec
Module: check_mk
Branch: master
Commit: 913ad42c810763a0cc9268da8d0420a62714ad07
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=913ad42c810763…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Sep 20 17:21:27 2018 +0200
Timeperiods: Number of time ranges is now flexible
* Add new render style "floating" to ListOf() valuespec to make the
time range list as compact as they were before
* Cleaned up ListOf() valuespec javascript code on the way
* Refactored MultipleTimeRanges() and TimeofdayRanges() to base on
the generic ListOf() valuespec
CMK-522
Change-Id: I07772d6582246a81e7b9ab7abad149c33eaa958a
---
cmk/gui/plugins/wato/check_mk_configuration.py | 3 +-
cmk/gui/plugins/wato/check_parameters.py | 8 +-
cmk/gui/valuespec.py | 155 +++++++++++++++++++------
cmk/gui/wato/pages/timeperiods.py | 89 ++++----------
web/htdocs/check_mk.css | 18 ++-
web/htdocs/js/checkmk.js | 140 +++++++++-------------
web/htdocs/themes/facelift/theme.css | 18 +--
7 files changed, 225 insertions(+), 206 deletions(-)
Diff: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commitdiff;h=913ad42c81…
Module: check_mk
Branch: master
Commit: 00659e23a54cf1f0cd931a12b32ae7fbc2b7bacd
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=00659e23a54cf1…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Sep 21 09:38:20 2018 +0200
Cleaned up special case of timeperiod 24X7 in the GUI
The timeperiod was implicitly defined and handled as special case in
many parts of Check_MK. This timeperiod is now visible to the user in
the timeperiods view, always available and declared as "builtin" in the
GUI. It can not be modified by the user.
CMK-522
Change-Id: I4f040fd0f32b8d871c4e4b80c31b02b69035c6dc
---
cmk/gui/wato/__init__.py | 9 ++++-----
cmk/gui/wato/pages/timeperiods.py | 32 +++++++++++++++++++++-----------
cmk/gui/watolib.py | 27 +++++++++++++++++++++++++--
3 files changed, 50 insertions(+), 18 deletions(-)
diff --git a/cmk/gui/wato/__init__.py b/cmk/gui/wato/__init__.py
index a61fe6f..100049d 100644
--- a/cmk/gui/wato/__init__.py
+++ b/cmk/gui/wato/__init__.py
@@ -9147,13 +9147,13 @@ class ModeUsers(WatoMode):
html.write_text(_("all events disabled"))
else:
tp = user.get("notification_period", "24X7")
- if tp != "24X7" and tp not in timeperiods:
+ if tp not in timeperiods:
tp = tp + _(" (invalid)")
- elif tp != "24X7":
+ elif tp not in watolib.builtin_timeperiods():
url = watolib.folder_preserving_link([("mode", "edit_timeperiod"), ("edit", tp)])
tp = html.render_a(timeperiods[tp].get("alias", tp), href=url)
else:
- tp = _("Always")
+ tp = timeperiods[tp].get("alias", tp)
html.write(tp)
# the visible custom attributes
@@ -9608,8 +9608,7 @@ class ModeEditUser(WatoMode):
# Notification period
forms.section(_("Notification time period"))
- choices = [ ( "24X7", _("Always")) ] + \
- [ ( id, "%s" % (tp["alias"])) for (id, tp) in self._timeperiods.items() ]
+ choices = [ ( id, "%s" % (tp["alias"])) for (id, tp) in self._timeperiods.items() ]
html.dropdown("notification_period", choices, deflt=self._user.get("notification_period"), sorted=True)
html.help(_("Only during this time period the "
"user will get notifications about host or service alerts."))
diff --git a/cmk/gui/wato/pages/timeperiods.py b/cmk/gui/wato/pages/timeperiods.py
index 5f3bfce..1b30347 100644
--- a/cmk/gui/wato/pages/timeperiods.py
+++ b/cmk/gui/wato/pages/timeperiods.py
@@ -98,6 +98,9 @@ class ModeTimeperiods(WatoMode):
def action(self):
delname = html.var("_delete")
if delname and html.transaction_valid():
+ if delname in watolib.builtin_timeperiods():
+ raise MKUserError("_delete", _("Builtin timeperiods can not be modified"))
+
usages = self._find_usages_of_timeperiod(delname)
if usages:
message = "<b>%s</b><br>%s:<ul>" % \
@@ -279,24 +282,30 @@ class ModeTimeperiods(WatoMode):
def page(self):
table.begin("timeperiods", empty_text = _("There are no timeperiods defined yet."))
- for name in sorted(self._timeperiods.keys()):
+ for name, timeperiod in sorted(self._timeperiods.items()):
table.row()
- timeperiod = self._timeperiods[name]
- edit_url = watolib.folder_preserving_link([("mode", "edit_timeperiod"), ("edit", name)])
- clone_url = watolib.folder_preserving_link([("mode", "edit_timeperiod"), ("clone", name)])
- delete_url = make_action_link([("mode", "timeperiods"), ("_delete", name)])
-
table.cell(_("Actions"), css="buttons")
- html.icon_button(edit_url, _("Properties"), "edit")
- html.icon_button(clone_url, _("Create a copy"), "clone")
- html.icon_button(delete_url, _("Delete"), "delete")
+ if name in watolib.builtin_timeperiods():
+ html.write_text(html.i(_("(builtin)")))
+ else:
+ self._action_buttons(name)
table.text_cell(_("Name"), name)
table.text_cell(_("Alias"), timeperiod.get("alias", ""))
table.end()
+ def _action_buttons(self, name):
+ edit_url = watolib.folder_preserving_link([("mode", "edit_timeperiod"), ("edit", name)])
+ clone_url = watolib.folder_preserving_link([("mode", "edit_timeperiod"), ("clone", name)])
+ delete_url = make_action_link([("mode", "timeperiods"), ("_delete", name)])
+
+ html.icon_button(edit_url, _("Properties"), "edit")
+ html.icon_button(clone_url, _("Create a copy"), "clone")
+ html.icon_button(delete_url, _("Delete"), "delete")
+
+
# Displays a dialog for uploading an ical file which will then
# be used to generate timeperiod exceptions etc. and then finally
@@ -579,6 +588,9 @@ class ModeEditTimeperiod(WatoMode):
self._name = html.var("edit") # missing -> new group
self._new = self._name == None
+ if self._name in watolib.builtin_timeperiods():
+ raise MKUserError("edit", _("Builtin timeperiods can not be modified"))
+
if self._new:
clone_name = html.var("clone")
if clone_name:
@@ -653,8 +665,6 @@ class ModeEditTimeperiod(WatoMode):
def _validate_id(self, value, varprefix):
if value in self._timeperiods:
raise MKUserError(varprefix, _("This name is already being used by another timeperiod."))
- if value == "24X7":
- raise MKUserError(varprefix, _("The time period name 24X7 cannot be used. It is always autmatically defined."))
def _validate_alias(self, value, varprefix):
diff --git a/cmk/gui/watolib.py b/cmk/gui/watolib.py
index b91d36d..0f49b10 100644
--- a/cmk/gui/watolib.py
+++ b/cmk/gui/watolib.py
@@ -8812,13 +8812,36 @@ def may_override_read_only_mode():
# | |_| |
# +----------------------------------------------------------------------+
+def builtin_timeperiods():
+ return {
+ "24X7": {
+ "alias" : _("Always"),
+ "monday" : ("00:00", "24:00"),
+ "tuesday" : ("00:00", "24:00"),
+ "wednesday" : ("00:00", "24:00"),
+ "thursday" : ("00:00", "24:00"),
+ "friday" : ("00:00", "24:00"),
+ "saturday" : ("00:00", "24:00"),
+ "sunday" : ("00:00", "24:00"),
+ }
+ }
+
+
def load_timeperiods():
- return store.load_from_mk_file(wato_root_dir + "timeperiods.mk", "timeperiods", {})
+ timeperiods = store.load_from_mk_file(wato_root_dir + "timeperiods.mk", "timeperiods", {})
+ timeperiods.update(builtin_timeperiods())
+ return timeperiods
def save_timeperiods(timeperiods):
store.mkdir(wato_root_dir)
- store.save_to_mk_file(wato_root_dir + "timeperiods.mk", "timeperiods", timeperiods, pprint_value = config.wato_pprint_config)
+ store.save_to_mk_file(wato_root_dir + "timeperiods.mk", "timeperiods",
+ filter_builtin_timeperiods(timeperiods), pprint_value = config.wato_pprint_config)
+
+
+def filter_builtin_timeperiods(timeperiods):
+ builtin_keys = builtin_timeperiods().keys()
+ return { k: v for k, v in timeperiods.items() if k not in builtin_keys}
class TimeperiodSelection(DropdownChoice):
Module: check_mk
Branch: master
Commit: f08152f3b14263604177dd692c23ba111c9727a3
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=f08152f3b14263…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Sep 21 09:12:11 2018 +0200
6628 Improved timeperiod management
The timeperiod management pages have been improved ins several ways:
<ul>
<li>Timeperiods can now be cloned.</li>
<li>Configuring equal times for all weekdays is now easier. Instead of setting
the same time ranges for each weekday it is now possible to select "Same times for all week days".</li>
<li>Timeperiods listed in the excludes list are now sorted.</li>
<li>The number of time ranges per day is now flexible. The dialog starts with
a single time range. You may click on "add time range" to add more.</li>
<li>Improved validations of input values.</li>
<li>The builtin timeperiod 24X7 is now always visible. The implicit existance
of this timeperiod confused users.</li>
</ul>
CMK-522
Change-Id: Icb9ab740bd5cf78a0874deebe0670a3a0642f5e1
---
.werks/6628 | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/.werks/6628 b/.werks/6628
new file mode 100644
index 0000000..43e4124
--- /dev/null
+++ b/.werks/6628
@@ -0,0 +1,22 @@
+Title: Improved timeperiod management
+Level: 2
+Component: wato
+Compatible: compat
+Edition: cre
+Version: 1.6.0i1
+Date: 1537513718
+Class: feature
+
+The timeperiod management pages have been improved ins several ways:
+
+<ul>
+<li>Timeperiods can now be cloned.</li>
+<li>Configuring equal times for all weekdays is now easier. Instead of setting
+the same time ranges for each weekday it is now possible to select "Same times for all week days".</li>
+<li>Timeperiods listed in the excludes list are now sorted.</li>
+<li>The number of time ranges per day is now flexible. The dialog starts with
+a single time range. You may click on "add time range" to add more.</li>
+<li>Improved validations of input values.</li>
+<li>The builtin timeperiod 24X7 is now always visible. The implicit existance
+of this timeperiod confused users.</li>
+</ul>