Unable to edit rules when explicit hostname contains hyphens

CMK version: 2.5.0p8 Pro
OS version: Debian 13

Error message:

Hi,

after upgrading from Checkmk 2.4 to Checkmk 2.5, we can no longer open or edit rules.

The server running checkmk contains a hyphen:

monitoring-01

Opening the rule results in the following exception:

ValueError: 'cond_host_monitoring-01' is not a valid, non-reserved Python identifier

Relevant part of the traceback:

  File "/omd/sites/prodnp/lib/python3/cmk/gui/wsgi/applications/checkmk.py", line 247, in _process_request
    resp = page_handler(ctx)
  File "/omd/sites/prodnp/lib/python3/cmk/gui/wsgi/applications/utils.py", line 140, in _call_auth
    handler(ctx)
  File "/omd/sites/prodnp/lib/python3/cmk/gui/wato/page_handler.py", line 81, in page_handler
    mode_instance = mode_registry.get(current_mode, ModeNotImplemented)()
  File "/omd/sites/prodnp/lib/python3/cmk/gui/wato/pages/rulesets.py", line 2085, in __init__
    self._form_type = self._init_form_type()
  File "/omd/sites/prodnp/lib/python3/cmk/gui/wato/pages/rulesets.py", line 2131, in _init_form_type
    create_rule_catalog(
  File "/omd/sites/prodnp/lib/python3/cmk/gui/watolib/rulesets.py", line 2467, in create_rule_catalog
    **_create_rule_conditions_catalog_topic(
  File "/omd/sites/prodnp/lib/python3/cmk/gui/watolib/rulesets.py", line 2405, in _create_rule_conditions_catalog_topic
    SingleChoiceElementAPI(name=n, title=Title("%s") % t)
  File "<string>", line 5, in __init__
  File "/omd/sites/prodnp/lib/python3.13/site-packages/cmk/rulesets/v1/form_specs/_basic.py", line 458, in __post_init__
    raise ValueError(f"'{self.name}' is not a valid, non-reserved Python identifier")
'cond_host_monitoring-01' is not a valid, non-reserved Python identifier

It appears that the hostname is used directly to generate the form element name:

cond_host_<hostname>

Since the resulting value contains hyphens, it is not a valid Python identifier.

The hostnames themselves were already present and worked without problems in Checkmk 2.4. Renaming the hosts is not a practical workaround for us.

Has anyone encountered this after upgrading to Checkmk 2.5? Is this already known or fixed in a newer patch release?

Oh dear. @martin.hirschvogel

There has been similar issues and Copilot proposed this fix based on the fixes for similar issues: Fix crash when editing rules with hyphenated predefined condition IDs by mueller-ma · Pull Request #932 · Checkmk/checkmk · GitHub

How exactly you can get to this error? If i create a rule with hosts that have a hyphen inside the name i get no error message. Also if i create a predefined condition with such a host no error happens.
All tested in 2.5.0p8

The server running checkmk server contains a hyphen in its name.

Looking deeper at it the issue is caused by predefined conditions that contain the hostnames of the monitoring servers in the title:

$ grep "cond_host_moni-" -R /omd/sites/mysite/etc/
/omd/sites/mysite/etc/check_mk/conf.d/wato/rules.mk:{'id': 'some id', 'value': {...}, 'condition': {'host_name': ['MONITORING-01']}, 'options': {'description': 'SMTP Check', 'predefined_condition_id': 'cond_host_monitoring-01'}},
/omd/sites/mysite/etc/check_mk/conf.d/wato/predefined_conditions.mk:predefined_conditions.update({'cond_host_monitoring-01': {'title': 'Hostname MONITORING-01', 'comment': '', 'docu_url': '', 'conditions': {'host_name': ['MONITORING-01'], 'host_folder': ''}, 'owned_by': None, 'shared_with': []}, 'cond_host_monitoring-02': {'title':
'Hostname MONITORING-02', 'comment': '', 'docu_url': '', 'conditions': {'host_name': ['MONITORING-02'], 'host_folder': ''}, 'owned_by': None, 'shared_with': []}, 'cond_service_hidden': {'title': 'Service Hidden', 'comment': '', 'docu_url': '', 'conditions': {'service_labels': {'service': 'hidden'}, 'host_folder': ''}, 'owned_by': None, 'shared_with': []}})

As these conditions are used by only one check, I might remove the predefined conditions and add them back as explicit condition for this one check.

1 Like

I can reproduce the issue and will open an internal ticket to fix this for good.

Thanks for bringing it to our attention @dahag-mm!

Internal reference: CMK-36792

2 Likes