How to write agent rules?

Hello everybody,

I’ve just successfully written my first CheckMk 2.0 plugin that checks Windows ODBC Dsns.
The plugin is very simple: it consists of two files: an agent plugin and the actual check plugin.

But now I’m missing the feature to bake an agent that contains the new agent plugin.
It seems I need to define an “agent rule” for this (i.e. th kind of rule that contains the option “deploy xxx plugin”).
Unfortunatly I cannot find documentation how to do this.
I even do not manage to find the definitions of existing agent rules in the CheckMk source code !?

Does anybody know how to write these rules?

Thanks and Regards,
Carsten

Hi @carsten

I have done this in some of my plugins, for example GitHub - jiuka/checkmk_winnfs: Checkmk extension for Windows NFS Server

It needs the wato rule to configure it in a file in local/share/check_mk/web/plugins/wato and the
and the bakery plugin in local/share/check_mk/agents/bakery/

The following are these files.

Regards Marius

1 Like

Thank you, Jiuka. That works :smile:

Hi @Jiuka,
I would like to extend my question: now I’m writing an extension that needs to deploy a special binary that gets called by the actual agent plugin. I’ve copied the binary to local/share/check_mk/agents/bin as this sounds reasonable to me. Now I suppose I have to mention it in my bakery plugin. How would I do this?
Carsten

Note: actually I have another topic for this question: Plugin development: were to put additional binaries
But it contains much less context and reflects an older knowlege level of myself.

Hi @carsten,

I am not sure, as I never had to do this. However alike the Plugin the seems to be a SystemBinary class. Which probably is what you need. So probably after the yield Plugin() a yield SystemBinary() to add this to the package.

Regards Marius

Hi @carsten,

I tried it now on a test environment.

def get_foobar(conf: Any) -> FileGenerator:
    yield Plugin(base_os=OS.LINUX, source=Path('foobar'))
    yield SystemBinary(base_os=OS.LINUX, source=Path('foo'))

Expects the files local/share/check_mk/agents/plugins/foobar and local/share/check_mk/agentsfoo. This will lead to a usr/bin/foo in the agent. If it should reside somewhere else you may be able to get it there with the target parameter.

def get_foobar(conf: Any) -> FileGenerator:
    yield Plugin(base_os=OS.LINUX, source=Path('foobar'))
    yield SystemBinary(base_os=OS.LINUX, source=Path('foo'), target=Path('../local/bin/foo'))

Regards Marius

Thanks again for your Support, Jiuka :slight_smile:
I also found the solution after I’ve discovered some documentation on the bakery api in this file:
/opt/omd/versions/default/lib/python3/cmk/base/cee/plugins/bakery/bakery_api/__init__.py