check-mk

Get host status by CheckMK Web-API


I'm trying to get the status of a host with the CheckMK WebAPI. Can someone point me in the right direction how to get these data?

We're currently using CheckMK enterprise 1.4.0.

I've tried:

https://<monitoringhost.tld>/<site>/check_mk/webapi.py?action=get_host&_username=<user>&_secret=<secret>&output_format=json&effective_attributes=1&request={"hostname": "<hostname>"}

But the response does not have any relevant information about the host itself (e.g. state up/down, uptime, etc.).

{
"result": {
    "attributes": {
        "network_scan": {
            "scan_interval": 86400,
            "exclude_ranges": [],
            "ip_ranges": [],
            "run_as": "api"
        },
        "tag_agent": "cmk-agent",
        "snmp_community": null,
        "ipv6address": "",
        "alias": "",
        "management_protocol": null,
        "site": "testjke",
        "tag_address_family": "ip-v4-only",
        "tag_criticality": "prod",
        "contactgroups": [
            true,
            []
        ],
        "network_scan_result": {
            "start": null,
            "state": null,
            "end": null,
            "output": ""
        },
        "parents": [],
        "management_address": "",
        "tag_networking": "lan",
        "ipaddress": "",
        "management_snmp_community": null
    },
    "hostname": "<host>",
    "path": ""
},
"result_code": 0

Solution

  • The webapi is only for getting/setting the configuration of a host or other objects. If you want't to get the live status of a host use livestatus.

    If you enabled livestats on port 6557 (default) you could query the status of a host via network. If you are logged into a shell locally you can use 'lq'.

    OMD[mysite]:~$ lq "GET hosts\nColumns: name"
    

    Why: The CheckMK webapi if for accessing WATO. WATO is the source for creating the nagios configuration. Nagios will do the monitoring of the hosts and the livestatus api is an extension of the nagios core.