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):