Hi, I have written my own special agent which is copied to local/share/check_mk/agents/special/agent_my_rest_api
and then I have a corresponding “argument thingy” for putting together the arguments sent to the special agent, copied to local/share/check_mk/checks/agent_my_rest_api
, as well as a web plugin at local/share/check_mk/web/plugins/wato/
. I can configure a rule for the special agent in the UI, and assign it to a host.
So far so good. I then build a check to handle the special agent output, and I can get it to display ok, warn or critical when looking at the host services. However, I realised that the check is not the same as the docs here: Writing your own check plug-ins - I think I have written an old 1.6 check. So, I followed the docs from that link and I copied my new check into local/lib/check_mk/base/plugins/agent_based/
.
I removed the site, added a new one, copied my files across, but now it seems like the new check doesn’t get called, and there is no service shown for the host.
How can I verify that the check is actually being called?
The special agent returns this:
OMD[mysite]:~$ cmk -d localhost
<<<my_rest_api>>>
filespace.anttest 17248
Here is the check plugin:
from .agent_based_api.v1 import *
def discover_my_rest_api(section):
yield Service()
def check_my_rest_api(section):
print("\r\n\r\nANTHERE:\r\n============================")
print("{}".format(section))
for line in section:
usage = line[1]
msg = "Usage: {}".format(usage)
if int(line[1]) > 10000: # TODO take from params
yield Result(state=State.CRIT, summary=msg)
return
yield Result(state=State.OK, summary=msg)
register.check_plugin(
name="my_rest_api",
service_name="LucidLink CheckPlugin",
discovery_function=discover_my_rest_api,
check_function=check_my_rest_api,
)
I assumed that because the special agent outputs a section called my_rest_api
, that would be used to find the check plugin, based on the name that I pass in the register function.
OMD[mysite]:~$ cmk -L | grep my_rest
my_rest_api agent (no man page present)
OMD[mysite]:~$ cmk --detect-plugins=my_rest_api -vI localhost
Discovering services and host labels on: localhost
localhost:
+ FETCHING DATA
[ProgramFetcher] Execute data source
No piggyback files for 'localhost'. Skip processing.
No piggyback files for '127.0.0.1'. 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
OMD[mysite]:~$ cmk --debug --check -v localhost
Checkmk version 2.0.0p12
+ FETCHING DATA
[ProgramFetcher] Execute data source
No piggyback files for 'localhost'. Skip processing.
No piggyback files for '127.0.0.1'. Skip processing.
[PiggybackFetcher] Execute data source
+ PARSE FETCHER RESULTS
Received no piggyback data
No piggyback files for 'localhost'. Skip processing.
No piggyback files for '127.0.0.1'. Skip processing.
[special_my_rest_api] Version: unknown, OS: unknown, execution time 1.1 sec | execution_time=1.140 user_time=0.010 system_time=0.000 children_user_time=0.160 children_system_time=0.020 cmk_time_ds=0.960 cmk_time_agent=0.000
The output from those last two calls to cmk makes me think that the check isnt being called - because the print statements aren’t being output.
more output follows. strangely i cant see the special agent output, but I can see it being called.
OMD[mysite]:~$ cmk --debug --checks=my_rest_api -vvn localhost
WARNING: '--checks' is deprecated in favour of option 'detect-plugins'
Checkmk version 2.0.0p12
Try license usage history update.
Trying to acquire lock on /omd/sites/mysite/var/check_mk/license_usage/next_run
Got lock on /omd/sites/mysite/var/check_mk/license_usage/next_run
Trying to acquire lock on /omd/sites/mysite/var/check_mk/license_usage/history.json
Got lock on /omd/sites/mysite/var/check_mk/license_usage/history.json
Next run time has not been reached yet. Abort.
Releasing lock on /omd/sites/mysite/var/check_mk/license_usage/history.json
Released lock on /omd/sites/mysite/var/check_mk/license_usage/history.json
Releasing lock on /omd/sites/mysite/var/check_mk/license_usage/next_run
Released lock on /omd/sites/mysite/var/check_mk/license_usage/next_run
Loading autochecks from /omd/sites/mysite/var/check_mk/autochecks/localhost.mk
+ FETCHING DATA
Source: SourceType.HOST/FetcherType.PROGRAM
[cpu_tracking] Start [7f10680c9970]
Calling: /omd/sites/mysite/local/share/check_mk/agents/special/agent_my_rest_api '--ClientID' 'nottellingyou' '--ClientSecret' 'secret' '--FileSpaceName' 'filespace.anttest' '--WarningTiB' '1' '--CriticalTiB' '2'
[ProgramFetcher] Fetch with cache settings: DefaultAgentFileCache(base_path=PosixPath('/omd/sites/mysite/tmp/check_mk/data_source_cache/special_my_rest_api/localhost'), max_age=MaxAge(checking=0, discovery=120, inventory=120), disabled=False, use_outdated=False, simulation=False)
Not using cache (Mode Mode.FORCE_SECTIONS)
[ProgramFetcher] Execute data source
Not using cache (Mode Mode.FORCE_SECTIONS)
[cpu_tracking] Stop [7f10680c9970 - Snapshot(process=posix.times_result(user=0.0, system=0.0, children_user=0.16, children_system=0.02, elapsed=1.050000000745058))]
Source: SourceType.HOST/FetcherType.PIGGYBACK
[cpu_tracking] Start [7f10680c9340]
No piggyback files for 'localhost'. Skip processing.
No piggyback files for '127.0.0.1'. Skip processing.
[PiggybackFetcher] Fetch with cache settings: NoCache(base_path=PosixPath('/omd/sites/mysite/tmp/check_mk/data_source_cache/piggyback/localhost'), max_age=MaxAge(checking=0, discovery=120, inventory=120), disabled=False, use_outdated=False, simulation=False)
Not using cache (Mode Mode.FORCE_SECTIONS)
[PiggybackFetcher] Execute data source
Not using cache (Mode Mode.FORCE_SECTIONS)
[cpu_tracking] Stop [7f10680c9340 - Snapshot(process=posix.times_result(user=0.0, system=0.0, children_user=0.0, children_system=0.0, elapsed=0.0))]
[cpu_tracking] Start [7f10680c9970]
+ PARSE FETCHER RESULTS
Source: SourceType.HOST/FetcherType.PROGRAM
No persisted sections loaded
-> Add sections: []
Source: SourceType.HOST/FetcherType.PIGGYBACK
No persisted sections loaded
-> Add sections: []
Received no piggyback data
Loading item states
Trying to acquire lock on /omd/sites/mysite/tmp/check_mk/counters/localhost
Got lock on /omd/sites/mysite/tmp/check_mk/counters/localhost
Releasing lock on /omd/sites/mysite/tmp/check_mk/counters/localhost
Released lock on /omd/sites/mysite/tmp/check_mk/counters/localhost
[cpu_tracking] Stop [7f10680c9970 - Snapshot(process=posix.times_result(user=0.0, system=0.0, children_user=0.0, children_system=0.0, elapsed=0.0))]
[special_my_rest_api] Version: unknown, OS: unknown, execution time 1.1 sec | execution_time=1.050 user_time=0.000 system_time=0.000 children_user_time=0.160 children_system_time=0.020 cmk_time_ds=0.870 cmk_time_agent=0.000
if i call the special agent the same way, there is output:
OMD[mysite]:~$ python3 /omd/sites/mysite/local/share/check_mk/agents/special/agent_my_rest_api '--ClientID' 'nottellingyou' '--ClientSecret' 'secret' '--FileSpaceName' 'filespace.anttest' '--WarningTiB' '1' '--CriticalTiB' '2'
<<<my_rest_api>>>
filespace.anttest 17248
Thanks of any tips on how to check what is going on under the hood.
Ant