Module: check_mk
Branch: master
Commit: 5cc0a0389f99b4c6e1413bccd9db5d217f4dfed0
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=5cc0a0389f99b4…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Fri Apr 10 16:30:23 2015 +0200
Fixed downtime script in treasures
---
.werks/1945 | 6 ++--
ChangeLog | 2 +-
doc/treasures/downtime | 82 +++++++++++++++++++++++++-----------------------
3 files changed, 46 insertions(+), 44 deletions(-)
diff --git a/.werks/1945 b/.werks/1945
index 278a1f7..613208c 100644
--- a/.werks/1945
+++ b/.werks/1945
@@ -1,4 +1,4 @@
-Title: doc/treasures/downtime script: was no longer working because of latest changes in
the GUI
+Title: doc/treasures/downtime: Fix setting and removing of downtimes
Level: 1
Component: multisite
Compatible: compat
@@ -6,5 +6,5 @@ Version: 1.2.7i1
Date: 1424337912
Class: fix
-This little helper script used the wrong multisite filter elements.
-Some of them have been renamed, e.g. from host to host_regex.
+The downtime helper script has been fixed to work with the new
+filter semantics of the host and service views.
diff --git a/ChangeLog b/ChangeLog
index a2308b4..7738037 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -362,7 +362,7 @@
* 1983 FIX: Fixed special case in language configuration via user profile...
* 1984 FIX: Fixed loosing sidebar after switching to/from edit mode in dashboard
edior on page reload...
* 1985 FIX: PNP graph dashlet handles graphs in distributed setups correctly...
- * 1945 FIX: doc/treasures/downtime script: was no longer working because of latest
changes in the GUI...
+ * 1945 FIX: doc/treasures/downtime: Fix setting and removing of downtimes...
* 2008 FIX: Users created during basic auth login get the role assigned configured in
"default user profile"...
* 2011 FIX: "Service Group" view sorts/groups the services now correctly by
host
* 2024 FIX: Views: Fixed problem when filtering views by strings containing
umlauts...
diff --git a/doc/treasures/downtime b/doc/treasures/downtime
index 416e4e9..06a0d82 100755
--- a/doc/treasures/downtime
+++ b/doc/treasures/downtime
@@ -67,14 +67,14 @@ long_options = [ "help", "set",
"remove", "comment=", "url=",
opt_all = False
opt_verbose = 0
opt_mode = 'set'
-opt_comment = "Automatic_downtime"
+opt_comment = "Automatic downtime"
opt_user = "automation"
opt_secret = None
opt_url = None
opt_duration = 120
if omd_site:
- opt_url = "http://localhost/" + omd_site + "/check_mk/"
+ opt_url = "http://localhost/" + omd_site + "/check_mk/"
try:
opts, args = getopt.getopt(sys.argv[1:], short_options, long_options)
except getopt.GetoptError, err:
@@ -110,10 +110,10 @@ for o,a in opts:
if omd_site and not opt_secret:
try:
- opt_secret = file(omd_root + "/var/check_mk/web/" + opt_user
+ opt_secret = file(omd_root + "/var/check_mk/web/" + opt_user
+ "/automation.secret").read().strip()
except Exception, e:
- bail_out("Cannot read automation secret from user %s: %s" %
+ bail_out("Cannot read automation secret from user %s: %s" %
(opt_user, e))
elif not omd_site and not opt_secret:
@@ -145,62 +145,64 @@ verbose("User: " + opt_user)
verbose("Secret: " + (opt_secret or "(none specified)"))
def make_url(base, variables):
- vartext = "&".join([ "%s=%s" % e for e in variables ])
+ vartext = "&".join([ "%s=%s" % (varname, urllib.quote(value))
for (varname, value) in variables ])
return base + "?" + vartext
+def set_downtime(variables, add_vars):
+ url = make_url(opt_url + "view.py", variables + add_vars)
+ verbose("URL: " + url)
+ try:
+ pipe = urllib.urlopen(url)
+ lines = pipe.readlines()
+ verbose(" --> Got %d lines of response" % len(lines))
+ if opt_verbose > 1:
+ for line in lines:
+ verbose("OUTPUT: %s" % line.rstrip())
+ for line in lines:
+ if line.startswith('<div class=error>'):
+ bail_out(line[17:].split('<')[0])
+ except Exception, e:
+ bail_out("Cannot call Multisite URL: %s" % e)
+
+
+# We have 6 different modes:
+# Only the host | 1: set | 4: remove
+# Only specific services | 2: set | 5: remove
+# Host and all services | 3: set | 6: remove
+
+# Authentication and host selection
variables = [
( "_username", opt_user ),
( "_secret", opt_secret ),
( "_transid", "-1" ),
( "_do_confirm", "yes" ),
( "_do_actions", "yes" ),
+ ("host", arg_host ),
]
-if opt_mode == 'remove':
+# Action variables for setting or removing (works in all views)
+if opt_mode == "remove":
variables += [
- ("view_name", "downtimes"),
("_remove_downtimes", "Remove"),
- ("host_regex", arg_host + "$" ),
+ ("_down_remove", "Remove"),
]
else:
variables += [
( "_down_from_now", "yes" ),
- ( "_down_minutes", opt_duration ),
+ ( "_down_minutes", str(opt_duration) ),
( "_down_comment", opt_comment ),
- ("host", arg_host ),
]
- if arg_services:
- variables.append(("view_name", "service"))
- else:
- variables.append(("view_name", "hoststatus"))
-def set_downtime(variables, add_vars):
- url = make_url(opt_url + "view.py", variables + add_vars)
- verbose("URL: " + url)
- try:
- pipe = urllib.urlopen(url)
- lines = pipe.readlines()
- verbose(" --> Got %d lines of response" % len(lines))
- if opt_verbose > 1:
- for line in lines:
- verbose("OUTPUT: %s" % line.rstrip())
- for line in lines:
- if line.startswith('<div class=error>'):
- bail_out(line[17:].split('<')[0])
- except Exception, e:
- bail_out("Cannot call Multisite URL: %s" % e)
+# Downtime on host (handles 1 & 4, needed for 3 & 6)
+if not arg_services:
+ set_downtime(variables, [("view_name", "hoststatus")])
-if arg_services:
- for service in arg_services:
- if opt_mode == "remove":
- set_downtime(variables, [("service", service )])
- else:
- set_downtime(variables, [("service", service )])
+# Downtime on specific services (handles 2 & 5)
else:
- set_downtime(variables, [])
- if opt_all:
- if opt_mode == 'set':
- set_downtime(variables, [("view_name", "service")])
-
+ for service in arg_services:
+ set_downtime(variables, [("view_name", "service"),
("service", service)])
+# Handle services for option --all (3 & 6)
+if opt_all:
+ set_downtime(variables, [("view_name", "host")])