owned this note
owned this note
Published
Linked with GitHub
# Developer Hour: DevAPI Migration Q&A
*Thank you for joining us for this Developer Hour!
Please consider asking your question before the meeting in the following format -- with the question and your name or username:*
---
1. Hi! I'm Dirk from the checkmk forum and I have some questions about the migration of WATO plugins (2.1 style) to rulesets (2.3/2.4 style).
In my old check plugin I only check for a CRIT threshold and I have this default parameter:
```
register.check_plugin(
...
check_default_parameters = {
"level": 100,
},
)
```
The check function simply checks `if value >= params["level"] then CRIT`.
Now I want to move to checkmk 2.3/2.4 and enhance the check and use the `check_levels()` function.
I wrote this new-style ruleset plugin:
```
...
def _parameter_valuespec() -> Dictionary:
return Dictionary(
elements={
"level": DictElement(
parameter_form=SimpleLevels[int](
form_spec_template=Integer(),
level_direction=LevelDirection.UPPER,
prefill_fixed_levels=DefaultValue((80, 100)),
title=Title("…"),
migrate=migrate_function,
),
)
},
)
...
```
The `migrate_function()` just takes the "old" single-valued CRIT threshold and converts it into a tuple with (WARN, CRIT) where WARN is 80 percent of CRIT, so that 100 becomes `('fixed', (80, 100))`:
```
def migrate_function(value: object) -> SimpleLevelsConfigModel[int]:
if isinstance(value, int):
return ('fixed', (int(0.8*value), value)) # convert
else:
return value # already converted
```
So if an old rule already exists with threshold 200 it gets converted to `('fixed', (160,200))`. So far, so good.
My questions are:
* When exactly gets the migration function called? I'd assume only when a rule exists and only when we load the rule in the GUI. Or does it get called every minute when the check is run?
* Is it correct that the migration function is a one-way ticket? I mean, it converts the old value that is defined in some `rules.mk` file into the new format once and when the rule is again saved (and only then) it is written back in the new format.
* What would I put in my check plugin as `check_default_parameters`? Since I want to use the `check_levels()` function, I'd assume the new format `('fixed', (80, 100))`.
* But what if an old rule exists with just the single-valued threshold (100) and nobody has yet read and saved that rule in the GUI. Then the check plugin will receive just the old value as `params["level"]`, right? So I need a migration function in the check plugin as well, right?
Thanks!
---
2. Hi! I'm Thomas from the forum (@thl-cmk), I have (hopfully) a simple question. I need to add a list of Checkmk hosts/services to a ruleset.
What ist the best/easyest way to do that? As far as I have found there are two options
- List of Strings
Here I can add a `custom_validate` function and check for empty fields in the list (or an empty list), but I can not make shure that the entered values are valid hosts/services and more imprtant I can not present the user with a list to chose from.
- List of `MonitoredHost`/`MonitoredService`
Here I can present a list of valid hosts/services where the user can chose from, but I can not add a `custom_validate` function. Or better I can but it just dont work. And the second issue I have here, if I add the `custom_validate` function on the list itself, every time there is an empty filed in the list (or an emty list) _all_ the `MonitoredHost`/`MonitoredService` fields in the ruleset where cleared :-(
So is there a way to have both, the valid list of Host/Services and the option to validate the input?
For reference [[BUG] (or by design?) form_spec MonitoredHost doesn’t work as expected](https://forum.checkmk.com/t/bug-or-by-design-form-spec-monitoredhost-doesnt-work-as-expected/55843)
Thanks
---
Hi,
What is the best way to ship addionatl python packages with a Extensions (normal and bakery agent)?
Thanks Andi
---