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

Hi,

I’m seeing the same issue. The result shown in this ticket is not helpful for me.

I’m testing the “foobar” example from the documentation:

  • Eigene Check-Plugins schreiben
  • On Rocky Linux release 8.5 (Green Obsidian)
  • With check-mk-free-2.0.0p23-el8-38.x86_64.rpm and check-mk-raw-2.0.0p23-el8-38.x86_64.rpm

Agent is installed:

OMD[mon]:~$ cmk -L | grep foobar
foobar                                      agent      (no man page present)
OMD[mon]:~$ cat 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)    # convert string to int
            slots = int(slots)  # convert string to int
            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,
)

Target host “zielhost” returns the foobar section:

OMD[mon]:~$ cmk -d zielhost | tail -n 10
Skew            : 0.694 ppm
Root delay      : 0.026444320 seconds
Root dispersion : 0.001693105 seconds
Update interval : 517.1 seconds
Leap status     : Normal
<<<local:sep(0)>>>
<<<foobar>>>
West 100 100
East 197 200
North 0 50
OMD[mon]:~$

Calling the command from the documentation shows “Found no new services”. Expected result was: " SUCCESS - Found 3 services, 1 host labels"

OMD[mon]:~$ cmk --detect-plugins=foobar -vI zielhost
Discovering services and host labels on: zielhost
zielhost:
+ FETCHING DATA
[TCPFetcher] Execute data source
[PiggybackFetcher] Execute data source
No piggyback files for 'zielhost'. Skip processing.
No piggyback files for 'zielhost'. Skip processing.
+ 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
OMD[mon]:~$

A full service scan on the webinterface shows the 3 new services, so the plugin is actually working. But I would find it very useful to be able to test in on commandline like shows in the documentation.

I tested this with CRE/CFE, same result.

I’d be thankful if someone could give me a hint what I’m doing wrong here.

Thanks,
Sven

Hello,

still with the most recent version of CRE 2.1 this not working.

cmk --detect-plugins=foobar -vI zielhost

Shows:

Discovering services and host labels on: zielhost
zielhost:
+ FETCHING DATA
[ProgramFetcher] Execute data source
[PiggybackFetcher] Execute data source
No piggyback files for 'zielhost'. Skip processing.
No piggyback files for '1.2.3.4'. Skip processing.
+ ANALYSE DISCOVERED HOST LABELS
SUCCESS - Found no new host labels
+ ANALYSE DISCOVERED SERVICES
+ EXECUTING DISCOVERY PLUGINS (0)
SUCCESS - Found no new services

In the service discovery in the web ui the “Foobar” services show up.

So the example from the documentation does not work if replicated 1:1 and I think this is a bug. If this is not supposed to work it should be removed from the documentation.

Regards,
Sven