Obtaining the host IP address from Check_MK

I am writing an extensive check with snmp. I need to combine snmp data with json data.
I know how to get the hostname from Check_MK (host_name ())

But how to get its IP defined in Check_MK (ipv4) ???

The check plugin itself should not actively query any hosts. This may lead to obscure behaviour.

You should write a special agent for the JSON data and try to combine that in the configuration.

tl;dr: What problem are you trying to solve?

Queries SNMP a lot of data, which OIDs are unpredictable because it depends on the current situation on the device.
I need the SNMP and JSON source available via SSH
filter out data for a specific IP. This IP is the one defined in Check_MK in the IPv4 section.

I am not an advanced programmer, so far I have been writing chekc heads via snmp and a few special agents, but I have never combined them into one.

I haven’t solved the problem.
I know that in special agent we can get this IP from parameters,
but I don’t know how to connect them to the SNMP query.

For now, I got around the problem … I pull a dozen or so IPs via SNMP, which are defined on the device and statically filters them. It works, but if in the future IP planning changes I will have to improve the code. This is not a nice solution.

I download json data via ssh using paramiko.

@WojRep just came across this ancient thread since i need to automatically detect hosts that are accessed with NAT address. Did you find a clean solution for that problem? Currently I work around with this one (but I am not really happy with that):

    # full path file name to cmk command (not in PATH)
    from os.path import expanduser
    cmk='%s/%s' % (expanduser("~"), '/bin/cmk')

    # did not find proper way to get (WATO-) IP of the monitored host :o(
    cmkip = os.popen('%s -D %s| awk \'/^Addr/ {print $2}\'' % (cmk, host_name())).read().rstrip()

Or anybody else with some hint?


If i need the host list inside my scripts i would do a GET on the API endpoint
Inside the list of “value” you can find for every entry the “id”/“title” and under “extensions”:“attributes”:“ipaddress” the corresponding address.

1 Like

Hi @andreas-doehler, thanks for that. I think, I’d stay with my os.popen, this is much less hazzle for me and only done on inventory. But would be cool to have easy access to such host information within checks, just as host_name().

Regards, und viele Grüße,