Module: check_mk
Branch: master
Commit: 5c54152b26364072fa166f8ebb4e7372086ae5bb
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=5c54152b263640…
Author: Sebastian Herbord <sh(a)mathias-kettner.de>
Date: Fri Apr 8 09:53:46 2016 +0200
3116 Timerange buttons for downtimes can now be configured
The dialog to set a downtime currently offers 5 buttons to quickly set a downtime: 2
hours, today,
this week, this month and this year.
Now one can add additional ranges or replace the current ones. The configuration can be
found under
Globals Settings->Custom Downtime Timeranges
---
.werks/3116 | 12 ++++
ChangeLog | 1 +
web/plugins/config/builtin.py | 8 +++
web/plugins/views/commands.py | 90 ++++++++++++++++------------
web/plugins/wato/check_mk_configuration.py | 45 ++++++++++++++
5 files changed, 119 insertions(+), 37 deletions(-)
diff --git a/.werks/3116 b/.werks/3116
new file mode 100644
index 0000000..9b6f2ec
--- /dev/null
+++ b/.werks/3116
@@ -0,0 +1,12 @@
+Title: Timerange buttons for downtimes can now be configured
+Level: 1
+Component: wato
+Compatible: compat
+Version: 1.2.9i1
+Date: 1460101816
+Class: feature
+
+The dialog to set a downtime currently offers 5 buttons to quickly set a downtime: 2
hours, today,
+this week, this month and this year.
+Now one can add additional ranges or replace the current ones. The configuration can be
found under
+Globals Settings->Custom Downtime Timeranges
diff --git a/ChangeLog b/ChangeLog
index e71a681..a485aa0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -189,6 +189,7 @@
* 3003 New treasure script: migrate_oldcmk2wato.py...
* 3304 Bulk deleting users is now available
* 3239 The delay and the period of notifications can be fractions of a minute now.
+ * 3116 Timerange buttons for downtimes can now be configured...
* 3060 FIX: Folder properties: Fixed exception when a user has no alias set...
* 3062 FIX: Git integration: Fixed not adding files in WATO folders to git control
* 3203 FIX: Distributed WATO: Fixed exception in remote host service discovery...
diff --git a/web/plugins/config/builtin.py b/web/plugins/config/builtin.py
index 66b9b73..c23c1d1 100644
--- a/web/plugins/config/builtin.py
+++ b/web/plugins/config/builtin.py
@@ -263,6 +263,14 @@ user_localizations = {
# Contains user specified icons and actions for hosts and services
user_icons_and_actions = {}
+user_downtime_timeranges = [
+ {'title': _("2 hours"), 'end': 2 * 60 * 60},
+ {'title': _("Today"), 'end':
'next_day'},
+ {'title': _("This week"), 'end':
'next_week'},
+ {'title': _("This month"), 'end':
'next_month'},
+ {'title': _("This year"), 'end':
'next_year'},
+ ]
+
# Override toplevel and sort_index settings of builtin icons
builtin_icon_visibility = {}
diff --git a/web/plugins/views/commands.py b/web/plugins/views/commands.py
index c5fc3c6..8fd2726 100644
--- a/web/plugins/views/commands.py
+++ b/web/plugins/views/commands.py
@@ -499,6 +499,20 @@ config.declare_permission("action.downtimes",
_("Schedule and remove downtimes on hosts and services"),
[ "user", "admin" ])
+
+def get_duration_human_readable(secs):
+ days, rest = divmod(secs, 86400)
+ hours, rest = divmod(rest, 3600)
+ mins, secs = divmod(rest, 60)
+
+ return ", ".join(["%d %s" % (val, label)
+ for val, label in [(days, "days"),
+ (hours, "hours"),
+ (mins, "minutes"),
+ (secs, "seconds")]
+ if val > 0])
+
+
def command_downtime(cmdtag, spec, row):
down_from = int(time.time())
down_to = None
@@ -509,39 +523,44 @@ def command_downtime(cmdtag, spec, row):
else:
title_start = _("schedule an immediate downtime")
- if html.var("_down_2h"):
- down_to = down_from + 7200
- title = _("<b>%s of 2 hours length</b> on") % title_start
-
- elif html.var("_down_today"):
- br = time.localtime(down_from)
- down_to = time.mktime((br.tm_year, br.tm_mon, br.tm_mday, 23, 59, 59, 0, 0,
br.tm_isdst)) + 1
- title = _("<b>%s until 24:00:00</b> on") % title_start
-
- elif html.var("_down_week"):
- br = time.localtime(down_from)
- wday = br.tm_wday
- days_plus = 6 - wday
- down_to = time.mktime((br.tm_year, br.tm_mon, br.tm_mday, 23, 59, 59, 0, 0,
br.tm_isdst)) + 1
- down_to += days_plus * 24 * 3600
- title = _("<b>%s until sunday night</b> on") % title_start
-
- elif html.var("_down_month"):
- br = time.localtime(down_from)
- new_month = br.tm_mon + 1
- if new_month == 13:
- new_year = br.tm_year + 1
- new_month = 1
+ rangebtns = html.all_varnames_with_prefix("_downrange")
+
+ def resolve_end(name):
+ now = time.localtime(down_from)
+ if name == "next_day":
+ return time.mktime((br.tm_year, br.tm_mon, br.tm_mday, 23, 59, 59, 0, 0,
br.tm_isdst)) + 1, \
+ _("<b>%s until 24:00:00</b> on") % title_start
+ elif name == "next_week":
+ br = time.localtime(down_from)
+ wday = br.tm_wday
+ days_plus = 6 - wday
+ res = time.mktime((br.tm_year, br.tm_mon, br.tm_mday, 23, 59, 59, 0, 0,
br.tm_isdst)) + 1
+ res += days_plus * 24 * 3600
+ return res, _("<b>%s until sunday night</b> on") %
title_start
+ elif name == "next_month":
+ br = time.localtime(down_from)
+ new_month = br.tm_mon + 1
+ if new_month == 13:
+ new_year = br.tm_year + 1
+ new_month = 1
+ else:
+ new_year = br.tm_year
+ return time.mktime((new_year, new_month, 1, 0, 0, 0, 0, 0, br.tm_isdst)), \
+ _("<b>%s until end of month</b> on") % title_start
+ elif name == "next_year":
+ br = time.localtime(down_from)
+ return time.mktime((br.tm_year, 12, 31, 23, 59, 59, 0, 0, br.tm_isdst)) + 1,
\
+ _("<b>%s until end of %d</b> on") % (title_start,
br.tm_year)
else:
- new_year = br.tm_year
- down_to = time.mktime((new_year, new_month, 1, 0, 0, 0, 0, 0, br.tm_isdst))
- title = _("<b>%s until end of month</b> on") % title_start
-
- elif html.var("_down_year"):
- br = time.localtime(down_from)
- down_to = time.mktime((br.tm_year, 12, 31, 23, 59, 59, 0, 0, br.tm_isdst)) + 1
- title = _("<b>%s until end of %d</b> on") % (title_start,
br.tm_year)
-
+ duration = int(name)
+ return down_from + duration, \
+ _("<b>%s of %s length</b> on") %\
+ (title_start, get_duration_human_readable(duration))
+
+ if rangebtns:
+ rangebtn = rangebtns.next()
+ btnname, end = rangebtn.split("__", 1)
+ down_to, title = resolve_end(end)
elif html.var("_down_from_now"):
try:
minutes = int(html.var("_down_minutes"))
@@ -668,11 +687,8 @@ def paint_downtime_buttons(what):
html.number_input("_down_minutes", 60, size=4,
submit="_down_from_now")
html.write(" " + _("minutes"))
html.write("<hr>")
- html.button("_down_2h", _("2 hours"))
- html.button("_down_today", _("Today"))
- html.button("_down_week", _("This week"))
- html.button("_down_month", _("This month"))
- html.button("_down_year", _("This year"))
+ for time_range in config.user_downtime_timeranges:
+ html.button("_downrange__%s" % time_range['end'],
time_range['title'])
if what != "aggr":
html.write(" - ")
html.button("_down_remove", _("Remove all"))
diff --git a/web/plugins/wato/check_mk_configuration.py
b/web/plugins/wato/check_mk_configuration.py
index 832d07e..66ef2a5 100644
--- a/web/plugins/wato/check_mk_configuration.py
+++ b/web/plugins/wato/check_mk_configuration.py
@@ -554,6 +554,51 @@ register_configvar(group,
domain = "multisite",
)
+register_configvar(group,
+ "user_downtime_timeranges",
+ ListOf(
+ Dictionary(
+ elements = [
+ ('title', TextUnicode(title = _('Title'))),
+ ('end', Alternative(
+ title = _("To"),
+ elements = [
+ Age(
+ title = _("Duration"),
+ display = [ "minutes", "hours",
"days" ]
+ ),
+ DropdownChoice(
+ title = _("Until"),
+ choices = [
+ ('next_day', _("Start of next day")),
+ ('next_week', _("Start of next
week")),
+ ('next_month', _("Start of next
month")),
+ ('next_year', _("Start of next
year")),
+ ],
+ default_value = "next_day"
+ )
+ ],
+ style = "dropdown",
+ default_value = 24 *60 * 60,
+ ))
+ ],
+ optional_keys = [],
+ ),
+ title = _("Custom Downtime Timeranges"),
+ movable = True,
+ totext = _("%d timeranges"),
+ default_value = [
+ {'title': _("2 hours"), 'end': 2 * 60 * 60},
+ {'title': _("Today"), 'end':
'next_day'},
+ {'title': _("This week"), 'end':
'next_week'},
+ {'title': _("This month"), 'end':
'next_month'},
+ {'title': _("This year"), 'end':
'next_year'},
+ ]
+ ),
+ domain = "multisite",
+)
+
+
def get_builtin_icons():
import views
return [ (id, id) for id in views.get_multisite_icons().keys() ]