Module: check_mk
Branch: master
Commit: 4d55e5bde21ddf3de0cf52b05a96be86e60441e5
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=4d55e5bde21ddf…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Thu Sep 11 15:10:41 2014 +0200
#1398 Allow to spread times of next check when rescheduling
When you do the action <i>Reschedule active checks</i> for more than one
active checks then you now can enter a number of minutes. All checks will
then be distributed evenly over that time.
This feature is interesting for checks with larger intervals. Most prominent
example is the <tt>Check_MK Inventory</tt> check, which usually is done every
2, 4 or 24 hours. By spreading the executing of these checks you avoid large
peaks in CPU load.
---
.werks/1398 | 16 ++++++++++++++++
ChangeLog | 1 +
web/htdocs/views.py | 17 ++++++++++++-----
web/plugins/views/commands.py | 30 ++++++++++++++++++++++++------
4 files changed, 53 insertions(+), 11 deletions(-)
diff --git a/.werks/1398 b/.werks/1398
new file mode 100644
index 0000000..20148ee
--- /dev/null
+++ b/.werks/1398
@@ -0,0 +1,16 @@
+Title: Allow to spread times of next check when rescheduling
+Level: 2
+Component: multisite
+Compatible: compat
+Version: 1.2.5i6
+Date: 1410440913
+Class: feature
+
+When you do the action <i>Reschedule active checks</i> for more than one
+active checks then you now can enter a number of minutes. All checks will
+then be distributed evenly over that time.
+
+This feature is interesting for checks with larger intervals. Most prominent
+example is the <tt>Check_MK Inventory</tt> check, which usually is done
every
+2, 4 or 24 hours. By spreading the executing of these checks you avoid large
+peaks in CPU load.
diff --git a/ChangeLog b/ChangeLog
index 5098f31..87bec08 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -92,6 +92,7 @@
Multisite:
* 1066 Implemented Dashboard Designer...
* 1392 WATO Folder filter: show only the paths a user is allowed to see
+ * 1398 Allow to spread times of next check when rescheduling...
* 1067 FIX: Fixed login problem in LDAP connector when no user filter specified...
* 1094 FIX: sidebar snaping 'Tree of folders': fixed exception
* 1154 FIX: Availability: Fixed unwanted redirect to edit annotation page after
editing availability options...
diff --git a/web/htdocs/views.py b/web/htdocs/views.py
index d6ba10d..dfaa22f 100644
--- a/web/htdocs/views.py
+++ b/web/htdocs/views.py
@@ -1890,7 +1890,7 @@ def show_command_form(is_open, datasource):
# (host name, service description, downtime/commands id) and
# construct one or several core command lines and a descriptive
# title.
-def core_command(what, row):
+def core_command(what, row, row_nr, total_rows):
host = row.get("host_name")
descr = row.get("service_description")
@@ -1917,7 +1917,14 @@ def core_command(what, row):
# confirmation dialog.
for cmd in multisite_commands:
if config.may(cmd["permission"]):
- result = cmd["action"](cmdtag, spec, row)
+
+ # Does the command need information about the total number of rows
+ # and the number of the current row? Then specify that
+ if cmd.get("row_stats"):
+ result = cmd["action"](cmdtag, spec, row, row_nr, total_rows)
+ else:
+ result = cmd["action"](cmdtag, spec, row)
+
if result:
executor = cmd.get("executor", command_executor_livestatus)
commands, title = result
@@ -1965,14 +1972,14 @@ def do_actions(view, what, action_rows, backurl):
return False # no actions done
command = None
- title, executor = core_command(what, action_rows[0])[1:3] # just get the title and
executor
+ title, executor = core_command(what, action_rows[0], 0, len(action_rows))[1:3] # just
get the title and executor
if not html.confirm(_("Do you really want to %(title)s the following %(count)d
%(what)s?") %
{ "title" : title, "count" : len(action_rows),
"what" : _(what + "s"), }, method = 'GET'):
return False
count = 0
- for row in action_rows:
- core_commands, title, executor = core_command(what, row)
+ for nr, row in enumerate(action_rows):
+ core_commands, title, executor = core_command(what, row, nr, len(action_rows))
for command in core_commands:
if type(command) == unicode:
command = command.encode("utf-8")
diff --git a/web/plugins/views/commands.py b/web/plugins/views/commands.py
index 4cdc8ef..5f6cdb8 100644
--- a/web/plugins/views/commands.py
+++ b/web/plugins/views/commands.py
@@ -40,21 +40,39 @@
#file('/tmp/1', 'a').write('%s %s\n%s' %
(datetime.datetime.now(), current_language, ''.join(traceback.format_stack())))
# RESCHEDULE ACTIVE CHECKS
+def command_reschedule(cmdtag, spec, row, row_nr, total_rows):
+ if html.var("_resched_checks"):
+ spread = saveint(html.var("_resched_spread"))
+ text = _("<b>reschedule an immediate check")
+ if spread:
+ text += _(" spreaded over %d minutes") % spread
+
+ text += "</b>" + _("of")
+
+ t = time.time()
+ if spread:
+ t += spread * 60.0 * row_nr / total_rows
+
+ command = "SCHEDULE_FORCED_" + cmdtag + "_CHECK;%s;%d" %
(spec, int(t))
+ return command, text
+
config.declare_permission("action.reschedule",
_("Reschedule checks"),
_("Reschedule host and service checks"),
[ "user", "admin" ])
+
multisite_commands.append({
"tables" : [ "host", "service" ],
"permission" : "action.reschedule",
- "title" : _("Reschedule"),
+ "title" : _("Reschedule active checks"),
"render" : lambda: \
- html.button("_resched_checks", _("Reschedule active
checks")),
- "action" : lambda cmdtag, spec, row:
- html.var("_resched_checks") and (
- "SCHEDULE_FORCED_" + cmdtag + "_CHECK;%s;%d" % (spec,
int(time.time())),
- _("<b>reschedule an immediate check</b> of"))
+ html.button("_resched_checks", _("Reschedule")) == \
+ html.write(_("and spread over") + " ") == \
+ html.number_input("_resched_spread", 0, size=3) == \
+ html.write(" " + _("minutes") + " "),
+ "action" : command_reschedule,
+ "row_stats" : True, # Get information about number of rows and current
row nr.
})