Licenses: Updated the list of licenses and added a PDF containing all license texts
[check_mk.git] / .werks / 4733
blob8163c46d2fa35dfa9e6ceafc7cdf729294fcb4c4
1 Title: Check_MK graphs can now be exported as PNG images
2 Level: 2
3 Component: metrics
4 Compatible: compat
5 Edition: cee
6 Version: 1.5.0i1
7 Date: 1495455247
8 Class: feature
10 It is now possible to export the Check_MK graphs as static PNG images. This mechanism
11 can be used to to integrate the graphs in 3rd party tools. For example, you can use it
12 to add graphs to NagVis maps or to the hover menu of NagVis.
14 The new page is named <tt>graph_image.py</tt>. The page is receiving a single request
15 parameter that is structured equal to the JSON/python graph API (See werk #8643).
17 The request object is structured like this:
19 F+:
21     "specification": [..., ...],
22     "data_range": {
23         "time_range" : [..., ...],
24     }
26 F-:
28 The specification is using the Check_MK internal graph specification
29 format. The first element is the specification type (<tt>template</tt>,
30 <tt>custom</tt> or <tt>explicit</tt>.  The structure of the second element
31 depends on the type. Please take a look at the examples below to get an idea
32 of it.
34 The time range is given in two unix timestamps, the start time and the
35 end time. But the whole <tt>data_range</tt> specification is optional. In
36 case you don't provide it, the 25h graph will be rendered.
38 The answer to this request is a single, dynamically rendered, PNG image.
40 Please note that this request is done in the context of the currently logged
41 in user. So the user that opens a page containing this snippet needs to be
42 authenticated with the Check_MK GUI and able to see the image. Otherwise the
43 user won't be able to see the image.
45 The most common use case will be to add the image generated by this. The
46 following snippets show how it can be embedded:
48 F+:
49 &lt;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}]}"&gt;
50 F-:
52 This will try to open the image from the Check_MK site <tt>mysite</tt> on
53 the server <tt>mycmkserver</tt>. The graph is specified by the following
54 request object in URL encoded form:
56 F+:
58     "specification": ["template", {
59         "service_description": "CPU load",
60         "site": "mysite",
61         "host_name": "myhost"
62     }]
64 F-:
66 It is also possible to adapt the rendering attributes of the graph using the
67 <tt>render_options</tt> data structure. This example hides the legend and the
68 title of the graph and sets a custom image size:
70 F+:
71 &lt;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]}}"&gt;
72 F-:
74 Again, the human friendly formated request object:
76 F+:
78     "specification": ["template", {
79         "service_description": "CPU load",
80         "site": "mysite",
81         "host_name": "myhost"
82     }],
83     "render_options": {
84         "show_legend": false,
85         "show_title": false,
86         "size": [ 50, 15 ]
87     }
89 F-:
91 In case you want to render custom graphs, you can use a specification like this
92 in your request. Replace <tt>custom_graph_1</tt> with the ID of the custom graph
93 you like to see:
95 F+:
96 ["custom", "custom_graph_1"]
97 F-: