How to create a rule to set data for a special agent, such as a username, password, and port?

I am developing a special agent that will perform data collection through an API, and I would like to create a rule to configure it via WATO.

While reading the article on how to develop plugins for Checkmk, I understood how to develop them and even how to create a rule for metrics, but I couldn’t find anything related to creating rules for special agents.

During my research, I came across a tip to check how the Fritzbox agent works. I took a look, but I still have some questions:

How is this “link” established between the agent and the rule? Does the agent have a naming convention?

How do I capture the rule parameters in my agent?

Hi Francisco,

I think a detailed written part about special agents in the docs would be nice. Maybe @mschlenker already has it on his Todo list.

in the meantime, I think if you got the special agent working, you know enough to deduct the necessary parts from existing special agents.
The necessary files aren’t easy to find in integrated check_mk special agents, but when you take a look at the ones on exchange.checkmk.com that usually works well.

A pretty minimal special agent config is in Checkmk Exchange (not however, there is a minor bug - the file in checks/ needs to be named agent_<name_of_your_special_agent> for it to work in CRE, I fixed that in
m365_service_health-1.1.0.mkp (5.4 KB)

But other special agents can also be used as reference i.e. the nutanix Checkmk Exchange or redfish special agents.

Basically you need two additional files:

local/share/check_mk/web/plugins/wato/<your_special_agent.py> -> the GUI definition file, helping users define a rule in the rules.mk file
local/share/check_mk/checks/agent_<your_special_agent> to take the parameters from the rules.mk and built a matching CLI call for your special agent.

Hope that helps :slight_smile:
Gerd

3 Likes

Now I understand! The special agent needs a wrapper in the directory ~/local/share/check_mk/checks.

from cmk.base.check_api import passwordstore_get_cmdline


def agent_m365_service_health_arguments(params, _no_hostname, _no_ipaddress):
    secrets = {
        'secret': params['secret'],
    }
    args = []
    
    keys = ("subscription", "tenant", "client", "issue_days")

    for key in (k for k in keys if k in params):
        option = "--%s" % key
        value = params[key]
        if isinstance(value, bool):
            if value:
                args.append(option)
        else:
            args += [option, value]

    args += [passwordstore_get_cmdline("--secret=%s", params["secret"])]

    return args

special_agent_info['m365_service_health'] = agent_m365_service_health_arguments

I hope that in the near future, we can have documentation for special agents. :pray:
Thank you, @gstolz! :handshake:

1 Like

Team KNW has it on it’s TODO list.

1 Like