Checkmk version: 2.3.0p36.cee
I am trying to use the “form_spec MonitoredHost” in a rule set. The goal is to create a list of hosts and avoid empty entries in the list. This should be achieved with the following code (I think):
'HOST_LIST': DictElement(
parameter_form=List(
title=Title('Host List'),
element_template=MonitoredHost(
custom_validate=(LengthInRange(
min_value=1,
error_msg=Message('Field can not be empty')),
),
),
))
Unfortunately, nothing happens. When I try this with my own custom validation on the MonitoredHost, nothing happens either (even if the validation is configured to always throw an exception).
class ValidateMonitoredHost:
def __init__(self, error_msg: Message | None = None) -> None:
self.error_msg: Final = error_msg or (Message("Host can not be empty."))
def __call__(self, value: str) -> None:
raise ValidationError(self.error_msg)
'HOST_LIST': DictElement(
parameter_form=List(
title=Title('Host List'),
element_template=MonitoredHost(
custom_validate=(ValidateMonitoredHost(),),
),
)),
It works at the List level. But then I encounter a new problem: The triggered exception clears (empties) ALL MonitoredHost fields, even in completely unrelated parts of the rule set ![]()
class ValidateMonitoredHostList:
def __init__(self, error_msg: Message | None = None) -> None:
self.error_msg: Final = error_msg or (Message("Host list can not contain empty fields."))
def __call__(self, value: Sequence[str]) -> None:
if any(len(entry) == 0 for entry in value):
raise ValidationError(self.error_msg)
'HOST_LIST': DictElement(
parameter_form=List(
title=Title('Host List'),
custom_validate=(ValidateMonitoredHostList(),),
element_template=MonitoredHost(),
))
So how can I create a list of monitored host in WATO without empty entrys?
Cheers
Thomas
PS: This also happens with MontoredServices.