Module: check_mk
Branch: master
Commit: a876d72c81a9b3e469fbcfb625adaadd8452987e
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=a876d72c81a9b3…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Dec 20 14:17:05 2013 +0100
FIX Fixed numbers shown in log entries of bulk inventory
For all hosts inventorized in one single bulk operation the counts in
the created log entry were equal. This were the summarized number of
services found, kept, removed or new ones. Now the numbers show the
individual counts again.
Conflicts:
ChangeLog
web/htdocs/wato.py
---
.werks/422 | 13 +++++++++++++
ChangeLog | 1 +
modules/automation.py | 23 +++++++++++------------
web/htdocs/wato.py | 45 ++++++++++++++++++++++++++++++++++++++++-----
4 files changed, 65 insertions(+), 17 deletions(-)
diff --git a/.werks/422 b/.werks/422
new file mode 100644
index 0000000..63b37dc
--- /dev/null
+++ b/.werks/422
@@ -0,0 +1,13 @@
+Title: Fixed numbers shown in log entries of bulk inventory
+Level: 1
+Component: wato
+Class: fix
+State: unknown
+Version: 1.2.5i1
+Date: 1387545192
+Targetversion: future
+
+For all hosts inventorized in one single bulk operation the counts in
+the created log entry were equal. This were the summarized number of
+services found, kept, removed or new ones. Now the numbers show the
+individual counts again.
diff --git a/ChangeLog b/ChangeLog
index 2c247b6..288b58e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -129,6 +129,7 @@
* 0419 FIX: LDAP: The default user profile roles are only assigned to users without
roles...
* 0249 FIX: Backup & Restore: fixed bug when uploading legacy snapshots...
* 0250 FIX: Fixed error on creating very large WATO snapshots...
+ * 0422 FIX: Fixed numbers shown in log entries of bulk inventory...
Notifications:
* 0362 sms: now searching PATH for sendsms and smssend commands...
diff --git a/modules/automation.py b/modules/automation.py
index f54b76d..66e5d5d 100644
--- a/modules/automation.py
+++ b/modules/automation.py
@@ -118,19 +118,18 @@ def automation_inventory(args):
how = args[0]
hostnames = args[1:]
- count_added = 0
- count_removed = 0
- count_kept = 0
- count_new = 0
-
+ counts = {}
failed_hosts = {}
k = globals().keys()
if how == "refresh":
for hostname in hostnames:
- count_removed += remove_autochecks_of(hostname) # checktype could be added here
+ counts.setdefault(hostname, [0, 0, 0, 0]) # added, removed, kept, new
+ counts[hostname][1] += remove_autochecks_of(hostname) # checktype could be
added here
reread_autochecks()
for hostname in hostnames:
+ counts.setdefault(hostname, [0, 0, 0, 0]) # added, removed, kept, new
+
try:
# Compute current state of new and existing checks
table = automation_try_inventory([hostname], leave_no_tcp=True,
with_snmp_scan=with_snmp_scan)
@@ -144,32 +143,32 @@ def automation_inventory(args):
if state_type == "new":
if how in [ "new", "fixall", "refresh"
]:
- count_added += 1
+ counts[hostname][0] += 1
new_items.append((ct, item, paramstring))
elif state_type == "old":
# keep currently existing valid services in any case
new_items.append((ct, item, paramstring))
- count_kept += 1
+ counts[hostname][2] += 1
elif state_type in [ "obsolete", "vanished" ]:
# keep item, if we are currently only looking for new services
# otherwise fix it: remove ignored and non-longer existing services
if how not in [ "fixall", "remove" ]:
new_items.append((ct, item, paramstring))
- count_kept += 1
+ counts[hostname][2] += 1
else:
- count_removed += 1
+ counts[hostname][1] += 1
automation_write_autochecks_file(hostname, new_items)
- count_new += len(new_items)
+ counts[hostname][3] += len(new_items)
except Exception, e:
if opt_debug:
raise
failed_hosts[hostname] = str(e)
- return (count_added, count_removed, count_kept, count_new), failed_hosts
+ return counts, failed_hosts
def automation_try_inventory(args, leave_no_tcp=False, with_snmp_scan=False):
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index f30546b..3456d49 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -2450,6 +2450,7 @@ def mode_inventory(phase, firsttime):
table.sort()
active_checks = {}
new_target = "folder"
+<<<<<<< HEAD
for st, ct, checkgroup, item, paramstring, params, descr, state, output,
perfdata in table:
if (html.has_var("_cleanup") or
html.has_var("_fixall")) \
and st in [ "vanished", "obsolete" ]:
@@ -2460,6 +2461,32 @@ def mode_inventory(phase, firsttime):
else:
varname = "_%s_%s" % (ct, html.varencode(item))
if html.var(varname, "") != "":
+=======
+
+ if html.var("_refresh"):
+ counts, failed_hosts = check_mk_automation(host[".siteid"],
"inventory", [ "@scan", "refresh", hostname ])
+ count_added, count_removed, count_kept, count_new = counts[hostname]
+ message = _("Refreshed check configuration of host [%s] with %d
services") % \
+ (hostname, count_added)
+ log_pending(LOCALRESTART, hostname, "refresh-autochecks",
message)
+
+ else:
+ table = check_mk_automation(host[".siteid"],
"try-inventory", cache_options + [hostname])
+ table.sort()
+ active_checks = {}
+ for st, ct, checkgroup, item, paramstring, params, descr, state, output,
perfdata in table:
+ if (html.has_var("_cleanup") or
html.has_var("_fixall")) \
+ and st in [ "vanished", "obsolete" ]:
+ pass
+ elif (html.has_var("_activate_all") or
html.has_var("_fixall")) \
+ and st == "new":
+ active_checks[(ct, item)] = paramstring
+ else:
+ varname = "_%s_%s" % (ct, html.varencode(item))
+ if html.var(varname, "") != "":
+ active_checks[(ct, item)] = paramstring
+ if st == "clustered":
+>>>>>>> 29799d8... FIX Fixed numbers shown in log entries of bulk
inventory
active_checks[(ct, item)] = paramstring
if st == "clustered":
active_checks[(ct, item)] = paramstring
@@ -2893,24 +2920,32 @@ def mode_bulk_inventory(phase):
if html.var("do_scan"):
arguments = [ "@scan" ] + arguments
counts, failed_hosts = check_mk_automation(site_id,
"inventory", arguments)
- #counts = ( 1, 2, 3, 4 )
- result = repr([ 'continue', num_hosts, 0 ] + list(counts)) +
"\n"
+ # sum up host individual counts to have a total count
+ sum_counts = [ 0, 0, 0, 0 ]
+ result_txt = ''
for hostname in hostnames:
+ sum_counts[0] += counts[hostname][0]
+ sum_counts[1] += counts[hostname][1]
+ sum_counts[2] += counts[hostname][2]
+ sum_counts[3] += counts[hostname][3]
host = folder[".hosts"][hostname]
if hostname in failed_hosts:
- result += _("Failed to inventorize %s: %s<br>") %
(hostname, failed_hosts[hostname])
+ result_txt += _("Failed to inventorize %s:
%s<br>") % (hostname, failed_hosts[hostname])
if not host.get("inventory_failed"):
host["inventory_failed"] = True
save_hosts(folder)
else:
- result += _("Inventorized %s<br>\n") % hostname
+ result_txt += _("Inventorized %s<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") % counts)
+ _("Inventorized host: %d added, %d removed, %d kept, %d
total services") %
+
tuple(counts[hostname]))
if "inventory_failed" in host:
del host["inventory_failed"]
save_hosts(folder) # Could be optimized, but difficult here
+ result = repr([ 'continue', num_hosts, 0 ] + sum_counts) +
"\n" + result_txt
+
except Exception, e:
result = repr([ 'failed', num_hosts, num_hosts, 0, 0, 0, 0, ]) +
"\n"
if site_id: