[BUG] or another strange behavior of input validation in rule sets

@Rebekka, i run into another issue with the input validation :frowning:

CMK version: 2.4.0p17.cee
OS version: 2.4.0p17.cee

If you have a rule set with a list of string and a input validation
for the strings in the list, the input validation marks correct
entries as invalid and removes correct entries from the list.

Here the issue in action

Start with a list of four entries, two valid, thow invalid

Try to save the rule, the first invalid entry gets marked as invalied → correct behavior

Remove the marked entry

Try to save again

The input validation finds the the second invalid entry, but marks a valid entry as invalid, adds an empty field at the beginning of the list, and removs the last entry from the list (which was a valid entry).

Here a very basic script to reproduce the issue.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from cmk.rulesets.v1 import Title
from cmk.rulesets.v1.form_specs import (
    DictElement,
    Dictionary,
    List,
    String,
)
from cmk.rulesets.v1.form_specs.validators import (
    Message,
    ValidationError,
)
from cmk.rulesets.v1.rule_specs import ActiveCheck, Topic

allowed_hosts = [
    'C9540-7-1',
    'C9348-7-1',
    'C9348-5-2',
]


class ValidateMonitoredHost:
    def __call__(self, value: str) -> None:
        if value not in allowed_hosts:
            raise ValidationError(
                Message(f'{value} not allowed. {",".join(allowed_hosts)} are allowed only')
            )


def parameter_form_nvdct_test() -> Dictionary:
    return Dictionary(
        elements={
            'seed_devices': DictElement(
                parameter_form=List(
                    title=Title('Seed Devices'),
                    element_template=String(  # should be MonitoredHost
                        custom_validate=[ValidateMonitoredHost()],
                    ),
                )),
        })


rule_spec_nvdct_test = ActiveCheck(
    topic=Topic.NETWORKING,
    title=Title('NVDCT Test'),
    name='nvdct_test',
    parameter_form=parameter_form_nvdct_test,
)

Cheers
Thomas

2 Likes

Hi, sorry for the long wait.

Unfortunately, the problem is in the current frontend part of the code.
Meaning that also the old Valuespecs have this issue and this is not ruleset API specific.

Since we are working on a new frontend for the upcoming 2.5 release this is not something we plan to fix in the old frontend anymore.

Cheers,
Rebekka

Hi @Rebekka,

thanks for the update.

No worries, I’m used to it :wink:

Does that mean I can’t use input validation in a “list” at all, or is there a workaround?

I understand your point, unfortunately this means that at least two problems in input validation are not fixed in the current version of Checkmk and we have to wait for Checkmk 2.5. and hope that things will be better :frowning:

Cheers
Thomas

Hi Thomas,

I’m not sure if I already mentioned this in a different topic, or missed to press the “Reply” button.

These bugs in the valuespec validation probably exists for at least 5 years or maybe since the introduction of the valuespec. We are not planning to fix&backport the legacy valuespec code, unless some basic feature gets completely broken somehow. Actually, it is not about the effort to fix this, more about the “what might break because of this change”.

The valuespecs are a combination of backend rendered html and some javascript code crudely modifiying the current DOM. It’s quite easy to overlook something here, breaking an entire release… So the risk is simply too high.

Regards
Andreas