Module: check_mk
Branch: master
Commit: 81fb7822b83aaaf8be440c3c3e09fdf1d170da89
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=81fb7822b83aaa…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Tue Jun 5 12:35:54 2018 +0200
Removed a few import cycles caused by cleanup_globals().
Change-Id: I6928b6a29bfc1c07b469bcf17f9e596e4b0a287d
---
cmk_base/cleanup.py | 42 ++++++++++++++++++++++++++++++++++++++++++
cmk_base/discovery.py | 3 ++-
cmk_base/inventory.py | 3 ++-
cmk_base/snmp.py | 5 +++--
cmk_base/utils.py | 15 ---------------
5 files changed, 49 insertions(+), 19 deletions(-)
diff --git a/cmk_base/cleanup.py b/cmk_base/cleanup.py
new file mode 100644
index 0000000..f33bd0b
--- /dev/null
+++ b/cmk_base/cleanup.py
@@ -0,0 +1,42 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2014 mk(a)mathias-kettner.de |
+# +------------------------------------------------------------------+
+#
+# This file is part of Check_MK.
+# The official homepage is at
http://mathias-kettner.de/check_mk.
+#
+# check_mk is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation in version 2. check_mk is distributed
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
+# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE. See the GNU General Public License for more de-
+# tails. You should have received a copy of the GNU General Public
+# License along with GNU Make; see the file COPYING. If not, write
+# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+# Boston, MA 02110-1301 USA.
+
+"""Hacky module to avoid cyclic imports. This should
die..."""
+
+import cmk_base.checks
+import cmk_base.item_state
+import cmk_base.core
+import cmk_base.snmp
+
+
+# Reset some global variable to their original value. This is needed in
+# keepalive mode. We could in fact do some positive caching in keepalive mode,
+# e.g. the counters of the hosts could be saved in memory.
+def cleanup_globals():
+ cmk_base.checks.set_hostname("unknown")
+ cmk_base.item_state.cleanup_item_states()
+ cmk_base.core.cleanup_timeperiod_caches()
+ cmk_base.snmp.cleanup_host_caches()
diff --git a/cmk_base/discovery.py b/cmk_base/discovery.py
index 4aa2d60..ace25d6 100644
--- a/cmk_base/discovery.py
+++ b/cmk_base/discovery.py
@@ -53,6 +53,7 @@ import cmk_base.check_table as check_table
import cmk_base.core as core
from cmk_base.exceptions import MKAgentError, MKParseFunctionError, \
MKSNMPError, MKTimeout
+import cmk_base.cleanup
try:
import cmk_base.cee.keepalive as keepalive
@@ -128,7 +129,7 @@ def do_discovery(hostnames, check_plugin_names, only_new):
raise
console.section_error("%s" % e)
finally:
- cmk_base.utils.cleanup_globals()
+ cmk_base.cleanup.cleanup_globals()
# Check whether or not the cluster host autocheck files are still
# existant. Remove them. The autochecks are only stored in the nodes
diff --git a/cmk_base/inventory.py b/cmk_base/inventory.py
index 0561e03..1238b61 100644
--- a/cmk_base/inventory.py
+++ b/cmk_base/inventory.py
@@ -53,6 +53,7 @@ import cmk_base.checking as checking
import cmk_base.discovery as discovery
import cmk_base.ip_lookup as ip_lookup
import cmk_base.data_sources as data_sources
+import cmk_base.cleanup
_inventory_output_dir = cmk.paths.var_dir + "/inventory"
_inventory_archive_dir = cmk.paths.var_dir + "/inventory_archive"
@@ -90,7 +91,7 @@ def do_inv(hostnames):
console.section_error("%s" % e)
finally:
- cmk_base.utils.cleanup_globals()
+ cmk_base.cleanup.cleanup_globals()
@checking.handle_check_mk_check_result("check_mk_active-cmk_inv",
"Check_MK HW/SW Inventory")
diff --git a/cmk_base/snmp.py b/cmk_base/snmp.py
index 840ee91..506b130 100644
--- a/cmk_base/snmp.py
+++ b/cmk_base/snmp.py
@@ -39,6 +39,7 @@ import cmk.store as store
import cmk_base.ip_lookup as ip_lookup
import cmk_base.agent_simulator
from cmk_base.exceptions import MKSNMPError
+import cmk_base.cleanup
try:
import cmk_base.cee.inline_snmp as inline_snmp
@@ -787,7 +788,7 @@ def do_snmpwalk(options, hostnames):
console.error("Error walking %s: %s\n" % (hostname, e))
if cmk.debug.enabled():
raise
- cmk_base.utils.cleanup_globals()
+ cmk_base.cleanup.cleanup_globals()
def do_snmpwalk_on(options, access_data, filename):
@@ -856,4 +857,4 @@ def do_snmpget(*args):
}
value = get_single_oid(access_data, oid)
console.output("%s (%s): %r\n" % (hostname, ipaddress, value))
- cmk_base.utils.cleanup_globals()
+ cmk_base.cleanup.cleanup_globals()
diff --git a/cmk_base/utils.py b/cmk_base/utils.py
index 34801fa..5f7285b 100644
--- a/cmk_base/utils.py
+++ b/cmk_base/utils.py
@@ -160,21 +160,6 @@ def cachefile_age(path):
% (path, e))
-# Reset some global variable to their original value. This
-# is needed in keepalive mode.
-# We could in fact do some positive caching in keepalive
-# mode - e.g. the counters of the hosts could be saved in memory.
-def cleanup_globals():
- import cmk_base.checks
- cmk_base.checks.set_hostname("unknown")
- import cmk_base.item_state
- cmk_base.item_state.cleanup_item_states()
- import cmk_base.core
- cmk_base.core.cleanup_timeperiod_caches()
- import cmk_base.snmp
- cmk_base.snmp.cleanup_host_caches()
-
-
#.
# .--Ctrl-C--------------------------------------------------------------.
# | ____ _ _ ____ |