lists.checkmk.com
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2024
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
September
August
July
June
May
April
March
February
January
2011
December
November
October
September
August
July
June
May
April
March
February
January
2010
December
November
October
List overview
Download
Checkmk git commits
April 2019
----- 2024 -----
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
----- 2010 -----
December 2010
November 2010
October 2010
checkmk-commits@lists.checkmk.com
15 participants
599 discussions
Start a n
N
ew thread
Activate shadowVar again.
by Sven Panne
Module: check_mk Branch: master Commit: a257b119b3a2795bdbbf0139eeab1072d0b9ecc3 URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=a257b119b3a279…
Author: Sven Panne <sp(a)mathias-kettner.de> Date: Fri Apr 26 13:25:10 2019 +0200 Activate shadowVar again. Change-Id: Iaed56e320289d0e242134905f4ca8490e45ab434 --- livestatus/src/cppcheck-suppressions.txt | 1 - livestatus/src/module.cc | 16 +++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/livestatus/src/cppcheck-suppressions.txt b/livestatus/src/cppcheck-suppressions.txt index 02ff896..073e164 100644 --- a/livestatus/src/cppcheck-suppressions.txt +++ b/livestatus/src/cppcheck-suppressions.txt @@ -6,7 +6,6 @@ noExplicitConstructor passedByValue preprocessorErrorDirective redundantAssignment -shadowVar shiftTooManyBitsSigned sizeofFunctionCall uninitMemberVar diff --git a/livestatus/src/module.cc b/livestatus/src/module.cc index 88363bc..bde38d9 100644 --- a/livestatus/src/module.cc +++ b/livestatus/src/module.cc @@ -690,13 +690,15 @@ std::string check_path(const std::string &name, const std::string &path) { } void livestatus_parse_arguments(Logger *logger, const char *args_orig) { - // set default path to our logfile to be in the same path as nagios.log - extern char *log_file; - std::string lf{log_file}; - auto slash = lf.rfind('/'); - fl_paths._logfile = - (slash == std::string::npos ? "/tmp/" : lf.substr(0, slash + 1)) + - "livestatus.log"; + { + // set default path to our logfile to be in the same path as nagios.log + extern char *log_file; + std::string lf{log_file}; + auto slash = lf.rfind('/'); + fl_paths._logfile = + (slash == std::string::npos ? "/tmp/" : lf.substr(0, slash + 1)) + + "livestatus.log"; + } if (args_orig == nullptr) { return; // no arguments, use default options
5 years, 5 months
1
0
0
0
postgres_stats: refactoring 4
by Florian Kromer
Module: check_mk Branch: master Commit: 71eb19e36d41589559a2def415cd7419baa19ecc URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=71eb19e36d4158…
Author: Florian Kromer <fk(a)mathias-kettner.de> Date: Fri Apr 26 11:26:00 2019 +0200 postgres_stats: refactoring 4 Change-Id: Id4c27bff9d1371dbccf82ef68ad50777b725e8a7 --- checks/postgres_stats | 54 +++++++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/checks/postgres_stats b/checks/postgres_stats index 9104f85..4382522 100644 --- a/checks/postgres_stats +++ b/checks/postgres_stats @@ -43,6 +43,32 @@ def inventory_postgres_stats(parsed): yield "ANALYZE %s" % db, {} +def _check_never_checked(item, text, never_checked, params, now): + key = "postgres_stats.%s" % item + if not never_checked: + set_item_state(key, now) + yield 0, "No never checked tables" + return + + count = len(never_checked) + infotext = "%d tables were never %s: %s%s" % (count, text, "/".join(never_checked[:5]), + " (first 5 shown)" if count > 5 else "") + levels = params.get("never_analyze_vacuum") + yield int(levels is None), infotext + + last_ts = get_item_state(key) + if last_ts is None: + set_item_state(key, now) + return + yield check_levels( + now - last_ts, + None, + levels, + human_readable_func=get_age_human_readable, + infoname='Unhandled tables for', + ) + + def check_postgres_stats(item, params, parsed): item_type, database = item.split(" ", 1) @@ -78,7 +104,7 @@ def check_postgres_stats(item, params, parsed): now = time.time() if oldest_element: yield 0, "Table: %s" % oldest_element["tname"] - oldest_age = time.time() - int(oldest_element[stats_field]) + oldest_age = now - int(oldest_element[stats_field]) yield check_levels( oldest_age, None, @@ -86,30 +112,8 @@ def check_postgres_stats(item, params, parsed): human_readable_func=get_age_human_readable, infoname='Time since last vacuum') - key = "postgres_stats.%s" % item - if not never_checked: - set_item_state(key, now) - yield 0, "No never checked tables" - return - - count = len(never_checked) - levels = params.get("never_analyze_vacuum") - infotext = "%d tables were never %s: %s%s" % (count, text, "/".join(never_checked[:5]), - " (first 5 shown)" if count > 5 else "") - - yield int(levels is None), infotext - - last_ts = get_item_state(key) - if last_ts is None: - set_item_state(key, now) - return - yield check_levels( - now - last_ts, - None, - levels, - human_readable_func=get_age_human_readable, - infoname='Unhandled tables for', - ) + for subresult in _check_never_checked(item, text, never_checked, params, now): + yield subresult check_info['postgres_stats'] = {
5 years, 5 months
1
0
0
0
Move config.extra_host_attributes processing to HostConfig
by Lars Michelsen
Module: check_mk Branch: master Commit: bf60746a27e2fb042afe92629f8b3c7449f4faf6 URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=bf60746a27e2fb…
Author: Lars Michelsen <lm(a)mathias-kettner.de> Date: Wed Apr 24 09:03:10 2019 +0200 Move config.extra_host_attributes processing to HostConfig CMK-2030 Change-Id: I441a66571857a5a6377ee9bcb9012e6ae30c6ac0 --- cmk_base/config.py | 14 ++++++++++++++ cmk_base/core_config.py | 15 +-------------- tests/unit/cmk_base/test_config.py | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 14 deletions(-) diff --git a/cmk_base/config.py b/cmk_base/config.py index 2451188..6600138 100644 --- a/cmk_base/config.py +++ b/cmk_base/config.py @@ -2582,6 +2582,20 @@ class HostConfig(object): return list(set(self._config_cache.host_extra_conf(self.hostname, host_icons_and_actions))) @property + def extra_host_attributes(self): + # type: () -> Dict[str, str] + attrs = {} + for key, ruleset in extra_host_conf.items(): + values = self._config_cache.host_extra_conf(self.hostname, ruleset) + if values: + if key[0] == "_": + key = key.upper() + + if values[0] is not None: + attrs[key] = values[0] + return attrs + + @property def hostgroups(self): # type: () -> List[str] """Returns the list of hostgroups of this host diff --git a/cmk_base/core_config.py b/cmk_base/core_config.py index 37da308..9c11136 100644 --- a/cmk_base/core_config.py +++ b/cmk_base/core_config.py @@ -383,8 +383,8 @@ def _icons_and_actions_of_service(config_cache, host_config, svcdesc, checkname, def get_host_attributes(hostname, config_cache): - attrs = _extra_host_attributes(config_cache, hostname) host_config = config_cache.get_host_config(hostname) + attrs = host_config.extra_host_attributes # Pre 1.6 legacy attribute. We have changed our whole code to use the # livestatus column "tags" which is populated by all attributes starting with @@ -454,19 +454,6 @@ def _get_tag_attributes(collection, prefix): return {u"__%s_%s" % (prefix, k): unicode(v) for k, v in collection.iteritems()} -def _extra_host_attributes(config_cache, hostname): - attrs = {} - for key, conflist in config.extra_host_conf.items(): - values = config_cache.host_extra_conf(hostname, conflist) - if values: - if key[0] == "_": - key = key.upper() - - if values[0] is not None: - attrs[key] = values[0] - return attrs - - def get_cluster_attributes(config_cache, host_config, nodes): # type: (config.ConfigCache, config.HostConfig, List[str]) -> Dict sorted_nodes = sorted(nodes) diff --git a/tests/unit/cmk_base/test_config.py b/tests/unit/cmk_base/test_config.py index bce2a1e..1182ad1 100644 --- a/tests/unit/cmk_base/test_config.py +++ b/tests/unit/cmk_base/test_config.py @@ -463,6 +463,38 @@ def test_host_config_icons_and_actions(monkeypatch, hostname, result): @pytest.mark.parametrize("hostname,result", [ + ("testhost1", {}), + ("testhost2", { + '_CUSTOM': ['value1'], + 'dingdong': ['value1'] + }), +]) +def test_host_config_extra_host_attributes(monkeypatch, hostname, result): + ts = Scenario().add_host(hostname) + ts.set_option( + "extra_host_conf", { + "dingdong": [ + ([ + "value1", + ], [], ["testhost2"], {}), + ([ + "value2", + ], [], ["testhost2"], {}), + ], + "_custom": [ + ([ + "value1", + ], [], ["testhost2"], {}), + ([ + "value2", + ], [], ["testhost2"], {}), + ], + }) + config_cache = ts.apply(monkeypatch) + assert config_cache.get_host_config(hostname).extra_host_attributes == result + + +(a)pytest.mark.parametrize("hostname,result", [ ("testhost1", ["check_mk"]), ("testhost2", ["dingdong"]), ])
5 years, 5 months
1
0
0
0
Move config.inv_export_hooks processing to HostConfig
by Lars Michelsen
Module: check_mk Branch: master Commit: 50998360c19e13932bf29a28c60bba02e56aaf84 URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=50998360c19e13…
Author: Lars Michelsen <lm(a)mathias-kettner.de> Date: Wed Apr 24 09:58:24 2019 +0200 Move config.inv_export_hooks processing to HostConfig CMK-2030 Change-Id: I0d85ec4e06833db4637b8cc97c8d7761409397cc --- cmk_base/config.py | 10 ++++++++++ cmk_base/inventory.py | 13 ++++--------- tests/unit/cmk_base/test_config.py | 26 ++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/cmk_base/config.py b/cmk_base/config.py index e844725..1c91ff7 100644 --- a/cmk_base/config.py +++ b/cmk_base/config.py @@ -2601,6 +2601,16 @@ class HostConfig(object): inv_parameters.get(section_name, [])) @property + def inventory_export_hooks(self): + # type: () -> List[Tuple[str, Dict]] + hooks = [] # type: List[Tuple[str, Dict]] + for hookname, ruleset in sorted(inv_exports.items(), key=lambda x: x[0]): + entries = self._config_cache.host_extra_conf(self.hostname, ruleset) + if entries: + hooks.append((hookname, entries[0])) + return hooks + + @property def hostgroups(self): # type: () -> List[str] """Returns the list of hostgroups of this host diff --git a/cmk_base/inventory.py b/cmk_base/inventory.py index c89316f..40442f1 100644 --- a/cmk_base/inventory.py +++ b/cmk_base/inventory.py @@ -228,7 +228,7 @@ def _do_inv_for(sources, multi_host_sections, host_config, ipaddress, do_status_ inventory_tree.normalize_nodes() old_timestamp = _save_inventory_tree(hostname, inventory_tree) - _run_inventory_export_hooks(hostname, inventory_tree) + _run_inventory_export_hooks(host_config, inventory_tree) success_msg = [ "Found %s%s%d%s inventory entries" % (tty.bold, tty.yellow, inventory_tree.count_entries(), @@ -408,14 +408,9 @@ def _save_status_data_tree(hostname, status_data_tree): status_data_tree.save_to(cmk.utils.paths.status_data_dir, hostname) -def _run_inventory_export_hooks(hostname, inventory_tree): +def _run_inventory_export_hooks(host_config, inventory_tree): import cmk_base.inventory_plugins as inventory_plugins - hooks = [] - config_cache = config.get_config_cache() - for hookname, ruleset in config.inv_exports.items(): - entries = config_cache.host_extra_conf(hostname, ruleset) - if entries: - hooks.append((hookname, entries[0])) + hooks = host_config.inventory_export_hooks if not hooks: return @@ -426,7 +421,7 @@ def _run_inventory_export_hooks(hostname, inventory_tree): "Execute export hook: %s%s%s%s" % (tty.blue, tty.bold, hookname, tty.normal)) try: func = inventory_plugins.inv_export[hookname]["export_function"] - func(hostname, params, inventory_tree.get_raw_tree()) + func(host_config.hostname, params, inventory_tree.get_raw_tree()) except Exception as e: if cmk.utils.debug.enabled(): raise diff --git a/tests/unit/cmk_base/test_config.py b/tests/unit/cmk_base/test_config.py index e7a0775..66b5d49 100644 --- a/tests/unit/cmk_base/test_config.py +++ b/tests/unit/cmk_base/test_config.py @@ -518,6 +518,32 @@ def test_host_config_inventory_parameters(monkeypatch, hostname, result): @pytest.mark.parametrize("hostname,result", [ + ("testhost1", []), + ("testhost2", [ + ("abc", { + "param1": 1 + }), + ("xyz", { + "param2": 1 + }), + ]), +]) +def test_host_config_inventory_export_hooks(monkeypatch, hostname, result): + ts = Scenario().add_host(hostname) + ts.set_option( + "inv_exports", { + "abc": [({ + "param1": 1 + }, [], ["testhost2"], {}),], + "xyz": [({ + "param2": 1 + }, [], ["testhost2"], {}),], + }) + config_cache = ts.apply(monkeypatch) + assert config_cache.get_host_config(hostname).inventory_export_hooks == result + + +(a)pytest.mark.parametrize("hostname,result", [ ("testhost1", ["check_mk"]), ("testhost2", ["dingdong"]), ])
5 years, 5 months
1
0
0
0
Move config.host_icons_and_actions processing to HostConfig
by Lars Michelsen
Module: check_mk Branch: master Commit: 55d2bdc79e39d4a90e190595b567b93f71e86f3c URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=55d2bdc79e39d4…
Author: Lars Michelsen <lm(a)mathias-kettner.de> Date: Wed Apr 24 08:58:02 2019 +0200 Move config.host_icons_and_actions processing to HostConfig CMK-2030 Change-Id: Ib4d56373a8904336b672679af845602abaeab7cd --- cmk_base/config.py | 5 +++++ cmk_base/core_config.py | 44 ++++++++++++++++++-------------------- tests/unit/cmk_base/test_config.py | 15 +++++++++++++ 3 files changed, 41 insertions(+), 23 deletions(-) diff --git a/cmk_base/config.py b/cmk_base/config.py index 96d9173..2451188 100644 --- a/cmk_base/config.py +++ b/cmk_base/config.py @@ -2577,6 +2577,11 @@ class HostConfig(object): return levels @property + def icons_and_actions(self): + # type: () -> List[str] + return list(set(self._config_cache.host_extra_conf(self.hostname, host_icons_and_actions))) + + @property def hostgroups(self): # type: () -> List[str] """Returns the list of hostgroups of this host diff --git a/cmk_base/core_config.py b/cmk_base/core_config.py index fb498ff..37da308 100644 --- a/cmk_base/core_config.py +++ b/cmk_base/core_config.py @@ -29,7 +29,7 @@ import numbers import os import sys import itertools -from typing import Optional, Any, List, Dict # pylint: disable=unused-import +from typing import Text, Optional, Any, List, Dict # pylint: disable=unused-import import cmk.utils.paths import cmk.utils.tty as tty @@ -170,25 +170,6 @@ def autodetect_plugin(command_line): return command_line -# TODO: Better move to cmk_base.config module -def _icons_and_actions_of(config_cache, what, hostname, svcdesc=None, checkname=None, params=None): - if what == 'host': - return list(set(config_cache.host_extra_conf(hostname, config.host_icons_and_actions))) - else: - actions = set( - config_cache.service_extra_conf(hostname, svcdesc, config.service_icons_and_actions)) - - # Some WATO rules might register icons on their own - if checkname: - checkgroup = config.check_info[checkname]["group"] - if checkgroup in ['ps', 'services'] and isinstance(params, dict): - icon = params.get('icon') - if icon: - actions.add(icon) - - return list(actions) - - def check_icmp_arguments_of(config_cache, hostname, add_defaults=True, family=None): host_config = config_cache.get_host_config(hostname) levels = host_config.ping_levels @@ -358,8 +339,9 @@ def _extra_service_attributes(hostname, description, config_cache, checkname, pa attrs["_%s" % varname.upper()] = value # Add custom user icons and actions - actions = _icons_and_actions_of(config_cache, "service", hostname, description, checkname, - params) + host_config = config_cache.get_host_config(hostname) + actions = _icons_and_actions_of_service(config_cache, host_config, description, checkname, + params) if actions: attrs["_ACTIONS"] = ','.join(actions) return attrs @@ -371,6 +353,22 @@ def _custom_service_attributes_of(config_cache, hostname, service_description): config.custom_service_attributes))) +def _icons_and_actions_of_service(config_cache, host_config, svcdesc, checkname, params): + actions = set( + config_cache.service_extra_conf(host_config.hostname, svcdesc, + config.service_icons_and_actions)) + + # Some WATO rules might register icons on their own + if checkname: + checkgroup = config.check_info[checkname]["group"] + if checkgroup in ['ps', 'services'] and isinstance(params, dict): + icon = params.get('icon') + if icon: + actions.add(icon) + + return list(actions) + + #. # .--HostAttributes------------------------------------------------------. # | _ _ _ _ _ _ _ _ _ | @@ -442,7 +440,7 @@ def get_host_attributes(hostname, config_cache): attrs["_FILENAME"] = path # Add custom user icons and actions - actions = _icons_and_actions_of(config_cache, "host", hostname) + actions = host_config.icons_and_actions if actions: attrs["_ACTIONS"] = ",".join(actions) diff --git a/tests/unit/cmk_base/test_config.py b/tests/unit/cmk_base/test_config.py index 9b55acb..bce2a1e 100644 --- a/tests/unit/cmk_base/test_config.py +++ b/tests/unit/cmk_base/test_config.py @@ -448,6 +448,21 @@ def test_host_config_ping_levels(monkeypatch, hostname, result): @pytest.mark.parametrize("hostname,result", [ + ("testhost1", []), + ("testhost2", ["icon1", "icon2"]), +]) +def test_host_config_icons_and_actions(monkeypatch, hostname, result): + ts = Scenario().add_host(hostname) + ts.set_ruleset("host_icons_and_actions", [ + ("icon1", [], ["testhost2"], {}), + ("icon1", [], ["testhost2"], {}), + ("icon2", [], ["testhost2"], {}), + ]) + config_cache = ts.apply(monkeypatch) + assert config_cache.get_host_config(hostname).icons_and_actions == result + + +(a)pytest.mark.parametrize("hostname,result", [ ("testhost1", ["check_mk"]), ("testhost2", ["dingdong"]), ])
5 years, 5 months
1
0
0
0
Move config.ping_levels processing to HostConfig
by Lars Michelsen
Module: check_mk Branch: master Commit: 248c3e907a605b8e5978c98d71150ec93fcb4e81 URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=248c3e907a605b…
Author: Lars Michelsen <lm(a)mathias-kettner.de> Date: Wed Apr 24 08:48:28 2019 +0200 Move config.ping_levels processing to HostConfig CMK-2030 Change-Id: Ib881070a2fb62c11243318b83bec3d9e363a1663 --- cmk_base/config.py | 12 ++++++++++++ cmk_base/core_config.py | 8 +++----- tests/unit/cmk_base/test_config.py | 24 ++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/cmk_base/config.py b/cmk_base/config.py index 38107df..96d9173 100644 --- a/cmk_base/config.py +++ b/cmk_base/config.py @@ -2565,6 +2565,18 @@ class HostConfig(object): return entries[0] @property + def ping_levels(self): + # type: () -> Dict[str, Union[int, float]] + levels = {} # type: Dict[str, Union[int, float]] + + values = self._config_cache.host_extra_conf(self.hostname, ping_levels) + # TODO: Use host_extra_conf_merged?) + for value in values[::-1]: # make first rules have precedence + levels.update(value) + + return levels + + @property def hostgroups(self): # type: () -> List[str] """Returns the list of hostgroups of this host diff --git a/cmk_base/core_config.py b/cmk_base/core_config.py index 4964d29..fb498ff 100644 --- a/cmk_base/core_config.py +++ b/cmk_base/core_config.py @@ -190,15 +190,13 @@ def _icons_and_actions_of(config_cache, what, hostname, svcdesc=None, checkname= def check_icmp_arguments_of(config_cache, hostname, add_defaults=True, family=None): - values = config_cache.host_extra_conf(hostname, config.ping_levels) - levels = {} - for value in values[::-1]: # make first rules have precedence - levels.update(value) + host_config = config_cache.get_host_config(hostname) + levels = host_config.ping_levels + if not add_defaults and not levels: return "" if family is None: - host_config = config_cache.get_host_config(hostname) family = 6 if host_config.is_ipv6_primary else 4 args = [] diff --git a/tests/unit/cmk_base/test_config.py b/tests/unit/cmk_base/test_config.py index 0537c7d..9b55acb 100644 --- a/tests/unit/cmk_base/test_config.py +++ b/tests/unit/cmk_base/test_config.py @@ -424,6 +424,30 @@ def test_host_config_explicit_check_command(monkeypatch, hostname, core_name, re @pytest.mark.parametrize("hostname,result", [ + ("testhost1", {}), + ("testhost2", { + "ding": 1, + "dong": 1 + }), +]) +def test_host_config_ping_levels(monkeypatch, hostname, result): + ts = Scenario().add_host(hostname) + ts.set_ruleset("ping_levels", [ + ({ + "ding": 1, + }, [], ["testhost2"], {}), + ({ + "ding": 3, + }, [], ["testhost2"], {}), + ({ + "dong": 1, + }, [], ["testhost2"], {}), + ]) + config_cache = ts.apply(monkeypatch) + assert config_cache.get_host_config(hostname).ping_levels == result + + +(a)pytest.mark.parametrize("hostname,result", [ ("testhost1", ["check_mk"]), ("testhost2", ["dingdong"]), ])
5 years, 5 months
1
0
0
0
Move config.active_checks processing to HostConfig
by Lars Michelsen
Module: check_mk Branch: master Commit: 96b9f881c3ebbf8c72df4f121d02e7a81c2504aa URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=96b9f881c3ebbf…
Author: Lars Michelsen <lm(a)mathias-kettner.de> Date: Wed Apr 24 17:53:47 2019 +0200 Move config.active_checks processing to HostConfig CMK-2030 Change-Id: I7c4113557ee7444129e2187045367d9fe3e4e767 --- cmk_base/automations/check_mk.py | 77 +++++++++++++++++++------------------- cmk_base/config.py | 25 ++++++++++++- cmk_base/core_nagios.py | 17 +++------ cmk_base/discovery.py | 30 +++++++-------- tests/unit/cmk_base/test_config.py | 38 +++++++++++++++++++ 5 files changed, 121 insertions(+), 66 deletions(-) Diff:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commitdiff;h=96b9f881c3…
5 years, 5 months
1
0
0
0
Move config.inv_parameters processing to HostConfig
by Lars Michelsen
Module: check_mk Branch: master Commit: 58267b64ce2062d222ab71ee48e7fae566d1c05d URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=58267b64ce2062…
Author: Lars Michelsen <lm(a)mathias-kettner.de> Date: Wed Apr 24 09:48:50 2019 +0200 Move config.inv_parameters processing to HostConfig CMK-2030 Change-Id: Id7b7bf3635792ac30ce75f7b215e181e6250ab2d --- cmk_base/config.py | 5 +++++ cmk_base/inventory.py | 15 +++++---------- tests/unit/cmk_base/test_config.py | 23 +++++++++++++++++++++++ 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/cmk_base/config.py b/cmk_base/config.py index 6600138..e844725 100644 --- a/cmk_base/config.py +++ b/cmk_base/config.py @@ -2595,6 +2595,11 @@ class HostConfig(object): attrs[key] = values[0] return attrs + def inventory_parameters(self, section_name): + # type: (str) -> Dict + return self._config_cache.host_extra_conf_merged(self.hostname, + inv_parameters.get(section_name, [])) + @property def hostgroups(self): # type: () -> List[str] diff --git a/cmk_base/inventory.py b/cmk_base/inventory.py index b0fae6c..c89316f 100644 --- a/cmk_base/inventory.py +++ b/cmk_base/inventory.py @@ -223,8 +223,8 @@ def _do_inv_for(sources, multi_host_sections, host_config, ipaddress, do_status_ _do_inv_for_cluster(host_config, inventory_tree) else: node["is_cluster"] = False - _do_inv_for_realhost(sources, multi_host_sections, hostname, ipaddress, inventory_tree, - status_data_tree, discovered_host_labels) + _do_inv_for_realhost(host_config, sources, multi_host_sections, hostname, ipaddress, + inventory_tree, status_data_tree, discovered_host_labels) inventory_tree.normalize_nodes() old_timestamp = _save_inventory_tree(hostname, inventory_tree) @@ -265,8 +265,8 @@ def _do_inv_for_cluster(host_config, inventory_tree): }) -def _do_inv_for_realhost(sources, multi_host_sections, hostname, ipaddress, inventory_tree, - status_data_tree, discovered_host_labels): +def _do_inv_for_realhost(host_config, sources, multi_host_sections, hostname, ipaddress, + inventory_tree, status_data_tree, discovered_host_labels): for source in sources.get_data_sources(): if isinstance(source, data_sources.SNMPDataSource): source.set_on_error("raise") @@ -324,7 +324,7 @@ def _do_inv_for_realhost(sources, multi_host_sections, hostname, ipaddress, inve kwargs[dynamic_arg_name] = dynamic_arg_value if len(inv_function_args) == 2: - params = _get_inv_params(hostname, section_name) + params = host_config.inventory_parameters(section_name) args = [section_content, params] else: args = [section_content] @@ -340,11 +340,6 @@ def _gather_snmp_check_plugin_names_inventory(host_config, host_config, on_error, do_snmp_scan, for_inventory=True, for_mgmt_board=for_mgmt_board) -def _get_inv_params(hostname, section_name): - return config.get_config_cache().host_extra_conf_merged( - hostname, config.inv_parameters.get(section_name, [])) - - #. # .--Inventory Tree------------------------------------------------------. # | ___ _ _____ | diff --git a/tests/unit/cmk_base/test_config.py b/tests/unit/cmk_base/test_config.py index 1182ad1..e7a0775 100644 --- a/tests/unit/cmk_base/test_config.py +++ b/tests/unit/cmk_base/test_config.py @@ -495,6 +495,29 @@ def test_host_config_extra_host_attributes(monkeypatch, hostname, result): @pytest.mark.parametrize("hostname,result", [ + ("testhost1", {}), + ("testhost2", { + 'value1': 1, + 'value2': 2, + }), +]) +def test_host_config_inventory_parameters(monkeypatch, hostname, result): + ts = Scenario().add_host(hostname) + ts.set_option("inv_parameters", { + "if": [ + ({ + "value1": 1, + }, [], ["testhost2"], {}), + ({ + "value2": 2, + }, [], ["testhost2"], {}), + ], + }) + config_cache = ts.apply(monkeypatch) + assert config_cache.get_host_config(hostname).inventory_parameters("if") == result + + +(a)pytest.mark.parametrize("hostname,result", [ ("testhost1", ["check_mk"]), ("testhost2", ["dingdong"]), ])
5 years, 5 months
1
0
0
0
Move config.custom_checks processing to HostConfig
by Lars Michelsen
Module: check_mk Branch: master Commit: 47c26b5b4f51ba93f3d10130f94bc5f4c62a5215 URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=47c26b5b4f51ba…
Author: Lars Michelsen <lm(a)mathias-kettner.de> Date: Thu Apr 25 07:43:32 2019 +0200 Move config.custom_checks processing to HostConfig CMK-2030 Change-Id: Id3c8f1f49df555b276a5ad4a2330721a8bec071d --- cmk_base/automations/check_mk.py | 52 +++++++++++++++----------------------- cmk_base/config.py | 12 ++++++++- cmk_base/core_nagios.py | 2 +- cmk_base/discovery.py | 5 +--- tests/unit/cmk_base/test_config.py | 22 ++++++++++++++++ 5 files changed, 56 insertions(+), 37 deletions(-) diff --git a/cmk_base/automations/check_mk.py b/cmk_base/automations/check_mk.py index 084288a..94e416a 100644 --- a/cmk_base/automations/check_mk.py +++ b/cmk_base/automations/check_mk.py @@ -682,25 +682,16 @@ class AutomationAnalyseServices(Automation): } # 3. Classical checks - for nr, entry in enumerate(config.custom_checks): - if len(entry) == 4: - rule, tags, hosts, options = entry - if options.get("disabled"): - continue - else: - rule, tags, hosts = entry - - matching_hosts = config.all_matching_hosts(tags, hosts, with_foreign_hosts=True) - if hostname in matching_hosts: - desc = rule["service_description"] - if desc == servicedesc: - result = { - "origin": "classic", - "rule_nr": nr, - } - if "command_line" in rule: # Only active checks have a command line - result["command_line"] = rule["command_line"] - return result + for nr, entry in enumerate(host_config.custom_checks): + desc = entry["service_description"] + if desc == servicedesc: + result = { + "origin": "classic", + "rule_nr": nr, + } + if "command_line" in entry: # Only active checks have a command line + result["command_line"] = entry["command_line"] + return result # 4. Active checks for plugin_name, entries in host_config.active_checks: @@ -1316,20 +1307,19 @@ class AutomationActiveCheck(Automation): hostname, plugin, item = args item = item.decode("utf-8") - config_cache = config.get_config_cache() - host_config = config_cache.get_host_config(hostname) + host_config = config.get_config_cache().get_host_config(hostname) if plugin == "custom": - custchecks = config_cache.host_extra_conf(hostname, config.custom_checks) - for entry in custchecks: - if entry["service_description"] == item: - command_line = self._replace_core_macros(hostname, entry.get( - "command_line", "")) - if command_line: - command_line = core_config.autodetect_plugin(command_line) - return self._execute_check_plugin(command_line) - - return -1, "Passive check - cannot be executed" + for entry in host_config.custom_checks: + if entry["service_description"] != item: + continue + + command_line = self._replace_core_macros(hostname, entry.get("command_line", "")) + if command_line: + command_line = core_config.autodetect_plugin(command_line) + return self._execute_check_plugin(command_line) + + return -1, "Passive check - cannot be executed" else: act_info = config.active_check_info[plugin] # Set host name for host_name()-function (part of the Check API) diff --git a/cmk_base/config.py b/cmk_base/config.py index e103ef2..4c225c8 100644 --- a/cmk_base/config.py +++ b/cmk_base/config.py @@ -2625,7 +2625,11 @@ class HostConfig(object): @property def active_checks(self): # type: () -> List[Tuple[str, List[Any]]] - """Returns the list of active checks configured for this host""" + """Returns the list of active checks configured for this host + + These are configured using the active check formalization of WATO + where the whole parameter set is configured using valuespecs. + """ configured_checks = [] # type: List[Tuple[str, List[Any]]] for plugin_name, ruleset in sorted(active_checks.items(), key=lambda x: x[0]): # Skip Check_MK HW/SW Inventory for all ping hosts, even when the @@ -2642,6 +2646,12 @@ class HostConfig(object): return configured_checks @property + def custom_checks(self): + # type: () -> List[Dict] + """Return the free form configured custom checks without formalization""" + return self._config_cache.host_extra_conf(self.hostname, custom_checks) + + @property def hostgroups(self): # type: () -> List[str] """Returns the list of hostgroups of this host diff --git a/cmk_base/core_nagios.py b/cmk_base/core_nagios.py index 9b3f5fd..feb2442 100644 --- a/cmk_base/core_nagios.py +++ b/cmk_base/core_nagios.py @@ -426,7 +426,7 @@ def _create_nagios_servicedefs(cfg, config_cache, hostname, host_attrs): outfile.write(get_dependencies(hostname, description).encode("utf-8")) # Legacy checks via custom_checks - custchecks = config_cache.host_extra_conf(hostname, config.custom_checks) + custchecks = host_config.custom_checks if custchecks: outfile.write("\n\n# Custom checks\n") for entry in custchecks: diff --git a/cmk_base/discovery.py b/cmk_base/discovery.py index e392eeb..460abc6 100644 --- a/cmk_base/discovery.py +++ b/cmk_base/discovery.py @@ -1020,11 +1020,8 @@ def _merge_manual_services(host_config, services, on_error): for (check_plugin_name, item), (params, descr, _unused_deps) in manual_items.items(): services[(check_plugin_name, item)] = ('manual', repr(params)) - config_cache = config.get_config_cache() - # Add custom checks -> "custom" - custchecks = config_cache.host_extra_conf(hostname, config.custom_checks) - for entry in custchecks: + for entry in host_config.custom_checks: services[('custom', entry['service_description'])] = ('custom', 'None') # Similar for 'active_checks', but here we have parameters diff --git a/tests/unit/cmk_base/test_config.py b/tests/unit/cmk_base/test_config.py index 3819987..2485dc2 100644 --- a/tests/unit/cmk_base/test_config.py +++ b/tests/unit/cmk_base/test_config.py @@ -607,6 +607,28 @@ def test_host_config_active_checks(monkeypatch, hostname, result): @pytest.mark.parametrize("hostname,result", [ + ("testhost1", []), + ("testhost2", [{ + "param1": 1 + }, { + "param2": 2 + }]), +]) +def test_host_config_custom_checks(monkeypatch, hostname, result): + ts = Scenario().add_host(hostname) + ts.set_ruleset("custom_checks", [ + ({ + "param1": 1 + }, [], ["testhost2"], {}), + ({ + "param2": 2 + }, [], ["testhost2"], {}), + ]) + config_cache = ts.apply(monkeypatch) + assert config_cache.get_host_config(hostname).custom_checks == result + + +(a)pytest.mark.parametrize("hostname,result", [ ("testhost1", ["check_mk"]), ("testhost2", ["dingdong"]), ])
5 years, 5 months
1
0
0
0
Move config.notification_parameters processing to HostConfig
by Lars Michelsen
Module: check_mk Branch: master Commit: f23483709fede4bd806a3d80db673ea880b86c6a URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=f23483709fede4…
Author: Lars Michelsen <lm(a)mathias-kettner.de> Date: Wed Apr 24 10:13:52 2019 +0200 Move config.notification_parameters processing to HostConfig CMK-2030 Change-Id: If136d6e34ea6b40172a6434f848a7d4f59a0adcf --- cmk_base/config.py | 5 +++++ cmk_base/notify.py | 4 ++-- tests/unit/cmk_base/test_config.py | 25 +++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/cmk_base/config.py b/cmk_base/config.py index 1c91ff7..1cf1594 100644 --- a/cmk_base/config.py +++ b/cmk_base/config.py @@ -2610,6 +2610,11 @@ class HostConfig(object): hooks.append((hookname, entries[0])) return hooks + def notification_plugin_parameters(self, plugin_name): + # type: (str) -> Dict + return self._config_cache.host_extra_conf_merged( + self.hostname, notification_parameters.get(plugin_name, [])) + @property def hostgroups(self): # type: () -> List[str] diff --git a/cmk_base/notify.py b/cmk_base/notify.py index b60a033..bb99710 100755 --- a/cmk_base/notify.py +++ b/cmk_base/notify.py @@ -589,8 +589,8 @@ def rbn_fallback_contacts(): def rbn_finalize_plugin_parameters(hostname, plugin, rule_parameters): # Right now we are only able to finalize notification plugins with dict parameters.. if isinstance(rule_parameters, dict): - parameters = config.get_config_cache().host_extra_conf_merged( - hostname, config.notification_parameters.get(plugin, [])) + host_config = config.get_config_cache().get_host_config(hostname) + parameters = host_config.notification_plugin_parameters(plugin).copy() parameters.update(rule_parameters) return parameters diff --git a/tests/unit/cmk_base/test_config.py b/tests/unit/cmk_base/test_config.py index 66b5d49..ef3156a 100644 --- a/tests/unit/cmk_base/test_config.py +++ b/tests/unit/cmk_base/test_config.py @@ -544,6 +544,31 @@ def test_host_config_inventory_export_hooks(monkeypatch, hostname, result): @pytest.mark.parametrize("hostname,result", [ + ("testhost1", {}), + ("testhost2", { + 'value1': 1, + 'value2': 2, + }), +]) +def test_host_config_notification_plugin_parameters(monkeypatch, hostname, result): + ts = Scenario().add_host(hostname) + ts.set_option( + "notification_parameters", { + "mail": [ + ({ + "value1": 1, + }, [], ["testhost2"], {}), + ({ + "value1": 2, + "value2": 2, + }, [], ["testhost2"], {}), + ], + }) + config_cache = ts.apply(monkeypatch) + assert config_cache.get_host_config(hostname).notification_plugin_parameters("mail") == result + + +(a)pytest.mark.parametrize("hostname,result", [ ("testhost1", ["check_mk"]), ("testhost2", ["dingdong"]), ])
5 years, 5 months
1
0
0
0
← Newer
1
2
3
4
5
6
7
...
60
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Results per page:
10
25
50
100
200