Module: check_mk
Branch: master
Commit: c1ecdcb1b7684c16c53079e1dc0a55a1c393fefc
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=c1ecdcb1b7684c…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Fri Feb 4 16:30:49 2011 +0100
Fixed downtime handling
---
ChangeLog | 1 +
web/htdocs/htmllib.py | 16 ++++++++++++++++
web/htdocs/views.py | 17 +++++------------
web/plugins/views/builtin.py | 35 +++++++++++++++++++----------------
web/plugins/views/painters.py | 14 +++++++++++++-
5 files changed, 54 insertions(+), 29 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 5aefdb9..ebd7d87 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -8,6 +8,7 @@
send notification and persisten comment
* Downtimes: allow to specify fixed/flexible downtime
* new display_options d/D for switching on/off the tab "Display"
+ * Improved builtin views for downtimes
WATO:
* Fixed problem appearing at restart on older Python version (RH)
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index 13f6a1c..14d800f 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -346,6 +346,22 @@ class html:
"Please enter the date/time in the format YYYY-MM-DD
HH:MM")
return int(time.mktime(br))
+ def get_time_input(self, varname, what):
+ t = self.var(varname)
+ if not t:
+ raise MKUserError(varname, "Please specify %s" % what)
+
+ try:
+ h, m = t.split(":")
+ m = int(m)
+ h = int(h)
+ if m < 0 or m > 59 or h < 0:
+ raise Exception()
+ except:
+ raise MKUserError(varname, "Please enter the time in the format
HH:MM")
+ return m * 60 + h * 3600
+
+
def html_head(self, title):
if not self.req.header_sent:
self.req.write(
diff --git a/web/htdocs/views.py b/web/htdocs/views.py
index 79ffab0..e696b8c 100644
--- a/web/htdocs/views.py
+++ b/web/htdocs/views.py
@@ -1632,9 +1632,9 @@ def show_host_service_actions(what):
html.write("</td></tr>")
html.write("<tr><td class=content>")
html.checkbox("_down_flexible", False)
- html.write(" flexible (automatically end downtime as soon as %s is %s
again)" %
- (what, what == "host" and "up" or "OK"))
- html.write("</td></tr>\n")
+ html.write(" flexible with max. duration ")
+ html.time_input("_down_duration", 2, 0)
+ html.write(" (HH:MM)</td></tr>\n")
html.write("<tr><td class=content><div
class=textinputlegend>Comment:</div>\n")
html.text_input("_down_comment")
@@ -1786,12 +1786,6 @@ def nagios_host_service_action_command(what, dataset):
time.asctime(time.localtime(down_from)),
time.asctime(time.localtime(down_to)))
- # handle hidden field (added for NagStaMon)
- elif html.var("_down_duration") and
config.may("action.downtimes"):
- duration = int(html.var("_down_duration"))
- down_to = down_from + duration
- title = "<b>schedule a downtime from now lasting for %d
seconds</b> on " % duration
-
elif html.var("_down_remove") and
config.may("action.downtimes"):
downtime_ids = []
for id in dataset[prefix + "downtimes"]:
@@ -1812,11 +1806,10 @@ def nagios_host_service_action_command(what, dataset):
raise MKUserError("_down_comment", "You need to supply a
comment for your downtime.")
if html.var("_down_flexible"):
fixed = 0
+ duration = html.get_time_input("_down_duration", "the
duration")
else:
fixed = 1
- duration = down_to - down_from
- if fixed == 0 and abs(down_from - time.time()) > 80:
- raise MKUserError("_down_from", "When creating flexible
downtimes the start time must be now.")
+ duration = 0
command = (("SCHEDULE_" + cmdtag + "_DOWNTIME;%s;" % spec) \
+ ("%d;%d;%d;0;%d;%s;" % (down_from, down_to, fixed,
duration, html.req.user)) \
+ comment)
diff --git a/web/plugins/views/builtin.py b/web/plugins/views/builtin.py
index 2a60cee..1e7b55f 100644
--- a/web/plugins/views/builtin.py
+++ b/web/plugins/views/builtin.py
@@ -237,12 +237,16 @@ multisite_builtin_views = {
'name': 'downtimes',
'num_columns': 1,
'owner': '',
- 'painters': [('host', None),
- ('service_description', None),
+ 'painters': [('host', 'host'),
+ ('service_description', 'service'),
+ ('downtime_author', None),
+ ('downtime_entry_time', None),
('downtime_start_time', None),
('downtime_end_time', None),
- ('downtime_author', None),
+ ('downtime_fixed', None),
+ ('downtime_duration', None),
('downtime_comment', None)],
+
'public': True,
'show_filters': ['service_scheduled_downtime_depth',
'hostregex',
@@ -264,12 +268,12 @@ multisite_builtin_views = {
'num_columns': 1,
'owner': '',
'painters': [('downtime_author', None),
- ('downtime_entry_time', None),
- ('downtime_comment', None),
- ('downtime_start_time', None),
- ('downtime_end_time', None),
- ('downtime_id', None),
- ('downtime_fixed', None)],
+ ('downtime_entry_time', None),
+ ('downtime_start_time', None),
+ ('downtime_end_time', None),
+ ('downtime_fixed', None),
+ ('downtime_duration', None),
+ ('downtime_comment', None)],
'public': True,
'show_filters': [],
'sorters': [],
@@ -289,13 +293,12 @@ multisite_builtin_views = {
'num_columns': 1,
'owner': '',
'painters': [('downtime_author', None),
- ('downtime_entry_time', None),
- ('downtime_comment', None),
- ('downtime_start_time', None),
- ('downtime_end_time', None),
- ('downtime_id', None),
- ('downtime_fixed', None),
- ('svc_in_downtime', None)],
+ ('downtime_entry_time', None),
+ ('downtime_start_time', None),
+ ('downtime_end_time', None),
+ ('downtime_fixed', None),
+ ('downtime_duration', None),
+ ('downtime_comment', None)],
'public': True,
'show_filters': [],
'sorters': [],
diff --git a/web/plugins/views/painters.py b/web/plugins/views/painters.py
index 256110b..c2e826d 100644
--- a/web/plugins/views/painters.py
+++ b/web/plugins/views/painters.py
@@ -1370,7 +1370,7 @@ multisite_painters["downtime_fixed"] = {
"title" : "Downtime is fixed",
"short" : "Fixed",
"columns" : ["downtime_fixed"],
- "paint" : lambda row: (None, row["downtime_fixed"] ==
"0" and "flexible" or "fixed")
+ "paint" : lambda row: (None, row["downtime_fixed"] == 0 and
"flexible" or "fixed")
}
multisite_painters["downtime_what"] = {
"title" : "Downtime type (host/service)",
@@ -1406,6 +1406,18 @@ multisite_painters["downtime_end_time"] = {
"options" : [ "ts_format", "ts_date" ],
"paint" : lambda row: paint_age(row["downtime_end_time"], True,
3600)
}
+def paint_downtime_duration(row):
+ if row["downtime_fixed"] == 1:
+ return None, ""
+ else:
+ return None, "%02d:%02d" % divmod(row["downtime_duration"] /
60, 60)
+
+multisite_painters["downtime_duration"] = {
+ "title" : "Downtime duration (if flexible)",
+ "short" : "Duration",
+ "columns" : ["downtime_duration", "downtime_fixed"],
+ "paint" : paint_downtime_duration
+}
# _
# | | ___ __ _