Module: check_mk
Branch: master
Commit: 9333ba78ecc3eb25bacec9fb69dd2d2b3ecd4ed5
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=9333ba78ecc3eb…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Wed Jun 6 11:26:02 2018 +0200
Simplified import cycle structure.
Still 11 cycles, but the structure will be easier to break.
Change-Id: I271c42f4ed526f82727bcca9f7367ec605d3ad25
---
cmk_base/automations/check_mk.py | 5 ++--
cmk_base/core.py | 4 ++--
cmk_base/core_nagios.py | 17 --------------
cmk_base/nagios_utils.py | 50 ++++++++++++++++++++++++++++++++++++++++
4 files changed, 54 insertions(+), 22 deletions(-)
diff --git a/cmk_base/automations/check_mk.py b/cmk_base/automations/check_mk.py
index ce81950..382a1c8 100644
--- a/cmk_base/automations/check_mk.py
+++ b/cmk_base/automations/check_mk.py
@@ -45,6 +45,7 @@ import cmk_base.discovery as discovery
from cmk_base.automations import automations, Automation, MKAutomationError
import cmk_base.check_utils
import cmk_base.autochecks
+import cmk_base.nagios_utils
class DiscoveryAutomation(Automation):
@@ -723,8 +724,6 @@ class AutomationRestart(Automation):
# TODO: Cleanup duplicate code with core.do_restart()
def execute(self, args):
- import cmk_base.core_nagios as core_nagios
-
# make sure, Nagios does not inherit any open
# filedescriptors. This really happens, e.g. if
# check_mk is called by WATO via Apache. Nagios inherits
@@ -780,7 +779,7 @@ class AutomationRestart(Automation):
raise
raise MKAutomationError("Error creating configuration: %s" %
e)
- if config.monitoring_core == "cmc" or
core_nagios.do_check_nagiosconfig():
+ if config.monitoring_core == "cmc" or
cmk_base.nagios_utils.do_check_nagiosconfig():
if backup_path:
os.remove(backup_path)
diff --git a/cmk_base/core.py b/cmk_base/core.py
index c5d6ce9..a0ebdc4 100644
--- a/cmk_base/core.py
+++ b/cmk_base/core.py
@@ -41,7 +41,7 @@ from cmk.exceptions import MKGeneralException
import cmk_base.console as console
import cmk_base.config as config
import cmk_base.core_config as core_config
-import cmk_base.core_nagios as core_nagios
+import cmk_base.nagios_utils
from cmk_base.exceptions import MKTimeout
from cmk_base import config_cache
import cmk_base.cleanup
@@ -98,7 +98,7 @@ def do_restart(only_reload = False):
raise
sys.exit(1)
- if config.monitoring_core == "cmc" or
core_nagios.do_check_nagiosconfig():
+ if config.monitoring_core == "cmc" or
cmk_base.nagios_utils.do_check_nagiosconfig():
if backup_path:
os.remove(backup_path)
diff --git a/cmk_base/core_nagios.py b/cmk_base/core_nagios.py
index 91e46d2..414fab7 100644
--- a/cmk_base/core_nagios.py
+++ b/cmk_base/core_nagios.py
@@ -46,23 +46,6 @@ import cmk_base.data_sources as data_sources
import cmk_base.check_utils
-def do_check_nagiosconfig():
- command = [ cmk.paths.nagios_binary, "-vp", cmk.paths.nagios_config_file ]
- console.verbose("Running '%s'\n" %
subprocess.list2cmdline(command))
- console.output("Validating Nagios configuration...")
-
- p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
- close_fds=True)
- exit_status = p.wait()
- if not exit_status:
- console.output(tty.ok + "\n")
- return True
- else:
- console.output("ERROR:\n")
- console.output(p.stdout.read(), stream=sys.stderr)
- return False
-
-
# .--Create config-------------------------------------------------------.
# | ____ _ __ _ |
# | / ___|_ __ ___ __ _| |_ ___ ___ ___ _ __ / _(_) __ _ |
diff --git a/cmk_base/nagios_utils.py b/cmk_base/nagios_utils.py
new file mode 100644
index 0000000..6b793dc
--- /dev/null
+++ b/cmk_base/nagios_utils.py
@@ -0,0 +1,50 @@
+#!/usr/bin/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.
+
+import subprocess
+import sys
+
+import cmk.paths
+import cmk.tty
+
+import cmk_base.console
+
+
+def do_check_nagiosconfig():
+ command = [ cmk.paths.nagios_binary, "-vp", cmk.paths.nagios_config_file ]
+ cmk_base.console.verbose("Running '%s'\n" %
subprocess.list2cmdline(command))
+ cmk_base.console.output("Validating Nagios configuration...")
+
+ p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
+ close_fds=True)
+ exit_status = p.wait()
+ if not exit_status:
+ cmk_base.console.output(cmk.tty.ok + "\n")
+ return True
+ else:
+ cmk_base.console.output("ERROR:\n")
+ cmk_base.console.output(p.stdout.read(), stream=sys.stderr)
+ return False