Module: check_mk
Branch: master
Commit: 7e197d053fd6a90c6a47feb67cf18a88bb3b1260
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=7e197d053fd6a9…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Fri Jul 10 11:24:25 2015 +0200
#2373 Skip unmonitored hosts during bulk discovery
Hosts that are set to <i>unmonitored</i> (usually using the selection
<i>Do not monitor this host</i>
in the host tag group <i>Criticality</i) are now being skipped during bulk
discovery. This now behaves
the same like <i>cmk -I</i> on the command line.
---
.werks/2373 | 11 +++++++++++
ChangeLog | 1 +
modules/automation.py | 9 ++++++++-
web/htdocs/wato.py | 23 ++++++++++++++++-------
4 files changed, 36 insertions(+), 8 deletions(-)
diff --git a/.werks/2373 b/.werks/2373
new file mode 100644
index 0000000..6794068
--- /dev/null
+++ b/.werks/2373
@@ -0,0 +1,11 @@
+Title: Skip unmonitored hosts during bulk discovery
+Level: 2
+Component: wato
+Compatible: compat
+Version: 1.2.7i3
+Date: 1436520172
+Class: feature
+
+Hosts that are set to <i>unmonitored</i> (usually using the selection
<i>Do not monitor this host</i>
+in the host tag group <i>Criticality</i) are now being skipped during bulk
discovery. This now behaves
+the same like <i>cmk -I</i> on the command line.
diff --git a/ChangeLog b/ChangeLog
index 3c37aa5..0692a68 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -58,6 +58,7 @@
* 2365 Removed old deprecated notification global options for plain emails...
* 2384 SEC: Prevent user passwords from being visible in webserver log on user
creation...
* 2386 SEC: Fixed possible XSS on WATO rule edit page...
+ * 2373 Skip unmonitored hosts during bulk discovery...
* 2344 FIX: Improved validation of selected rules when editing BI aggregations...
* 2346 FIX: Notifications: Fixed garbled page when switching on/off
bulks/backlog/user rules
* 2372 FIX: Avoid freezing WATO during bulk discovery if hosts do not respond in a
timely manner
diff --git a/modules/automation.py b/modules/automation.py
index 044e6c1..ba2b78e 100644
--- a/modules/automation.py
+++ b/modules/automation.py
@@ -106,11 +106,13 @@ def do_automation(cmd, args):
output_profile()
sys.exit(0)
-# Does inventory for *one* host. Possible values for how:
+# Does discovery for a list of hosts. Possible values for how:
# "new" - find only new services (like -I)
# "remove" - remove exceeding services
# "fixall" - find new, remove exceeding
# "refresh" - drop all services and reinventorize
+# Hosts on the list that are offline (unmonitored) will
+# be skipped.
def automation_discovery(args):
# Error sensivity
@@ -146,6 +148,11 @@ def automation_discovery(args):
for hostname in hostnames:
counts.setdefault(hostname, [0, 0, 0, 0]) # added, removed, kept, total
+
+ if hostname not in all_hosts_untagged:
+ failed_hosts[hostname] = None # means offline
+ continue # unmonitored host
+
try:
# in "refresh" mode we first need to remove all previously
discovered
# checks of the host, so that get_host_services() does show us the
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index aba0f43..d574472 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -3750,6 +3750,8 @@ def mode_bulk_inventory(phase):
site_id, folderpath, hostnamesstring =
html.var("_item").split("|")
hostnames = hostnamesstring.split(";")
num_hosts = len(hostnames)
+ num_skipped_hosts = 0
+ num_failed_hosts = 0
folder = g_folders[folderpath]
load_hosts(folder)
arguments = [how,] + hostnames
@@ -3775,22 +3777,28 @@ def mode_bulk_inventory(phase):
sum_counts[3] += counts[hostname][3]
host = folder[".hosts"][hostname]
if hostname in failed_hosts:
- result_txt += _("Failed to inventorize %s:
%s<br>") % (hostname, failed_hosts[hostname])
- if not host.get("inventory_failed") and not
host.get(".folder", {}).get("_lock_hosts"):
- host["inventory_failed"] = True
- save_hosts(folder)
+ reason = failed_hosts[hostname]
+ if reason == None:
+ result_txt += _("%s: discovery skipped: host not
monitored<br>") % hostname
+ num_skipped_hosts += 1
+ else:
+ num_failed_hosts += 1
+ result_txt += _("%s: discovery failed:
%s<br>") % (hostname, failed_hosts[hostname])
+ if not host.get("inventory_failed") and not
host.get(".folder", {}).get("_lock_hosts"):
+ host["inventory_failed"] = True
+ save_hosts(folder)
else:
- result_txt += _("Inventorized %s<br>\n") %
hostname
+ result_txt += _("%s: discovery successful<br>\n")
% hostname
mark_affected_sites_dirty(folder, hostname, sync=False,
restart=True)
log_pending(AFFECTED, hostname, "bulk-inventory",
- _("Inventorized host: %d added, %d removed, %d kept, %d
total services") %
+ _("Did service discovery on host: %d added, %d removed,
%d kept, %d total services") %
tuple(counts[hostname]))
if "inventory_failed" in host and not
host.get(".folder", {}).get("_lock_hosts"):
del host["inventory_failed"]
save_hosts(folder) # Could be optimized, but difficult here
- result = repr([ 'continue', num_hosts, len(failed_hosts) ] +
sum_counts) + "\n" + result_txt
+ result = repr([ 'continue', num_hosts, num_failed_hosts,
num_skipped_hosts ] + sum_counts) + "\n" + result_txt
except Exception, e:
result = repr([ 'failed', num_hosts, num_hosts, 0, 0, 0, 0, ]) +
"\n"
@@ -3902,6 +3910,7 @@ def mode_bulk_inventory(phase):
_("Bulk Service Discovery"), # title
[ (_("Total hosts"), 0),
(_("Failed hosts"), 0),
+ (_("Skipped hosts"), 0),
(_("Services added"), 0),
(_("Services removed"), 0),
(_("Services kept"), 0),