Module: check_mk
Branch: master
Commit: 994ea58cf57602c8c3d90bc5382f58425bde0de8
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=994ea58cf57602…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Oct 30 15:48:40 2015 +0100
Cleaning up global caches after each host during bulk actions
---
modules/check_mk.py | 9 ++++++++-
modules/discovery.py | 2 ++
modules/inventory.py | 1 +
3 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/modules/check_mk.py b/modules/check_mk.py
index 8402777..6ed4325 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -3260,6 +3260,7 @@ def do_snmptranslate(args):
for translation, line in translated_lines:
sys.stdout.write("%s --> %s\n" % (line, translation))
+
def do_snmpwalk(hostnames):
if opt_oids and opt_extra_oids:
raise MKGeneralException("You cannot specify --oid and --extraoid at the
same time.")
@@ -3267,8 +3268,10 @@ def do_snmpwalk(hostnames):
if len(hostnames) == 0:
sys.stderr.write("Please specify host names to walk on.\n")
return
+
if not os.path.exists(snmpwalks_dir):
os.makedirs(snmpwalks_dir)
+
for host in hostnames:
try:
do_snmpwalk_on(host, snmpwalks_dir + "/" + host)
@@ -3276,6 +3279,8 @@ def do_snmpwalk(hostnames):
sys.stderr.write("Error walking %s: %s\n" % (host, e))
if opt_debug:
raise
+ cleanup_globals()
+
def do_snmpwalk_on(hostname, filename):
verbose("%s:\n" % hostname)
@@ -3309,6 +3314,7 @@ def do_snmpwalk_on(hostname, filename):
out.close()
verbose("Successfully Wrote %s%s%s.\n" % (tty_bold, filename, tty_normal))
+
def do_snmpget(oid, hostnames):
if len(hostnames) == 0:
for host in all_active_realhosts():
@@ -3319,6 +3325,7 @@ def do_snmpget(oid, hostnames):
ip = lookup_ipv4_address(host)
value = get_single_oid(host, ip, oid)
sys.stdout.write("%s (%s): %r\n" % (host, ip, value))
+ cleanup_globals()
def show_paths():
@@ -3600,7 +3607,7 @@ def usage():
cmk -D, --dump [H1 H2 ..] dump all or some hosts
cmk -d HOSTNAME|IPADDRESS show raw information from agent
cmk --check-discovery HOSTNAME check for items not yet checked
- cmk --discover-marked-hosts run discover-marked-hosts for hosts known to
have changed services
+ cmk --discover-marked-hosts run discovery for hosts known to have changed
services
cmk --update-dns-cache update IP address lookup cache
cmk -l, --list-hosts [G1 G2 ...] print list of all hosts
cmk --list-tag TAG1 TAG2 ... list hosts having certain tags
diff --git a/modules/discovery.py b/modules/discovery.py
index bd6d374..ee09c5d 100644
--- a/modules/discovery.py
+++ b/modules/discovery.py
@@ -76,6 +76,8 @@ def do_discovery(hostnames, check_types, only_new):
raise
verbose(" -> Failed: %s\n" % e)
+ cleanup_globals()
+
def do_discovery_for(hostname, check_types, only_new, use_caches, on_error):
# Usually we disable SNMP scan if cmk -I is used without a list of
diff --git a/modules/inventory.py b/modules/inventory.py
index 075d0c5..897eee0 100644
--- a/modules/inventory.py
+++ b/modules/inventory.py
@@ -171,6 +171,7 @@ def do_inv(hostnames):
raise
verbose("Failed: %s\n" % e)
errors.append("Failed to inventorize %s: %s" % (hostname, e))
+ cleanup_globals()
if errors:
raise MKGeneralException("\n".join(errors))