Ejemplo n.º 1
0
def test_get_graph_image(web, graph_test_config):
    result = web.post("graph_image.py",
                      data={
                          "request": json.dumps({
                              "specification": [
                                  "template", {
                                      "service_description": "Check_MK",
                                      "site": web.site.id,
                                      "graph_index": 0,
                                      "host_name": "test-host-get-graph",
                                  }
                              ],
                          }),
                      })

    content = result.content

    assert content.startswith(b'\x89PNG')

    try:
        Image.open(BytesIO(content))
    except IOError:
        raise Exception("Failed to open image: %r" % content)
Ejemplo n.º 2
0
def test_get_graph_hover(web, graph_test_config):
    graph_context = {
        u'definition': {
            u'explicit_vertical_range': [None, None],
            u'title':
            u'Time usage by phase',
            u'horizontal_rules': [],
            u'specification': [
                u'template', {
                    u'service_description': u'Check_MK',
                    u'site': web.site.id,
                    u'graph_index': 0,
                    u'host_name': u'test-host-get-graph'
                }
            ],
            u'consolidation_function':
            u'max',
            u'metrics': [{
                u'color':
                u'#87f058',
                u'line_type':
                u'stack',
                u'expression': [
                    u'operator', u'+',
                    [[
                        u'rrd', u'test-host-get-graph', u'test-host-get-graph',
                        u'Check_MK', u'user_time', None, 1
                    ],
                     [
                         u'rrd', u'test-host-get-graph',
                         u'test-host-get-graph', u'Check_MK',
                         u'children_user_time', None, 1
                     ]]
                ],
                u'unit':
                u's',
                u'title':
                u'CPU time in user space'
            }, {
                u'color':
                u'#ff8840',
                u'line_type':
                u'stack',
                u'expression': [
                    u'operator', u'+',
                    [[
                        u'rrd', u'test-host-get-graph', u'test-host-get-graph',
                        u'Check_MK', u'system_time', None, 1
                    ],
                     [
                         u'rrd', u'test-host-get-graph',
                         u'test-host-get-graph', u'Check_MK',
                         u'children_system_time', None, 1
                     ]]
                ],
                u'unit':
                u's',
                u'title':
                u'CPU time in operating system'
            }, {
                u'color':
                u'#00b2ff',
                u'line_type':
                u'stack',
                u'expression': [
                    u'rrd', u'test-host-get-graph', u'test-host-get-graph',
                    u'Check_MK', u'cmk_time_agent', None, 1
                ],
                u'unit':
                u's',
                u'title':
                u'Time spent waiting for Check_MK agent'
            }, {
                u'color':
                u'#d080af',
                u'line_type':
                u'line',
                u'expression': [
                    u'rrd', u'test-host-get-graph', u'test-host-get-graph',
                    u'Check_MK', u'execution_time', None, 1
                ],
                u'unit':
                u's',
                u'title':
                u'Total execution time'
            }],
            u'omit_zero_metrics':
            False,
            u'unit':
            u's'
        },
        u'graph_id': u'graph_0',
        u'data_range': {
            u'step': 20,
            u"time_range": [time.time() - 3600,
                            time.time()]
        },
        u'render_options': {
            u'preview': False,
            u'editing': False,
            u'font_size': 8,
            u'show_graph_time': True,
            u'resizable': True,
            u'show_time_axis': True,
            u'fixed_timerange': False,
            u'foreground_color': u'#000000',
            u'title_format': u'plain',
            u'canvas_color': u'#ffffff',
            u'show_legend': True,
            u'interaction': True,
            u'show_time_range_previews': True,
            u'show_title': True,
            u'show_margin': True,
            u'vertical_axis_width': u'fixed',
            u'show_controls': True,
            u'show_pin': True,
            u'background_color': u'#f8f4f0',
            u'show_vertical_axis': True,
            u'size': [70, 16]
        }
    }

    result = web.post("ajax_graph_hover.py",
                      data={
                          "context": json.dumps(graph_context),
                          "hover_time": int(time.time() - 300),
                      })

    data = result.json()

    assert "rendered_hover_time" in data
    assert len(data["curve_values"]) == 4

    for index, metric in enumerate(
            graph_context["definition"]["metrics"][::-1]):
        curve_value = data["curve_values"][index]

        assert curve_value["color"] == metric["color"]
        assert curve_value["title"] == metric["title"]

        # TODO: Wait for first values?
        assert curve_value["rendered_value"][0] is None
        assert curve_value["rendered_value"][1] == "n/a"