Custom notification plugin – parameters not showing (Checkmk 2.4.0p13)

Hi everyone,

I’m new to Checkmk and I’m trying to create a custom notification plugin that will later connect to our ticket system.
Right now I just want to get the parameter form working in the GUI.

No matter what I do, I only see this generic text:


So my parameters are not detected

Im currently using 2.4.0p13 (CRE)

My current filestructure:

Notification plugin

/omd/sites/monitoring/local/lib/python3/cmk/notification_plugins/tbs_ticket.py

#!/usr/bin/env python3
from __future__ import annotations
import json, urllib.request
from cmk.utils.notify_types import PluginNotificationContext
from cmk.notification_plugins.utils import process_by_status_code

def _build_payload(ctx: PluginNotificationContext) -> dict:
    return {
        "type": ctx.get("PARAMETER_ticket_art"),
        "host": ctx.get("HOSTNAME"),
        "state": ctx.get("HOSTSTATE"),
    }

def main() -> int:
    def _send(ctx: PluginNotificationContext) -> int:
        api_url = ctx.get("PARAMETER_api_url")
        token = ctx.get("PARAMETER_api_token")
        req = urllib.request.Request(
            url=f"{api_url.rstrip('/')}/tickets",
            method="POST",
            data=json.dumps(_build_payload(ctx)).encode("utf-8"),
            headers={"Content-Type": "application/json", "Authorization": f"Bearer {token}"},
        )
        with urllib.request.urlopen(req, timeout=10) as r:
            return r.getcode()
    return process_by_status_code(lambda *_: _send, (200, 201, 202))

Wrapper (is executable)

/omd/sites/monitoring/local/share/check_mk/notifications/tbs_ticket

#!/usr/bin/env python3
import sys
from cmk.notification_plugins.tbs_ticket import main
if __name__ == "__main__":
    sys.exit(main())

Ruleset

/omd/sites/monitoring/local/lib/python3/cmk_addons/plugins/tbs_ticket/rulesets/notifications_tbs_ticket.py

# -*- coding: utf-8 -*-
from cmk.rulesets.v1 import Title
from cmk.rulesets.v1.form_specs import Dictionary, String, Boolean, DropdownChoice, DefaultValue
from cmk.rulesets.v1.rule_specs import NotificationParameters
from cmk.rulesets.v1.form_specs import validators

def _params_form():
    return Dictionary(elements=[
        ("ticket_art", DropdownChoice(
            title=Title("Ticket Type"),
            elements=[("incident", Title("Incident")),
                      ("service_request", Title("Service Request"))],
            prefill=DefaultValue("incident"),
        )),
        ("api_url", String(title=Title("API URL"), validators=[validators.Url()])),
        ("api_token", String(title=Title("API Token"), allow_empty=False)),
        ("send_links", Boolean(title=Title("Send Links"), prefill=DefaultValue(True))),
    ])

rule_spec_tbs_ticket = NotificationParameters(
    name="tbs_ticket",
    title=Title("TBS Ticket – Parameters"),
    parameter_form=_params_form,
)


I restarted the site using omd restartand activated the changes (but as i remeber there were none). The plugin appears correctly as a method under Setup → Events → Notifications, but I still don’t see any custom parameter fields, only the generic section that says “Parameters… Call with the following parameters”.

What am I missing? Are my paths or filenames wrong, or did something change in version 2.4? Is there maybe a simple working example of a custom notification plugin with parameters that I can compare mine against?

Thanks in advance and best regards :waving_hand:

Hi.

Did you chec the ~/var/log/web.log for error’s? Loo’s lie that your ruleset code is wrong. From my point of view it should be:

# -*- coding: utf-8 -*-
from cmk.rulesets.v1 import Title
from cmk.rulesets.v1.form_specs import Dictionary, String, Boolean, DropdownChoice, DefaultValue
from cmk.rulesets.v1.rule_specs import NotificationParameters
from cmk.rulesets.v1.form_specs import validators

def _params_form():
    return Dictionary(
        title=Title("Some title"),
        elements={
            "ticket_art", DropdownChoice(
                 title=Title("Ticket Type"),
                 elements=[("incident", Title("Incident")),
                      ("service_request", Title("Service Request"))],
                prefill=DefaultValue("incident"),
        ),
        "api_url", String(title=Title("API URL"), validators=[validators.Url()]),
        "api_token", String(title=Title("API Token"), allow_empty=False),
        "send_links", Boolean(title=Title("Send Links"), prefill=DefaultValue(True)),
    })

rule_spec_tbs_ticket = NotificationParameters(
    name="tbs_ticket",
    title=Title("TBS Ticket – Parameters"),
    parameter_form=_params_form,
)

The Problem is at first dictionary. In the new RuleAPI you need “{}” instead of “”. And the elements are nut in “()”.

RG, Christian