Foobar example plugin not working

I am trying to learn to write plugins for Check_mk and start with the foobar example from the documentation on plugin development. I am running Check_mk locally on a windows computer in docker, and am having trouble getting the example to produce the expected output.

Inside docker container, in location: /usr/lib/check_mk_agent/plugins/foobar

#!/bin/sh
echo "<<<foobar>>>"
echo "West 100 100"
echo "East 197 200"
echo "North 0 50"

When I run check_mk_agent I see the expected output from the foobar agent.

Then I run the command su cmk to login to the instance (I did not create any so I guess this is the default/standard?).
Location: local/lib/check_mk/base/plugins/agent_based/foobar.py

from .agent_based_api.v1 import *
import pprint


def discover_foobar(section):
    for sector, used, slots in section:
        yield Service(item=sector)


def check_foobar(item, section):
    for sector, used, slots in section:
        if sector == item:
            used = int(used)
            slots = int(slots)
            if used == slots:
                s = State.CRIT
            elif slots - used <= 10:
                s = State.WARN
            else:
                s = State.OK
            yield Result(
                state = s,
                summary = f"Used {used} out of {slots} slots")
            return


register.check_plugin(
    name = "foobar",
    service_name = "Foobar Sector %s",
    discovery_function = discover_foobar,
    check_function = check_foobar,
)

Now when I will try out the discovery by running the command cmk --detect-plugins=foobar -vI Home. Home is here the site that I see when I execute cmk -l and that I have added to Check_mk in the UI. The results are however not at all what is expected:

Discovering services and host labels on: Home
Home:
+ FETCHING DATA
[TCPFetcher] Execute data source
No piggyback files for 'Home'. Skip processing.
No piggyback files for '192.168.0.94'. Skip processing.
[PiggybackFetcher] Execute data source
+ PARSE FETCHER RESULTS
Received no piggyback data
+ EXECUTING HOST LABEL DISCOVERY
+ PERFORM HOST LABEL DISCOVERY
+ EXECUTING DISCOVERY PLUGINS (0)
SUCCESS - Found no new services, no new host labels

I was thinking if there is an issue with permissions on the file.
The file /usr/lib/check_mk_agent/plugins/foobar is owned by root:root with permissions -rwxr-xr-x and the file
local/lib/check_mk/base/plugins/agent_based/foobar.py is owned by cmk:cmk with permissions -rwxrwx---.

Are there any obvious mistakes that anyone can find?

In an other thread there was a comment about the --detect-plugins parameter not working correctly. You may need to try it without this parameter.

Thank you @Jiuka for mentioning this thread. I tried it and are getting the same results with the final line being SUCCESS - Found no new services, no new host labels.

Hi @Elaak

The things you pasted seems OK for me. However python and cmk possibly are mot picky then I am. If a plugin which I expect to show up just does not I usually resort to the following command.

cmk -vv --debug -II HOST

The two v makes the output more verbous, the --debug ensures exceptions are not hidden away and the two I forces a rediscovery of all not just the new services. If this runs without any problems but still misses your check check the lines below + EXECUTING DISCOVERY PLUGINS if you plugin is listed as one tested.

Regards Marius

1 Like

Hi @Jiuka,

thanks for the detailed explaination on the command. I do not see the plugin in the list. I also do not see any errors in the debugging results. Here is the list of plugins it returns

+ EXECUTING DISCOVERY PLUGINS (21)
  Trying discovery with: services_summary, fileinfo_groups, dotnet_clrmemory, mem_linux, wmi_cpuload, systemtime, fileinfo, check_mk_agent_update, services, winperf_if, domino_tasks, esx_vsphere_hostsystem_cpu_usage, winperf_phydisk, check_mk_only_from, uptime, df, docker_container_status_uptime, winperf_processor_util, mem_win, mem_vmalloc, ps

Hi @Elaak

I think the problem is that you added the “client side” agent plugin to the docker container, but are testing the windows agent. The /usr/lib/check_mk_agent/plugins/foobar is expected to be run on the agent you test. Sorry did not catch this at first from your description.

If you want to add this to your windows agent ass the following to C:\ProgramData\checkmk\agent\plugins\foobar.ps1 should to the trick.

Write-Host "<<<foobar>>>"
Write-Host "West 100 100"
Write-Host "East 197 200"
Write-Host "North 0 50"

Or add localhost as a host and run the commands against localhost.

Regards Marius

Hi @Jiuka,

Sorry maybe I did not make my situation clear. I do not have Check_mk installed on my windows computer. All files and commands are running inside a docker container. So the files for foobar is located inside the docker Linux instance. My configured host however is my windows instance, I have added the IP of my computer as the host in Check_mk and it is correctly accessing information such as harddrive space of C:\ etc.

I tried changing the file extension and the command itself, but for all possibilities I try, I still see the same plugins in the list.

Hi @Elaak

It’s the Agent on you Windows which needs to return the <<<foobar>>> section to checkmk. With the command cmk --dump-agent Home you should get the output of the agent of your Windows instance. Inthere there need to be the <<<foobar>>> and the following lines.

So you need to create this file on your Windows instance, not within the docker container. If you create a new file C:\ProgramData\checkmk\agent\plugins\foobar.ps1 on your Windows instance and put the following lines into it this should be the correct equivalent for Winows

Write-Host "<<<foobar>>>"
Write-Host "West 100 100"
Write-Host "East 197 200"
Write-Host "North 0 50"

Then cmk --dump-agent Home should return the <<<foobar>>> line.

Regards Marius