Module: check_mk
Branch: master
Commit: cfda140a233b791faa1ee28730b81a82314a7e5d
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=cfda140a233b79…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Oct 13 14:19:00 2016 +0200
First steps moving some files from check_mk modules dir to python modules
---
cmk_base/.f12 | 7 ++++++
cmk_base/__init__.py | 29 ++++++++++++++++++++++
{modules => cmk_base}/agent_simulator.py | 7 ++++--
.../compresslog.py => cmk_base/compress_history.py | 0
{modules => cmk_base}/localize.py | 0
modules/check_mk.py | 13 ++++++----
modules/check_mk_base.py | 4 ++-
modules/nagios.py | 3 ---
modules/snmp.py | 4 ++-
tests/pylint/test_pylint_misc.py | 1 +
tests/testlib/pylint_cmk.py | 3 ---
11 files changed, 56 insertions(+), 15 deletions(-)
diff --git a/cmk_base/.f12 b/cmk_base/.f12
new file mode 100644
index 0000000..5372824
--- /dev/null
+++ b/cmk_base/.f12
@@ -0,0 +1,7 @@
+#!/bin/bash
+SITE=${SITE:-$(cat ../.site 2>/dev/null || true)}
+SITE=${SITE:-$(omd sites --bare | head -n 1)}
+OMD_ROOT=/omd/sites/${SITE}
+
+sudo rsync -a *.py $OMD_ROOT/lib/python/cmk_base/
+echo "Installed to $OMD_ROOT/lib/python/cmk_base/"
diff --git a/cmk_base/__init__.py b/cmk_base/__init__.py
new file mode 100644
index 0000000..66c865c
--- /dev/null
+++ b/cmk_base/__init__.py
@@ -0,0 +1,29 @@
+#!/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.
+
+"""This is the python module hierarchy used by Check_MK's core
+components, former called modules. This hosts the checking,
+discovery and a lot of other functionality."""
diff --git a/modules/agent_simulator.py b/cmk_base/agent_simulator.py
similarity index 97%
rename from modules/agent_simulator.py
rename to cmk_base/agent_simulator.py
index f59eedb..9b63d37 100644
--- a/modules/agent_simulator.py
+++ b/cmk_base/agent_simulator.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
# +------------------------------------------------------------------+
# | ____ _ _ __ __ _ __ |
@@ -30,7 +30,7 @@ def our_uptime():
return float((file("/proc/uptime").read().split()[0]))
# replace simulator tags in output
-def agent_simulator_process(output):
+def process(output):
try:
while True:
i = output.find('%{')
@@ -48,6 +48,7 @@ def agent_simulator_process(output):
return output
+
def agentsim_uptime(rate = 1.0, period = None): # period = sinus wave
if period == None:
return int(our_uptime() * rate)
@@ -56,10 +57,12 @@ def agentsim_uptime(rate = 1.0, period = None): # period = sinus wave
u = our_uptime()
return int(u * rate + int(a * math.sin(u * 2.0 * math.pi / period)))
+
def agentsim_enum(values, period = 1): # period is in seconds
hit = int(our_uptime()) / period % len(values)
return values[hit]
+
def agentsim_sinus(base = 50, amplitude = 50, period = 300):
return int(math.sin(our_uptime() * 2.0 * math.pi / period) * amplitude + base)
diff --git a/modules/compresslog.py b/cmk_base/compress_history.py
similarity index 100%
rename from modules/compresslog.py
rename to cmk_base/compress_history.py
diff --git a/modules/localize.py b/cmk_base/localize.py
similarity index 100%
rename from modules/localize.py
rename to cmk_base/localize.py
diff --git a/modules/check_mk.py b/modules/check_mk.py
index 05c2f74..3217d6d 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -266,7 +266,7 @@ config_variable_names = set(vars().keys()).difference(known_vars)
# at check time (and many of what is also needed at administration time).
try:
- modules = [ 'check_mk_base', 'discovery', 'snmp',
'agent_simulator', 'notify', 'events',
+ modules = [ 'check_mk_base', 'discovery', 'snmp',
'notify', 'events',
'alert_handling', 'prediction', 'cmc',
'inline_snmp', 'agent_bakery', 'cap' ]
for module in modules:
if module_exists(module):
@@ -4777,8 +4777,8 @@ try:
do_packaging(args)
done = True
elif o in ['--localize']:
- load_module("localize")
- do_localize(args)
+ import cmk_base.localize
+ cmk_base.localize.do_localize(args)
done = True
elif o == '--donate':
do_donation()
@@ -4868,15 +4868,18 @@ try:
load_module("rrd")
do_create_rrd(args)
done = True
+
elif o == '--convert-rrds':
read_config_files(with_conf_d=True)
load_module("rrd")
do_convert_rrds(args)
done = True
+
elif o == '--compress-history':
- load_module("compresslog")
- do_compress_history(args)
+ import cmk_base.compress_history
+ cmk_base.compress_history.do_compress_history(args)
done = True
+
elif o in [ '-A', '--bake-agents' ]:
if 'do_bake_agents' not in globals():
bail_out("Agent baking is not implemented in your version of
Check_MK. Sorry.")
diff --git a/modules/check_mk_base.py b/modules/check_mk_base.py
index d5cf890..3f39a25 100644
--- a/modules/check_mk_base.py
+++ b/modules/check_mk_base.py
@@ -60,6 +60,8 @@ import cmk.render as render
import cmk.crash_reporting as crash_reporting
import cmk.paths
+import cmk_base.agent_simulator
+
# PLANNED CLEANUP:
# - central functions for outputting verbose information and bailing
# out because of errors. Remove all explicit "if cmk.debug.enabled()...".
@@ -748,7 +750,7 @@ def get_agent_info(hostname, ipaddress, max_cache_age):
write_cache_file(hostname, output)
if agent_simulator:
- output = agent_simulator_process(output)
+ output = cmk_base.agent_simulator.process(output)
return output
diff --git a/modules/nagios.py b/modules/nagios.py
index 9865aaa..1b27163 100644
--- a/modules/nagios.py
+++ b/modules/nagios.py
@@ -1063,9 +1063,6 @@ no_discovery_possible = None
else:
output.write("has_inline_snmp = False\n")
- if agent_simulator:
- output.write(stripped_python_file(cmk.paths.modules_dir +
"/agent_simulator.py"))
-
# check info table
# We need to include all those plugins that are referenced in the host's
# check table
diff --git a/modules/snmp.py b/modules/snmp.py
index c6d5d4a..5adb37f 100644
--- a/modules/snmp.py
+++ b/modules/snmp.py
@@ -30,6 +30,8 @@ import subprocess
import cmk.tty as tty
+import cmk_base.agent_simulator
+
OID_END = 0 # Suffix-part of OID that was not specified
OID_STRING = -1 # Complete OID as string ".1.3.6.1.4.1.343...."
OID_BIN = -2 # Complete OID as binary string
"\x01\x03\x06\x01..."
@@ -516,7 +518,7 @@ def get_stored_snmpwalk(hostname, oid):
if o == oid or o.startswith(oid_prefix + "."):
if len(parts) > 1:
try:
- value = agent_simulator_process(parts[1])
+ value = cmk_base.agent_simulator.process(parts[1])
except:
value = parts[1] # agent simulator missing in precompiled mode
else:
diff --git a/tests/pylint/test_pylint_misc.py b/tests/pylint/test_pylint_misc.py
index 6dc0ebb..8798810 100755
--- a/tests/pylint/test_pylint_misc.py
+++ b/tests/pylint/test_pylint_misc.py
@@ -9,6 +9,7 @@ import testlib.pylint_cmk as pylint_cmk
def test_pylint_misc():
search_paths = [
+ "cmk_base",
"lib",
"bin",
"notifications",
diff --git a/tests/testlib/pylint_cmk.py b/tests/testlib/pylint_cmk.py
index d96ef43..228ca43 100644
--- a/tests/testlib/pylint_cmk.py
+++ b/tests/testlib/pylint_cmk.py
@@ -21,7 +21,6 @@ def ordered_module_files():
"modules/config.py",
"modules/discovery.py",
"modules/snmp.py",
- "modules/agent_simulator.py",
"modules/notify.py",
"modules/events.py",
"modules/nagios.py",
@@ -29,8 +28,6 @@ def ordered_module_files():
"modules/prediction.py",
"modules/automation.py",
"modules/inventory.py",
- "modules/compresslog.py",
- "modules/localize.py",
"../cmc/modules/real_time_checks.py",
"../cmc/modules/alert_handling.py",
"../cmc/modules/keepalive.py",