Module: check_mk
Branch: master
Commit: 4a6654ea49b3161c60a6123403bf0576e76dc498
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=4a6654ea49b316…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Tue Jul 1 11:30:23 2014 +0200
FIX doc/treasures/downtime: fix --url option, better error output
---
.werks/1036 | 8 ++++++++
ChangeLog | 1 +
doc/treasures/downtime | 50 +++++++++++++++++++++++++++++-------------------
3 files changed, 39 insertions(+), 20 deletions(-)
diff --git a/.werks/1036 b/.werks/1036
new file mode 100644
index 0000000..1273d43
--- /dev/null
+++ b/.werks/1036
@@ -0,0 +1,8 @@
+Title: doc/treasures/downtime: fix --url option, better error output
+Level: 1
+Component: multisite
+Version: 1.2.5i5
+Date: 1404206990
+Class: fix
+
+
diff --git a/ChangeLog b/ChangeLog
index 55da1ba..a0cce65 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -22,6 +22,7 @@
* 1013 Sort host names naturally, e.g. foobar11 comes after foobar2...
* 1033 New Mutisite filter for the number of services a host has...
* 0945 FIX: Sidebar snapin "Problem hosts": Now excludes hosts and services in downtime
+ * 1036 FIX: doc/treasures/downtime: fix --url option, better error output
WATO:
* 0990 FIX: Fix HTTP error handling in bulk inventory...
diff --git a/doc/treasures/downtime b/doc/treasures/downtime
index 99a0a75..8374419 100755
--- a/doc/treasures/downtime
+++ b/doc/treasures/downtime
@@ -41,40 +41,40 @@ the script only supports cookie based login - no HTTP basic
authentication.
Before you use this script, please read:
-http://mathias-kettner.de/checkmk_multisite_automation.html
-You need to create an automation user - best with the name 'automation'
-- and make sure that this user either has the admin role or is contact
+http://mathias-kettner.de/checkmk_multisite_automation.html
+You need to create an automation user - best with the name 'automation'
+- and make sure that this user either has the admin role or is contact
for all relevant objects.
Options:
- -v, --verbose Show what's going on
+ -v, --verbose Show what's going on (specify twice for more verbose output)
-s, --set Set downtime (this is the default and thus optional)
-r, --remove Remove all downtimes from that host/service
-c, --comment Comment for the downtime (otherwise "Automatic downtime")
-d, --duration Duration of the downtime in minutes (default: 120)
-h, --help Show this help and exit
-u, --user Name of automation user (default: "automation")
- -S, --secret Automation secret (default: read from user settings)
+ -S, --secret Automation secret (default: read from user settings)
-U, --url Base-URL of Multisite (default: guess local OMD site)
-a, --all Include all services when setting/removing host downtime
""")
-short_options = 'vhrsc:d:u:S:a'
-long_options = [ "help", "set", "remove", "comment=",
+short_options = 'vhrsc:d:u:S:aU:'
+long_options = [ "help", "set", "remove", "comment=", "url=",
"duration=", "user=", "secret=", "all" ]
-opt_all = False
-opt_verbose = False
-opt_mode = 'set'
-opt_command = "Automatic downtime"
-opt_user = "automation"
-opt_secret = None
-opt_url = None
+opt_all = False
+opt_verbose = 0
+opt_mode = 'set'
+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/"
+if omd_site:
+ opt_url = "http://localhost/" + omd_site + "/check_mk/"
try:
opts, args = getopt.getopt(sys.argv[1:], short_options, long_options)
except getopt.GetoptError, err:
@@ -90,7 +90,7 @@ for o,a in opts:
# Modifiers
elif o in [ '-v', '--verbose']:
- opt_verbose = True
+ opt_verbose += 1
elif o in [ '-a', '--all']:
opt_all = True
elif o in [ '-s', '--set']:
@@ -116,6 +116,10 @@ if omd_site and not opt_secret:
bail_out("Cannot read automation secret from user %s: %s" %
(opt_user, e))
+elif not omd_site and not opt_secret:
+ bail_out("Please specify the automation secret for the user '%s'!" % opt_user)
+
+
if not opt_url:
bail_out("Please specify the URL to Check_MK Multisite with -U.")
@@ -138,7 +142,7 @@ if arg_services:
verbose("Services: " + " ".join(arg_services))
verbose("Multisite-URL: " + opt_url)
verbose("User: " + opt_user)
-verbose("Secret: " + opt_secret)
+verbose("Secret: " + (opt_secret or "(none specified)"))
def make_url(base, variables):
vartext = "&".join([ "%s=%s" % e for e in variables ])
@@ -174,8 +178,14 @@ def set_downtime(variables, add_vars):
verbose("URL: " + url)
try:
pipe = urllib.urlopen(url)
- l = len(pipe.readlines())
- verbose(" --> Got %d lines of response" % l)
+ 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)