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?