Werk #3585: Implemented API for exporting the full host inventory

Component HW/SW inventory
Title Implemented API for exporting the full host inventory
Date May 31, 2016
Checkmk Edition Checkmk Raw (CRE)
Checkmk Version 1.4.0i1
Level Prominent Change
Class New Feature
Compatibility Compatible - no manual interaction needed

The HW/SW inventory data can now be exported using a webservice. This webservice outputs the raw structured inventory data of a host.

The URL to this webservice is:

http://[MONITORING-SERVER]/[SITE]/check_mk/host_inv_api.py?host=[HOST]&output_format=json

You choose one of these output formats: json, xml, python.

The data provided by this webservice looks as follows:

{
    "result": {
        "hardware": {
            "memory": {
                "total_ram_usable": 16697331712,
                "total_swap": 17049841664,
                "total_vmalloc": 35184372087808
            }
        },
        "networking": {
            "hostname": "Klappspaten"
        }
    },
    "result_code": 0
}

The data below the key result is the HW/SW inventory data.

In case an error occurs during processing of the request, for example a host can not be found, the result_code is set to 1 and the result contains the error message:

{"result": "Found no inventory data for this host.", "result_code": 1}

You can also request data of multiple hosts at once. In this case, you need to specify your request like this:

http://[MONITORING-SERVER]/[SITE]/check_mk/host_inv_api.py?request={"hosts": ["host1", "host2"]}&output_format=json

You will then get an answer that is similar to the answer above. With the difference that the top level dictionary uses the host names as keys and the values are the inventory tree of this host.

{
    "result": {
        "gestern": {
            "hardware": {
                "memory": {
                    "total_ram_usable": 16697307136,
                    "total_swap": 17049841664,
                    "total_vmalloc": 35184372087808
                }
            },
            "networking": {
                "hostname": "Klappspaten"
            }
        },
        "heute": {
            "hardware": {
                "memory": {
                    "total_ram_usable": 16697307136,
                    "total_swap": 17049841664,
                    "total_vmalloc": 35184372087808
                }
            },
            "networking": {
                "hostname": "Klappspaten"
            }
        },
        "slave": {}
    },
    "result_code": 0
}

Another difference in this mode: When a host has no inventory data, the host has an empty dictionary as value instead of providing an error result.

If you want to only have a subset of inventory data, you can specify a list of inventory paths which are then used to filter the tree. Only hosts that have those paths will show the trees.

For example, if you only want to see the total and swap memory information of a single host, you can use the following URL:

http://[MONITORING-SERVER]/[SITE]/check_mk/host_inv_api.py?host=[HOST]&request={"paths": [".hardware.memory.total_ram_usable", ".hardware.memory.total_swap"]}&output_format=json

You will get back only the requested data:

{
    "result": {
        "": {
            "hardware": {
                "memory": {
                    "total_ram_usable": 16697307136,
                    "total_swap": 17049841664
                }
            }
        }
    },
    "result_code": 0
}

To the list of all Werks