Module: check_mk
Branch: master
Commit: 1c811fc4e3cf80ec8d9ca3955cb2ce50c4bb5926
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=1c811fc4e3cf80…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Mon Oct 14 20:57:20 2013 +0200
WATO: New option for full SNMP scan in bulk inventory
---
ChangeLog | 1 +
modules/automation.py | 35 +++++++++++++++++++++++++----------
modules/check_mk_base.py | 4 +++-
web/htdocs/wato.py | 10 +++++++---
4 files changed, 36 insertions(+), 14 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 46ba14f..d2f562c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -27,6 +27,7 @@
* You can now have site-specific global settings when using
distributed WATO (available in the "Distributed Monitoring")
* bulk inventory: display percentage in progress bar
+ * New option for full SNMP scan in bulk inventory
* FIX: correct display of number of hosts in bulk inventory
1.2.3i4:
diff --git a/modules/automation.py b/modules/automation.py
index f9b7034..8a46ee3 100644
--- a/modules/automation.py
+++ b/modules/automation.py
@@ -89,10 +89,20 @@ def do_automation(cmd, args):
# "fixall" - find new, remove exceeding
# "refresh" - drop all services and reinventorize
def automation_inventory(args):
- global opt_use_cachefile, inventory_max_cachefile_age
- if args[0] == "--cache":
+ global opt_use_cachefile, inventory_max_cachefile_age, check_max_cachefile_age
+
+ # perform full SNMP scan on SNMP devices?
+ if args[0] == "@scan":
+ with_snmp_scan = True
+ args = args[1:]
+ else:
+ with_snmp_scan = False
+
+ # use cache files if present?
+ if args[0] == "@cache":
opt_use_cachefile = True
inventory_max_cachefile_age = 1000000000
+ check_max_cachefile_age = 1000000000
args = args[1:]
else:
opt_use_cachefile = False
@@ -119,7 +129,7 @@ def automation_inventory(args):
for hostname in hostnames:
try:
# Compute current state of new and existing checks
- table = automation_try_inventory([hostname], leave_no_tcp=True)
+ table = automation_try_inventory([hostname], leave_no_tcp=True,
with_snmp_scan=with_snmp_scan)
# Create new list of checks
new_items = []
@@ -158,13 +168,17 @@ def automation_inventory(args):
return (count_added, count_removed, count_kept, count_new), failed_hosts
-def automation_try_inventory(args, leave_no_tcp=False):
+def automation_try_inventory(args, leave_no_tcp=False, with_snmp_scan=False):
global opt_use_cachefile, inventory_max_cachefile_age, check_max_cachefile_age
- if args[0] == '--cache':
+ if args[0] == '@noscan':
+ args = args[1:]
+ with_snmp_scan = False
opt_use_cachefile = True
check_max_cachefile_age = 1000000000
inventory_max_cachefile_age = 1000000000
+ elif args[0] == '@scan':
args = args[1:]
+ with_snmp_scan = True
hostname = args[0]
@@ -174,7 +188,7 @@ def automation_try_inventory(args, leave_no_tcp=False):
if is_cluster(hostname):
already_added = set([])
for node in nodes_of(hostname):
- new_services = automation_try_inventory_node(node,
leave_no_tcp=leave_no_tcp)
+ new_services = automation_try_inventory_node(node, leave_no_tcp=leave_no_tcp,
with_snmp_scan=with_snmp_scan)
for entry in new_services:
if host_of_clustered_service(node, entry[6]) == hostname:
# 1: check, 6: Service description
@@ -190,7 +204,7 @@ def automation_try_inventory(args, leave_no_tcp=False):
already_added.add( (ct, descr) ) # make it unique
else:
- new_services = automation_try_inventory_node(hostname,
leave_no_tcp=leave_no_tcp)
+ new_services = automation_try_inventory_node(hostname, leave_no_tcp=leave_no_tcp,
with_snmp_scan=with_snmp_scan)
for entry in new_services:
host = host_of_clustered_service(hostname, entry[6])
if host == hostname:
@@ -202,7 +216,7 @@ def automation_try_inventory(args, leave_no_tcp=False):
-def automation_try_inventory_node(hostname, leave_no_tcp=False):
+def automation_try_inventory_node(hostname, leave_no_tcp=False, with_snmp_scan=False):
global opt_use_cachefile, opt_no_tcp, opt_dont_submit
try:
@@ -219,7 +233,7 @@ def automation_try_inventory_node(hostname, leave_no_tcp=False):
snmp_error = None
if is_snmp_host(hostname):
try:
- if opt_use_cachefile:
+ if not with_snmp_scan:
existing_checks = set([ cn for (cn, item) in get_check_table(hostname)
])
for cn in inventorable_checktypes("snmp"):
if cn in existing_checks:
@@ -230,7 +244,8 @@ def automation_try_inventory_node(hostname, leave_no_tcp=False):
if sys_descr == None:
raise MKSNMPError("Cannot get system description via SNMP.
"
"SNMP agent is not responding. Probably
wrong "
- "community or wrong SNMP version.")
+ "community or wrong SNMP version. IP
address is %s" %
+ ipaddress)
found_services = do_snmp_scan([hostname], True, True)
diff --git a/modules/check_mk_base.py b/modules/check_mk_base.py
index 55a7046..1b37a71 100644
--- a/modules/check_mk_base.py
+++ b/modules/check_mk_base.py
@@ -548,7 +548,9 @@ def read_cache_file(relpath, max_cache_age):
sys.stderr.write("Using data from cachefile %s.\n" %
cachefile)
return result
elif opt_debug:
- sys.stderr.write("Skipping cache file %s: Too old\n" % cachefile)
+ sys.stderr.write("Skipping cache file %s: Too old "
+ "(age is %d sec, allowed is %d sec)\n" %
+ (cachefile, cachefile_age(cachefile), max_cache_age))
if simulation_mode and not opt_no_cache:
raise MKGeneralException("Simulation mode and no cachefile present.")
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index e372316..be5ba4f 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -2193,7 +2193,7 @@ def mode_inventory(phase, firsttime):
config.need_permission("wato.services")
check_host_permissions(hostname)
if html.check_transaction():
- cache_options = not html.var("_scan") and [ '--cache' ] or
[]
+ cache_options = html.var("_scan") and [ '@scan' ] or [
'@noscan' ]
table = check_mk_automation(host[".siteid"],
"try-inventory", cache_options + [hostname])
table.sort()
active_checks = {}
@@ -2229,7 +2229,7 @@ def show_service_table(host, firsttime):
hostname = host[".name"]
# Read current check configuration
- cache_options = not html.var("_scan") and [ '--cache' ] or []
+ cache_options = html.var("_scan") and [ '@scan' ] or [
'@noscan' ]
# We first try using the Cache (if the user has not pressed Full Scan).
# If we do not find any data, we omit the cache and immediately try
@@ -2611,7 +2611,9 @@ def mode_bulk_inventory(phase):
load_hosts(folder)
arguments = [how,] + hostnames
if html.var("use_cache"):
- arguments = [ "--cache" ] + arguments
+ arguments = [ "@cache" ] + arguments
+ 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"
@@ -2779,6 +2781,8 @@ def mode_bulk_inventory(phase):
forms.section(_("Performance options"))
html.checkbox("use_cache", True, label=_("Use cached data if
present"))
html.write("<br>")
+ html.checkbox("do_scan", True, label=_("Do full SNMP scan for SNMP
devices"))
+ html.write("<br>")
html.write(_("Number of hosts to handle at once:") + " ")
html.number_input("bulk_size", 10, size=3)