Important news regarding Development APIs

While you can now find quite a lot of migrated things already in checkmk/cmk/plugins at master · Checkmk/checkmk · GitHub - you can not find there anything regarding agent bakery stuff as this is part of our Checkmk Enterprise code base.

For agent plugin configs, please find thus here an example:

.../rulesets/_agent_plugin_config.py

# Copyright (C) 2019 Checkmk GmbH - License: Checkmk Enterprise License
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.


from collections.abc import Mapping

from cmk.rulesets.v1 import Help, Title
from cmk.rulesets.v1.form_specs import (
    CascadingSingleChoice,
    CascadingSingleChoiceElement,
    DefaultValue,
    DictElement,
    Dictionary,
    FixedValue,
    Password,
    String,
    TimeMagnitude,
    TimeSpan,
    validators,
)
from cmk.rulesets.v1.rule_specs import AgentConfig, Topic


def _migrate(value: object) -> Mapping[str, object]:
    if isinstance(value, dict) and "user" in value:
        iv = value.get("interval")
        return {
            "deployment": ("cached", None) if not iv else ("sync", float(iv - iv % 60.0)),
            "auth": {
                "user": value["user"],
                "password": ("cmk_postprocesed", "explicit_password", value["password"]),
            },
        }

    match value:
        case None:
            return {"deployment": ("do_not_deploy", 0.0)}
        case dict():
            return value
    raise ValueError(value)


def _agent_config_mk_tsm() -> Dictionary:
    return Dictionary(
        help_text=Help(
            "This will deploy the agent plug-in <tt>mk_tsm</tt>. "
            "It will provide several checks concerning TSM."
        ),
        elements={
            "deployment": DictElement(
                parameter_form=CascadingSingleChoice(
                    title=Title("Deployment type"),
                    elements=(
                        CascadingSingleChoiceElement(
                            name="sync",
                            title=Title("Deploy the TSM plug-in and run it synchronously"),
                            parameter_form=FixedValue(value=None),
                        ),
                        CascadingSingleChoiceElement(
                            name="cached",
                            title=Title("Deploy the TSM plug-in and run it asynchronously"),
                            parameter_form=TimeSpan(
                                displayed_magnitudes=(
                                    TimeMagnitude.HOUR,
                                    TimeMagnitude.MINUTE,
                                )
                            ),
                        ),
                        CascadingSingleChoiceElement(
                            name="do_not_deploy",
                            title=Title("Do not deploy the TSM plug-in"),
                            parameter_form=FixedValue(value=None),
                        ),
                    ),
                    prefill=DefaultValue("sync"),
                ),
            ),
            "auth": DictElement(
                parameter_form=Dictionary(
                    title=Title("Authentication"),
                    elements={
                        "user": DictElement(
                            parameter_form=String(
                                title=Title("Username for login"),
                                custom_validate=(validators.LengthInRange(min_value=1),),
                            ),
                            required=True,
                        ),
                        "password": DictElement(
                            parameter_form=Password(title=Title("Password for login")),
                            required=True,
                        ),
                    },
                ),
            ),
        },
        migrate=_migrate,
    )


rule_spec_tsm_bakelet = AgentConfig(
    name="mk_tsm",
    title=Title("TSM - IBM Tivoli Storage Manager (Linux, Unix)"),
    topic=Topic.STORAGE,
    parameter_form=_agent_config_mk_tsm,
)

1 Like