Module: check_mk
Branch: master
Commit: 17a7d43cafbfc6f8fe8513d483803a1974e6e90d
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=17a7d43cafbfc6…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Wed Dec 5 16:06:04 2012 +0100
New option when setting host downtimes for also including child hosts
---
ChangeLog | 1 +
web/plugins/views/commands.py | 96 ++++++++++++++++++++++++++++------------
2 files changed, 68 insertions(+), 29 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index fe97010..92f3499 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -37,6 +37,7 @@
* FIX: warn / crit levels in if-check when using "bit" as unit
* Use pprint when writing global settings (makes files more readable)
* New script for settings/removing downtimes: doc/treasures/downtime
+ * New option when setting host downtimes for also including child hosts
WATO:
* FIX: Fixed generated manual check definitions for checks without items
diff --git a/web/plugins/views/commands.py b/web/plugins/views/commands.py
index 5fa9df4..a9b4998 100644
--- a/web/plugins/views/commands.py
+++ b/web/plugins/views/commands.py
@@ -383,41 +383,79 @@ def command_downtime(cmdtag, spec, row):
else:
fixed = 1
duration = 0
- command = (("SCHEDULE_" + cmdtag + "_DOWNTIME;%s;" % spec) \
+
+ if html.var("_include_childs"): # only for hosts
+ specs = [ spec ] + get_child_hosts(row["site"], [spec], recurse =
not not html.var("_include_childs_recurse"))
+ else:
+ specs = [ spec ]
+
+ commands = [(("SCHEDULE_" + cmdtag + "_DOWNTIME;%s;" % spec )
\
+ ("%d;%d;%d;0;%d;%s;" % (down_from, down_to, fixed,
duration, config.user_id)) \
- + comment)
- return command, title
+ + comment) for spec in specs]
+ return commands, title
+
+def get_child_hosts(site, hosts, recurse):
+ hosts = set(hosts)
+ html.live.set_only_sites([site])
+ query = "GET hosts\nColumns: name\n"
+ for h in hosts:
+ query += "Filter: parents >= %s\n" % h
+ query += "Or: %d\n" % len(hosts)
+ childs = html.live.query_column(query)
+ html.live.set_only_sites(None)
+ # Recursion, but try to avoid duplicate work
+ childs = set(childs)
+ new_childs = childs.difference(hosts)
+ if new_childs and recurse:
+ rec_childs = get_child_hosts(site, new_childs, True)
+ new_childs.update(rec_childs)
+ return list(new_childs)
+
+def paint_downtime_buttons(what):
+ html.write(_('Downtime Comment')+": ")
+ html.text_input("_down_comment", size=40)
+ 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"))
+ html.write(" - ")
+ html.button("_down_remove", _("Remove all"))
+ html.write("<hr>")
+ html.button("_down_custom", _("Custom time range"))
+ html.datetime_input("_down_from", time.time())
+ html.write(" "+_('to')+" ")
+ html.datetime_input("_down_to", time.time() + 7200)
+ html.write("<hr>")
+ html.button("_down_from_now", _("From now for"))
+ html.write(" ")
+ html.number_input("_down_minutes", 60, size=4, style="text-align:
right")
+ html.write(" " + _("minutes"))
+ html.write("<hr>")
+ html.checkbox("_down_flexible", False, label=_('flexible with max.
duration')+" ")
+ html.time_input("_down_duration", 2, 0)
+ html.write(" "+_('(HH:MM)'))
+ if what == "host":
+ html.write("<hr>")
+ html.checkbox("_include_childs", False, label=_('Also set downtime
on child hosts'))
+ html.write(" ")
+ html.checkbox("_include_childs_recurse", False, label=_('Do this
recursively'))
multisite_commands.append({
- "tables" : [ "host", "service" ],
+ "tables" : [ "host" ],
"permission" : "action.downtimes",
"title" : _("Schedule downtimes"),
- "render" : lambda: \
- 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")) == \
- html.write(" - ") == \
- html.button("_down_remove", _("Remove all")) == \
- html.write("<hr>") == \
- html.button("_down_custom", _("Custom time range")) == \
- html.datetime_input("_down_from", time.time()) == \
- html.write(" "+_('to')+" ") == \
- html.datetime_input("_down_to", time.time() + 7200) == \
- html.write("<hr>") == \
- html.button("_down_from_now", _("From now for")) == \
- html.write(" ") == \
- html.number_input("_down_minutes", 60, size=4, style="text-align:
right") == \
- html.write(" " + _("minutes")) == \
- html.write("<hr>") == \
- html.checkbox("_down_flexible", False, label=_('flexible with max.
duration')+" ") == \
- html.time_input("_down_duration", 2, 0) == \
- html.write(" "+_('(HH:MM)')) == \
- html.write("<hr>") == \
- html.write(_('Comment')+": ") == \
- html.text_input("_down_comment", size=48),
+ "render" : lambda: paint_downtime_buttons("host"),
+ "action" : command_downtime,
+})
+
+multisite_commands.append({
+ "tables" : [ "service" ],
+ "permission" : "action.downtimes",
+ "title" : _("Schedule downtimes"),
+ "render" : lambda: paint_downtime_buttons("service"),
"action" : command_downtime,
})