Skip to content

Commit

Permalink
Move cmk_base to cmk.base
Browse files Browse the repository at this point in the history
cmk_base was the first larger Python module we built and does not fit
correctly into our current module hierarchy. The correct place is
cmk.base. This commits moves the files over.

Change-Id: I424a9f3a251e47c7e052751fbb9e0c1c6cd5152b
  • Loading branch information
LarsMichelsen committed Jan 7, 2020
1 parent 2e43320 commit 0ad3357
Show file tree
Hide file tree
Showing 175 changed files with 818 additions and 819 deletions.
9 changes: 0 additions & 9 deletions Makefile
Expand Up @@ -197,15 +197,6 @@ $(DISTNAME).tar.gz: omd/packages/mk-livestatus/mk-livestatus-$(VERSION).tar.gz .
--exclude "cme.py*" \
cmk/* ; \
rm cmk/*.pyc
$(PIPENV2) run python -m compileall cmk_base ; \
tar czf $(DISTNAME)/base.tar.gz \
$(TAROPTS) \
--exclude "cee" \
--exclude "cee.py*" \
--exclude "cme" \
--exclude "cme.py*" \
cmk_base/* ; \
rm cmk_base/*.pyc
tar czf $(DISTNAME)/werks.tar.gz $(TAROPTS) -C .werks werks
tar czf $(DISTNAME)/checks.tar.gz $(TAROPTS) -C checks $$(cd checks ; ls)
tar czf $(DISTNAME)/active_checks.tar.gz $(TAROPTS) -C active_checks $$(cd active_checks ; ls)
Expand Down
2 changes: 1 addition & 1 deletion agents/windows/it/test_old_agent_start_parameters.py
Expand Up @@ -129,7 +129,7 @@ def copy_capfile():


# Pack a directory and return the byte stream of the CAP.
# Excerpt from enterprise/cmk_base/cee/cap.py
# Excerpt from enterprise/cmk/base/cee/cap.py
def pack(install_basedir):
cap = ""
old_cwd = os.path.abspath('.')
Expand Down
20 changes: 10 additions & 10 deletions bin/check_mk
Expand Up @@ -49,18 +49,18 @@ import cmk.utils.debug
import cmk.utils.log
import cmk.utils.paths

import cmk_base # pylint: disable=cmk-module-layer-violation
import cmk_base.console as console # pylint: disable=cmk-module-layer-violation
import cmk_base.config as config # pylint: disable=cmk-module-layer-violation
import cmk_base.profiling as profiling # pylint: disable=cmk-module-layer-violation
from cmk_base.modes import modes # pylint: disable=cmk-module-layer-violation
import cmk_base.check_api as check_api # pylint: disable=cmk-module-layer-violation
import cmk_base.crash_reporting # pylint: disable=cmk-module-layer-violation
import cmk.base # pylint: disable=cmk-module-layer-violation
import cmk.base.console as console # pylint: disable=cmk-module-layer-violation
import cmk.base.config as config # pylint: disable=cmk-module-layer-violation
import cmk.base.profiling as profiling # pylint: disable=cmk-module-layer-violation
from cmk.base.modes import modes # pylint: disable=cmk-module-layer-violation
import cmk.base.check_api as check_api # pylint: disable=cmk-module-layer-violation
import cmk.base.crash_reporting # pylint: disable=cmk-module-layer-violation

cmk.utils.log.setup_console_logging()
logger = logging.getLogger("cmk.base")

cmk_base.utils.register_sigint_handler()
cmk.base.utils.register_sigint_handler()

try:
opts, args = getopt.getopt(sys.argv[1:], modes.short_getopt_specs(), modes.long_getopt_specs())
Expand Down Expand Up @@ -117,8 +117,8 @@ except (MKGeneralException, MKBailOut) as e:
sys.exit(3)

except Exception:
crash = cmk_base.crash_reporting.CMKBaseCrashReport.from_exception()
cmk_base.crash_reporting.CrashReportStore().save(crash)
crash = cmk.base.crash_reporting.CMKBaseCrashReport.from_exception()
cmk.base.crash_reporting.CrashReportStore().save(crash)
raise
finally:
profiling.output_profile()
18 changes: 9 additions & 9 deletions bin/update_rrd_fs_names.py
Expand Up @@ -26,13 +26,13 @@
from pathlib2 import Path
import six

import cmk_base.autochecks
import cmk.base.autochecks
try:
import cmk_base.cee.rrd
import cmk.base.cee.rrd
except ImportError:
raise RuntimeError("Can only be used with the Checkmk Enterprise Editions")
import cmk_base.config as config
import cmk_base.check_api as check_api
import cmk.base.config as config
import cmk.base.check_api as check_api

import cmk.utils
import cmk.utils.store as store
Expand Down Expand Up @@ -84,15 +84,15 @@ def get_hostnames(config_cache):

def get_info_file(hostname, servicedesc, source):
if source == 'cmc':
host_dir = cmk_base.cee.rrd.rrd_cmc_host_dir(hostname)
host_dir = cmk.base.cee.rrd.rrd_cmc_host_dir(hostname)
servicefile = cmk.utils.pnp_cleanup(servicedesc)
return os.path.join(host_dir, servicefile + '.info')
return cmk_base.cee.rrd.xml_path_for(hostname, servicedesc)
return cmk.base.cee.rrd.xml_path_for(hostname, servicedesc)


def get_metrics(filepath, source):
if source == 'cmc':
return cmk_base.cee.rrd.read_existing_metrics(filepath)
return cmk.base.cee.rrd.read_existing_metrics(filepath)

root = ET.parse(filepath).getroot()
return [x.text for x in root.findall('.//NAME')]
Expand All @@ -116,7 +116,7 @@ def update_files(args, hostname, servicedesc, item, source):
if update_condition:
if source == 'cmc':
r_metrics = ['fs_used' if x == perfvar else x for x in metrics]
cmk_base.cee.rrd.create_cmc_rrd_info_file(hostname, servicedesc, r_metrics)
cmk.base.cee.rrd.create_cmc_rrd_info_file(hostname, servicedesc, r_metrics)
else:
update_pnp_info_files(perfvar, 'fs_used', filepath)

Expand Down Expand Up @@ -166,7 +166,7 @@ def update_pnp_info_files(perfvar, newvar, filepath):
- Rename matching rrdfile to use newvar
- For all journal files, replace rrdfile with new file"""

rrdfile, rrdfilenew = cmk_base.cee.rrd.update_metric_pnp_xml_info_file(
rrdfile, rrdfilenew = cmk.base.cee.rrd.update_metric_pnp_xml_info_file(
perfvar, newvar, filepath)
os.rename(rrdfile, rrdfilenew)
logger.info("Renamed %s -> %s", rrdfile, rrdfilenew)
Expand Down
5 changes: 3 additions & 2 deletions checks/agent_bi
Expand Up @@ -26,8 +26,9 @@


def agent_bi_arguments(params, hostname, ipaddress):
import cmk_base.data_sources.programs
return cmk_base.data_sources.programs.SpecialAgentConfiguration("", repr(params))
# TODO: Cleanup this separation violation. This should be accessed through the check API
import cmk.base.data_sources.programs
return cmk.base.data_sources.programs.SpecialAgentConfiguration("", repr(params))


special_agent_info['bi'] = agent_bi_arguments
5 changes: 3 additions & 2 deletions checks/agent_prometheus
Expand Up @@ -25,13 +25,14 @@
# Boston, MA 02110-1301 USA.

import copy
import cmk_base.data_sources.programs
# TODO: Cleanup this separation violation. This should be accessed through the check API
import cmk.base.data_sources.programs


def agent_prometheus_arguments(params, _hostname, ipaddress):
prometheus_params = copy.copy(params)
prometheus_params.update({"host_address": ipaddress})
return cmk_base.data_sources.programs.SpecialAgentConfiguration("", repr(prometheus_params))
return cmk.base.data_sources.programs.SpecialAgentConfiguration("", repr(prometheus_params))


special_agent_info['prometheus'] = agent_prometheus_arguments
2 changes: 1 addition & 1 deletion checks/domino_tasks
Expand Up @@ -39,7 +39,7 @@

inv_domino_tasks_rules = []

# Deprecated option since 1.6. cmk_base creates a config warning when finding rules
# Deprecated option since 1.6. cmk.base creates a config warning when finding rules
# for this ruleset. Can be dropped with 1.7.
inv_domino_tasks = []

Expand Down
2 changes: 1 addition & 1 deletion checks/esx_vsphere_hostsystem
Expand Up @@ -31,7 +31,7 @@
# datasources can be defined in Check_MK natively. Therefore we shift
# the detection of the duplicate services directly to this check.
# When it is possible to handle duplicate services for different
# datasources correctly at the cmk_base level this code can be removed.
# datasources correctly at the cmk.base level this code can be removed.
# NOTE: By design the extra_sections are passed to EVERY subcheck and
# therefore have to be removed in every subcheck!
# Change-Id: I3b6a56efcff4c75bbd05a051242e18deaa499d9e
Expand Down
5 changes: 3 additions & 2 deletions checks/fileinfo
Expand Up @@ -268,8 +268,9 @@ def fileinfo_groups_precompile(hostname, item, params):
if group_name_pattern == item:
patterns.append(pattern)

import cmk_base.checking
precomped = cmk_base.checking.determine_check_params(params).copy()
# TODO: Cleanup this separation violation. This should be accessed through the check API
import cmk.base.checking
precomped = cmk.base.checking.determine_check_params(params).copy()
precomped['precompiled_patterns'] = patterns
return precomped

Expand Down
2 changes: 1 addition & 1 deletion checks/local
Expand Up @@ -82,7 +82,7 @@ def _parse_perfentry(entry):
'''parse single perfdata entry
return a named tuple containing check_levels compatible levels field, as well as
cmk_base compatible perfdata 6-tuple.
cmk.base compatible perfdata 6-tuple.
This function may raise Index- or ValueErrors.
'''
Expand Down
2 changes: 1 addition & 1 deletion checks/logwatch
Expand Up @@ -41,7 +41,7 @@ logwatch_max_filesize = 500000 # do not save more than 500k of message (configu
logwatch_service_output = "default"
logwatch_groups = []

# Deprecated option since 1.6. cmk_base creates a config warning when finding rules
# Deprecated option since 1.6. cmk.base creates a config warning when finding rules
# for this ruleset. Can be dropped with 1.7.
logwatch_patterns = {}

Expand Down
2 changes: 1 addition & 1 deletion checks/ps
Expand Up @@ -71,7 +71,7 @@
# 4. levels: four numbers (thresholds)
inventory_processes_rules = []

# Deprecated option since 1.6. cmk_base creates a config warning when finding rules
# Deprecated option since 1.6. cmk.base creates a config warning when finding rules
# for this ruleset. Can be dropped with 1.7.
inventory_processes = []

Expand Down
2 changes: 1 addition & 1 deletion checks/services
Expand Up @@ -40,7 +40,7 @@
# BITS running/demand Intelligenter Hintergrund<FC>bertragungsdienst
# Bonjour_Service running/auto Dienst "Bonjour"

# Deprecated option since 1.6. cmk_base creates a config warning when finding rules
# Deprecated option since 1.6. cmk.base creates a config warning when finding rules
# for this ruleset. Can be dropped with 1.7.
inventory_services = []

Expand Down
31 changes: 31 additions & 0 deletions cmk/base/.f12
@@ -0,0 +1,31 @@
#!/bin/bash
set -e

SITE=${SITE:-$(until [ $PWD == / ]; do if [ -e .site ]; then
cat .site
break
else cd ..; fi; done)}
SITE=${SITE:-$(omd sites --bare | head -n 1)}
ROOT=/omd/sites/$SITE

echo "Update site $SITE..."

echo "Copy CRE files..."
sudo rsync \
--exclude=cee \
--exclude=cee.py \
--exclude=cme.py \
-a * $ROOT/lib/python/cmk/base/
sudo pycompile -q $ROOT/lib/python/cmk/base

# Also deploy all other directories of same type
if [ ${ALL_EDITIONS:-1} != 0 ]; then
for WHAT in enterprise managed; do
if [ -e ../../$WHAT/cmk/base/.f12 ]; then
(
cd ../../$WHAT/cmk/base
ONLY_COPY=1 ALL_EDITIONS=0 bash .f12
)
fi
done
fi
6 changes: 3 additions & 3 deletions cmk_base/__init__.py → cmk/base/__init__.py
Expand Up @@ -28,14 +28,14 @@
discovery and a lot of other functionality."""

import sys
import cmk_base.caching
from .caching import CacheManager

# This cache manager holds all caches that rely on the configuration
# and have to be flushed once the configuration is reloaded in the
# keepalive mode
config_cache = cmk_base.caching.CacheManager()
config_cache = CacheManager()

# These caches are not automatically cleared during the whole execution
# time of the current Check_MK process. Single cached may be cleaned
# manually during execution.
runtime_cache = cmk_base.caching.CacheManager()
runtime_cache = CacheManager()
File renamed without changes.
14 changes: 7 additions & 7 deletions cmk_base/autochecks.py → cmk/base/autochecks.py
Expand Up @@ -38,13 +38,13 @@
from cmk.utils.exceptions import MKGeneralException
from cmk.utils.encoding import convert_to_unicode

import cmk_base.config as config
import cmk_base.console
from cmk_base.discovered_labels import (
import cmk.base.config as config
import cmk.base.console
from cmk.base.discovered_labels import (
DiscoveredServiceLabels,
ServiceLabel,
)
from cmk_base.check_utils import ( # pylint: disable=unused-import
from cmk.base.check_utils import ( # pylint: disable=unused-import
CheckPluginName, CheckParameters, DiscoveredService, Item, Service,
)

Expand Down Expand Up @@ -144,20 +144,20 @@ def _read_raw_autochecks_of(self, hostname):

check_config = config.get_check_variables()
try:
cmk_base.console.vverbose("Loading autochecks from %s\n", filepath)
cmk.base.console.vverbose("Loading autochecks from %s\n", filepath)
autochecks_raw = eval(
open(filepath).read().decode("utf-8"), check_config,
check_config) # type: List[Dict]
except SyntaxError as e:
cmk_base.console.verbose("Syntax error in file %s: %s\n",
cmk.base.console.verbose("Syntax error in file %s: %s\n",
filepath,
e,
stream=sys.stderr)
if cmk.utils.debug.enabled():
raise
return result
except Exception as e:
cmk_base.console.verbose("Error in file %s:\n%s\n", filepath, e, stream=sys.stderr)
cmk.base.console.verbose("Error in file %s:\n%s\n", filepath, e, stream=sys.stderr)
if cmk.utils.debug.enabled():
raise
return result
Expand Down
Expand Up @@ -35,11 +35,11 @@
from cmk.utils.encoding import make_utf8
from cmk.utils.exceptions import MKException

import cmk_base.utils
import cmk_base.config as config
import cmk_base.console as console
import cmk_base.profiling as profiling
import cmk_base.check_api as check_api
import cmk.base.utils
import cmk.base.config as config
import cmk.base.console as console
import cmk.base.profiling as profiling
import cmk.base.check_api as check_api


# TODO: Inherit from MKGeneralException
Expand Down

0 comments on commit 0ad3357

Please sign in to comment.