Checks appearing where they shouldnt

CMK version: 2.5.0p12
OS version: Appliance 1.7.22

Hi @thl-cmk ! We are using your Checkmk / Vendor independent / Check NTP · GitLab Plugin, and after upgrading to 2.5, we observe a very strange behavior here: The corresponding rule is only mapped to two explicit hosts. However, we sometimes receive alerts from other hosts, that should not even have this check:

When clicking on the “view issue” link, the service is already gone, just as if it never existed.

Do you have an idea what is happening here?

Thanks in advance.

Hi Janncek,

no idea right now. As this is an active check it should only run in the context of the host where it is attached to (in your case the explicit hosts from your rule).

To me this looks like in issue with CMK.

Cheers
Thomas

Hi Thomas,

Thanks for the quick response. It’s really strange, as soon as I deactivate the MKP, everything is fine. When it’s active, I see several, totally random and strange issues. Besides the issue mentioned above, I am also getting warnings when activating changes like:

check_mk: Config creation for active check http failed on myhost3: 'str' object has no attribute 'items'
check_mk: Config creation for special agent pure_storage_fa failed on host 'myhost1': 'bool' object has no attribute 'items'
check_mk: Config creation for special agent pure_storage_fa failed on host 'myhost2': 'bool' object has no attribute 'items'

Activating changes also takes much longer, when the MKP is active. Sometimes, the site is shown dead afterwards.

I just received this error after activating:

Error running automation call restart (exit code 1), error:

An error occurred: Error creating configuration: Traceback (most recent call last):
  File "/omd/sites/mysite/lib/python3/cmk/base/nonfree/cmc/helper_config.py", line 1485, in _hosts_worker
    results = _serialize_worker_hosts(hosts_data, worker_id)
  File "/omd/sites/mysite/lib/python3/cmk/base/nonfree/cmc/helper_config.py", line 1354, in _serialize_worker_hosts
    string_pool_bytes, string_pool_count = serialize_string_pool(sp)
                                           ~~~~~~~~~~~~~~~~~~~~~^^^^
  File "/omd/sites/mysite/lib/python3/cmk/base/nonfree/cmc/_string_pool.py", line 32, in serialize_string_pool
    protobuf_string_pool = sp.table
                           ^^^^^^^^
  File "/omd/sites/mysite/lib/python3/cmk/base/nonfree/cmc/_string_pool.py", line 26, in table
    pool.entries.extend(list(self._map.keys()))
    ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: bad argument type for built-in operation

Totally reproduceable by enabling/disabling the package. But it makes no sense right now…

I will try to fix it with support, but I’m afraid they’ll tell me they offer no support for this problem if it is caused by a third party plugin.

Thanks though. If you have any other ideas, I’d much appreciate it :slight_smile:

I think i know what the problem is.
If you enable the package and don’t enable the check on any host nothing should happen.
For me it looks like you enabled the check on a huge amount of hosts and then the config generation got into this strange random problems.

This is a problem with active checks and fetching the “HostConfig” from the server_side_calls_v1 API. I have already a ticket open for a similar problem and this looks like this from my system. In my case it was only a problem if i had active checks enabled on more than 600 hosts and the server side call was fetching the SNMP config for these.

Can you provide a screenshot from your active check config for the NTP?
It should be possible to prevent this problem, if you don’t set a specific “Server IP-address or name” inside the rule.

Hi Andreas,

The rules currently look like this:

Unfortunately, I have to set a specific IP Address here, because the Host has multiple IPs, and NTP here only listens to this one address.

Nonetheless I deleted the IP from both rules and I didnt get any errors so far, but still a warning:

check_mk: Config creation for active check rdp_x224 failed on ...: 'str' object has no attribute 'items'

It gets even more weird:

I have a host with a cert check. It should look like this:

image

When the MKP is enabled, it looks like this:

Also happens on a few other hosts. What is checkmk cooking here :smiley:

If you have a support contract you should raise a ticket as this look like a general problem with classic active checks inside 2.5 under specific circumstances.

In my case i found a workaround with avoiding the fetching of specific host data at config generation.

For what it’s worth, we’re experiencing something similar on 2.5.0p11. In our case, we’re seeing active checks such as ldap and ssh that are configured for a few hosts alarming on the wrong hosts briefly OR errors on the activation page due to missing parameters. Very intermittent.

I almost posted something similar but couldn’t quite determine a commonality to make it logical. I opened a case with our 3rd party support provider yesterday to help narrow it down. We’re scheduled to do some initial triage today. If there’s a CheckMK case #, please let me know and I’ll see if we can associate it to our issue.

Could you explain what you mean by this workaround?

Sincerely,

Scotsie

Hi Scott,

Thanks for your input. I do have a case open since yesterday, SUP-30521. No answer so far. I’ll update the thread if I have new information.

Btw, tonight we were getting alarms for a check “TCP Port 22”, which also should not exist. We do use the “check ssh service” rule on a few hosts, but the service generated from this rule is called different. So yeah, there is definitely a huge problem with active checks in 2.5

My workaround was only, that the active check does not fetch the SNMP config from the host object, i provided this information inside the active check config.
The use active check is the “check_metric” from @r.sander there you have the option to specify the creds manually or let it fetch from the host config object. I had only problems with active checks if the information was fetched from the host config object.

@andreas-doehler , Thank you for the clarification.
I do use the check_snmp_metric plugin so I have updated several rules to explicitly provide the snmp v2 credentials and will monitor the performance.

Just for the protocol: I initially thought it was the MKPs fault, but it obviously isn’t. I disabled it, at least I dont get errors anymore while activating changes, but many active checks are still behaving weird. Furthermore, I still have errors like this in the ui-scheduler log:

OMD[mysite]:~/var/log$ tail -50 ui-job-scheduler/ui-job-scheduler.log
    AutodiscoveryBackgroundJob().execute(
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        job_interface,
        ^^^^^^^^^^^^^^
        debug=args.debug,
        ^^^^^^^^^^^^^^^^^
        use_git=args.use_git,
        ^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/omd/sites/mysite/lib/python3/cmk/gui/watolib/autodiscovery.py", line 72, in execute
    result = autodiscovery(debug=debug)
  File "/omd/sites/mysite/lib/python3/cmk/gui/watolib/check_mk_automations.py", line 239, in autodiscovery
    _automation_serialized(
    ~~~~~~~~~~~~~~~~~~~~~~^
        "autodiscovery",
        ^^^^^^^^^^^^^^^^
        automation_config=LocalAutomationConfig(),
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        debug=debug,
        ^^^^^^^^^^^^
    ),
    ^
  File "/omd/sites/mysite/lib/python3/cmk/gui/watolib/check_mk_automations.py", line 60, in _automation_serialized
    cmdline, serialized_result = check_mk_local_automation_serialized(
                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        command=command,
        ^^^^^^^^^^^^^^^^
    ...<6 lines>...
        collect_all_hosts=collect_all_hosts,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/omd/sites/mysite/lib/python3/cmk/gui/watolib/automations.py", line 203, in check_mk_local_automation_serialized
    raise MKAutomationException(msg)
cmk.gui.watolib.automations.MKAutomationException: Error running automation call <tt>autodiscovery</tt> (exit code 2), error: <pre>An error occurred: Error creating configuration: Traceback (most recent call last):
  File "/omd/sites/mysite/lib/python3/cmk/base/nonfree/cmc/helper_config.py", line 1485, in _hosts_worker
    results = _serialize_worker_hosts(hosts_data, worker_id)
  File "/omd/sites/mysite/lib/python3/cmk/base/nonfree/cmc/helper_config.py", line 1350, in _serialize_worker_hosts
    _HostsData.fill_host(h, host.serialized_host, sp, worker_id)
    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/omd/sites/mysite/lib/python3/cmk/base/nonfree/cmc/helper_config.py", line 1802, in fill_host
    host.group_refs.append(sp.intern(group))
                           ~~~~~~~~~^^^^^^^
  File "/omd/sites/mysite/lib/python3/cmk/base/nonfree/cmc/_string_pool.py", line 18, in intern
    if (str_index := self._map.get(s)) is None:
                     ~~~~~~~~~~~~~^^^
TypeError: unhashable type: 'dict'

</pre>

I wish I could increase the case’s priority.

This should be fixed in the latest version of the MKP for 2.5

Hi,
I’ve already got some test data from @andreas-doehler and reproduced the error earlier today.
The error is caused by some active check MKP packages which (re)load the configuration while the configuration for the core is created.

You will get the error from at least three different MKPs

check_snmp_metric/server_side_calls/check_snmp_metric.py
59:        loading_result = config.load(
60-            discovery_rulesets=(), get_builtin_host_labels=lambda x: {}

check_snmp/server_side_calls/check_snmp.py
75:        loading_result = config.load(
76-            discovery_rulesets=(), get_builtin_host_labels=lambda x: {}

check_snmp_temperature_single/server_side_calls/check_snmp_temperature_single.py
55:        loading_result = config.load(
56-            discovery_rulesets=(), get_builtin_host_labels=lambda x: {}

This seems to break the existing configuration. But not only in a way that some hosts get invalid rules assigned.
Entire blocks of data get corrupted and contain value from different rules. This randomly breaks other mechanisms during the config generation.

For example, here I’ve printed the hostgroups for each host. Should be a list of strings.

config cache hostgroups {'router628': ['check_mk'], 'router703': ['check_mk'], 'router502': ['check_mk'], 'router248': ['check_mk'], 'router369': ['check_mk'], 'router750': ['check_mk'], 'router654': ['check_mk'], 'router459': ['check_mk'], 'router627': ['check_mk'], 'router770': ['check_mk'], 'router408': ['check_mk'], 'router483': ['check_mk'], 'router526': ['check_mk'], 'router003': ['check_mk'], 'router696': ['check_mk'], 'router421': ['check_mk'], 'router536': ['check_mk'], 'router315': ['check_mk'], 'router172': ['check_mk'], 'router800': ['check_mk'], 'router200': ['check_mk'], 'router500': ['check_mk'], 'router683': ['check_mk'], 'router431': ['check_mk'], 'router178': ['check_mk'], 'router741': ['check_mk'], 'router757': ['check_mk'], 'router436': ['check_mk'], 'router570': ['check_mk'], 'router579': ['check_mk'], 'router005': ['check_mk'], 'router378': ['check_mk'], 'router476': ['check_mk'], 'router180': ['check_mk'], 'router080': [{'description': 'PING'}]}

The last entry got a dictionary → Config generation crashes.

Right now I am investigating the reason how this can happen. Most likely because we refer the rulesets by their id(the_ruleset)- which is just a memory address. If something gets re-initialized it is possible that a different ruleset uses the same memory address. Under investiigation…

Until then I would strongly advise against using check_snmp_metric/check_snmp/check_snmp_temperature_single
UNLESS you can make sure that it does not reach this code block. Looks like that the args can specified in multiple ways.

def check_snmp_metric_arguments(params, host_config: HostConfig) -> Iterator[ActiveCheckCommand]:
    if 'creds' in params:
        args = _creds_to_args(params['creds'])
    else:
        ##### BAD THINGS WILL HAPPEN FROM HERE ON
        loading_result = config.load(
            discovery_rulesets=(), get_builtin_host_labels=lambda x: {}
        )
        config_cache = loading_result.config_cache
        ip_lookup_config = config_cache.ip_lookup_config()
        host_name = HostName(host_config.name)
        ip_family = ip_lookup_config.default_address_family(host_name)
        ip_address = HostAddress(host_config.primary_ip_config.address)
        snmp_config = config_cache.make_snmp_config(host_name, ip_family, ip_address, SourceType.HOST, backend_override=None)
        args = _creds_to_args(snmp_config.credentials)


I’ve let claude do all the work. That’s pretty much what I had in mind at the start, so no new surprises. Actually one. I didn’t know that we had this method config.access_globally_cached_config_cache()
This can be used to fix the current problem. Keep in mind that this is still not part of the public API.

My Prompt

This file seems to break the rulesets in the config generation @~local/lib/python3/cmk_addons/plugins/check_snmp_metric/server_side_calls/check_snmp_metric.py. I’ve got an error where the hostgroups the ConfigCache provided corrupted data. Normally you should get a list of strings. In this scenario here there was dictionary as list entry for router080. I assume that it might have something to do with the way we cache the rule matches. The check_snmp_metric.py does a config.load a probably breaks something.

CLAUDE RESPONSE

check_snmp_metric plugin corrupts ConfigCache during config generation

Affected plugin

check_snmp_metric
File: local/lib/python3/cmk_addons/plugins/check_snmp_metric/server_side_calls/check_snmp_metric.py

Symptom

After activating changes, hostgroup assignments contain corrupted data — dictionaries appearing in lists that should only contain strings. In our case, router080 had a dict as a hostgroup entry instead of a plain group name. Other rulesets (contactgroups, service
parameters, etc.) may also be affected. The corruption is non-deterministic and depends on host count, rule count, and Python’s memory allocator behavior.

Root cause

When the active check rule has no explicit SNMP credentials configured, the plugin calls config.load() at line 59 to obtain them from the host’s SNMP configuration. This happens during config generation — i.e., while Checkmk is already in the middle of generating
configs for all hosts.

config.load() completely reinitializes the global configuration state: it replaces all module-level ruleset variables (host_groups,
snmp_communities, host_contactgroups, etc.) with new Python objects and creates a new ConfigCache with a new RulesetMatcher.

This causes corruption through two vectors:

  1. Late-bound module globals: Methods like ConfigCache.hostgroups() resolve ruleset variables from the module namespace at call time, not at construction time. After config.load() replaces the variable, the original ConfigCache (still in use by the ongoing generation) suddenly reads the replacement list on any subsequent uncached lookup.

  2. id()-based cache collision: The RulesetOptimizer caches rule match results keyed by id(ruleset_list) — the Python memory address. When config.load() deallocates the old lists, Python’s allocator can reuse those addresses for newly created lists. A new ruleset allocated at the same address as a different old ruleset produces a cache hit on completely unrelated data — e.g., contactgroup values returned when hostgroup data is queried.

Fix

Replace the config.load() call with config.access_globally_cached_config_cache(), which returns the already-loaded ConfigCache
without reinitializing any module state:

# BEFORE (broken):
loading_result = config.load(
    discovery_rulesets=(), get_builtin_host_labels=lambda x: {}
)
config_cache = loading_result.config_cache

# AFTER (fixed):
config_cache = config.access_globally_cached_config_cache()

The rest of the SNMP credential lookup (ip_lookup_config, make_snmp_config, etc.) remains unchanged — it just operates on the existing
ConfigCache instead of a destructively rebuilt one.

General advice

Never call config.load() from within a server-side calls plugin. The server-side calls API (cmk.server_side_calls.v1) is intentionally sandboxed and does not expose config internals. If you need host configuration data that isn’t available through HostConfig, use config.access_globally_cached_config_cache() to read from the already-loaded state, or better yet, pass the required data as rule parameters.

So how do I get the SNMP configuration of the current host to configure the active check?

Safe but unofficial:
config.access_globally_cached_config_cache()

Official API:
Good question. I doubt there is any. I will try to find someone from this code component, who can provide a better answer.

There’s no plug-in API to get this part of the configuration, currently.
If you go the access_globally_cached_config_cache route, be aware that it is already gone in the master branch. This whole area is under significant churn, so I can’t really tell you what an acceptable workaround for 3.0 could look like.

As a quick follow up that may be moot given the recent comments. Since modifying the existing rules to include snmp credentials, I have not experienced any further issues. For now this is ‘good enough’ for the few snmp checks that I have added as one off/work around(s).