Werk #8643: Web API: New API for fetching graph data

Component Metrics system
Title Web API: New API for fetching graph data
Date Dec 2, 2016
Checkmk Edition Checkmk Enterprise (CEE)
Checkmk Version 1.4.0i3
Level Prominent Change
Class New Feature
Compatibility Compatible - no manual interaction needed

The raw data of the Check_MK graphs can now be fetched via the Web API. The new action is named get_graph.

The request object is structured like this:

{
    "specification": [..., ...],
    "data_range": {
        "time_range" : [..., ...],
    }
}

The specification is using the Check_MK internal graph specification format. The first element is the specification type (template, custom or explicit. The structure of the second element depends on the type. Please take a look at the examples below to get an idea of it.

The time range is given in two unix timestamps, the start time and the end time.

For example this command can be used to fetch the first graph of the Check_MK service of the host myhost123:

UP:curl "http://mycmkserver/mysite/check_mk/webapi.py?action=get_graph&_username=automation&_secret=af665c15-5728-4541-b5bf-04d1d98deee8" -d 'request={"specification": ["template", {"service_description": "Check_MK", "site": "mysite", "graph_index": 0, "host_name": "myhost123" }], "data_range": {"time_range": [1480653120, 1480667520]}}'

The answer may look like this:

{
    "result": {
        "step": 60,
        "start_time": 1480653120,
        "end_time": 1480667520,
        "curves": [
            {
                "color": "#87f058",
                "rrddata": [null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, 0.05, 0.059, 0.0423333, 0.0488333, 0.0413333, 0.0573333, 0.0515, 0.05, 0.05, 0.05, 0.05, 0.058, 0.052, 0.0578333, 0.0365, 0.0453333, 0.0576667, 0.0525, 0.05, 0.0573333, 0.0526667, 0.0428333, 0.0471667, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.0436667, 0.0526667, 0.06, 0.06, 0.054, 0.05, 0.0558333, 0.0541667, 0.0556667, 0.049, 0.0455, 0.0553333, 0.0493333, 0.04, 0.0451667, 0.05, 0.05, 0.05],
                "line_type": "stack",
                "title": "CPU time in user space"
            },
        ]
    },
    "result_code": 0
}

This command is used to fetch the data of a custom graph named custom_graph_1:

UP:curl "http://mycmkserver/mysite/check_mk/webapi.py?action=get_graph&_username=automation&_secret=af665c15-5728-4541-b5bf-04d1d98deee8" -d 'request={"specification": ["custom", "custom_graph_1"], "data_range": {"time_range": [1480653120, 1480667520]}}'

To the list of all Werks