Werk #4733: Check_MK graphs can now be exported as PNG images

Component Metrics system
Title Check_MK graphs can now be exported as PNG images
Date May 22, 2017
Checkmk Edition Checkmk Enterprise (CEE)
Checkmk Version 1.5.0i1
Level Prominent Change
Class New Feature
Compatibility Compatible - no manual interaction needed

It is now possible to export the Check_MK graphs as static PNG images. This mechanism can be used to to integrate the graphs in 3rd party tools. For example, you can use it to add graphs to NagVis maps or to the hover menu of NagVis.

The new page is named graph_image.py. The page is receiving a single request parameter that is structured equal to the JSON/python graph API (See werk #8643).

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. But the whole data_range specification is optional. In case you don't provide it, the 25h graph will be rendered.

The answer to this request is a single, dynamically rendered, PNG image.

Please note that this request is done in the context of the currently logged in user. So the user that opens a page containing this snippet needs to be authenticated with the Check_MK GUI and able to see the image. Otherwise the user won't be able to see the image.

The most common use case will be to add the image generated by this. The following snippets show how it can be embedded:

<img src="http://mycmkserver/mysite/check_mk/graph_image.py?request={%22specification%22:%20[%22template%22,%20{%22service_description%22:%20%22CPU%20load%22,%20%22site%22:%20%22mysite%22,%20%22host_name%22:%20%22myhost%22}]}">

This will try to open the image from the Check_MK site mysite on the server mycmkserver. The graph is specified by the following request object in URL encoded form:

{
    "specification": ["template", {
        "service_description": "CPU load",
        "site": "mysite",
        "host_name": "myhost"
    }]
}

It is also possible to adapt the rendering attributes of the graph using the render_options data structure. This example hides the legend and the title of the graph and sets a custom image size:

<img src="http://mycmkserver/mysite/check_mk/graph_image.py?request={%22specification%22:%20[%22template%22,%20{%22service_description%22:%20%22CPU%20load%22,%20%22site%22:%20%22mysite%22,%20%22host_name%22:%20%22myhost%22}],%20%22render_options%22:%20{%22show_legend%22:%20false,%20%22show_title%22:%20false,%20%22size%22:%20[50,15]}}">

Again, the human friendly formated request object:

{
    "specification": ["template", {
        "service_description": "CPU load",
        "site": "mysite",
        "host_name": "myhost"
    }],
    "render_options": {
        "show_legend": false,
        "show_title": false,
        "size": [ 50, 15 ]
    }
}

In case you want to render custom graphs, you can use a specification like this in your request. Replace custom_graph_1 with the ID of the custom graph you like to see:

["custom", "custom_graph_1"]

To the list of all Werks