This article explains how special agents can get their parameters via stdin.


Step-by-step guide

A couple of our special agents get their parameters via stdin. For example, the Prometheus special agent or the AWS special agent. You can see this in the output of the command cmk -D myhost. If after the line for Program  you find a line beginning with Program stdin, you have to pipe these parameters into the special agent with echo.

Let's say you want to debug the special agent for Prometheus. You configured a rule and pinned it to the host myprometheushost. Log in as the site user and run the following command:

OMD[mysite]:~$ cmk -D myprometheushost

The output will look something like this:

Tags:                   [address_family:ip-v4-only], [agent:cmk-agent], [checkmk-agent:checkmk-agent], [criticality:prod], [ip-v4:ip-v4], [networking:lan], [piggyback:auto-piggyback], [site:kube], [snmp_ds:no-snmp], [tcp:tcp]
Labels:                 [cmk/site:mysite]
Host groups:            check_mk
Contact groups:         all
Agent mode:             Normal Checkmk agent, or special agent if configured
Type of agent:          
  Program: /omd/sites/kube/local/share/check_mk/agents/special/agent_prometheus 
  Program stdin:
{'connection': ('ip_address', {'port': 31275}), 'verify-cert': False, 'protocol': 'http', 'exporter': [('kube_state', {'cluster_name': 'mypromcluster', 'prepend_namespaces': 'use_namespace', 'entities': ['cluster', 'nodes', 'services', 'pods', 'daemon_sets']})], 'promql_checks': [], 'host_address': '', 'host_name': 'myprometheushost'}
  Process piggyback data from /omd/sites/mysite/tmp/check_mk/piggyback/myprometheushost

Now go ahead and copy the block after Program stdin wrap it in double quotes and prepend it with an echo. Next, put a pipe and the path to the special agent you find in the line, starting with Program. Together it looks like this:

OMD[mysite]:~$ echo "{'connection': ('ip_address', {'port': 31275}), 'verify-cert': False, 'protocol': 'http', 'exporter': [('kube_state', {'cluster_name': 'mypromcluster', 'prepend_namespaces': 'use_namespace', 'entities': ['cluster', 'nodes', 'services', 'pods', 'daemon_sets']})], 'promql_checks': [], 'host_address': '', 'host_name': 'myprometheushost'}" | /omd/sites/mysite/local/share/check_mk/agents/special/agent_prometheus

In most cases, the special agents offer the possibility to activate verbose output or debug output from Python. Simply append -vvv  and/or --debug at the very end of the command above.