Esempio n. 1
0
def render_cmk_graphs(context):
    if context["WHAT"] == "HOST":
        svc_desc = "_HOST_"
    else:
        svc_desc = context["SERVICEDESC"]

    url = "http://localhost:%d/%s/check_mk/ajax_graph_images.py?host=%s&service=%s" % \
                    (site.get_apache_port(), os.environ["OMD_SITE"],
                     urllib.quote(context["HOSTNAME"]), urllib.quote(svc_desc))

    try:
        json_data = urllib2.urlopen(url).read()
    except Exception as e:
        if opt_debug:
            raise
        sys.stderr.write("ERROR: Failed to fetch graphs: %s\nURL: %s\n" %
                         (e, url))
        return []

    try:
        base64_strings = json.loads(json_data)
    except Exception as e:
        if opt_debug:
            raise
        sys.stderr.write(
            "ERROR: Failed to decode graphs: %s\nURL: %s\nData: %r\n" %
            (e, url, json_data))
        return []

    return map(base64.b64decode, base64_strings)
Esempio n. 2
0
def render_cmk_graphs(context: dict[str, str], is_bulk: bool) -> list[bytes]:
    if context["WHAT"] == "HOST":
        svc_desc = "_HOST_"
    else:
        svc_desc = context["SERVICEDESC"]

    url = (
        "http://localhost:%d/%s/check_mk/ajax_graph_images.py?host=%s&service=%s&num_graphs=%s"
        % (
            site.get_apache_port(),
            os.environ["OMD_SITE"],
            quote(context["HOSTNAME"]),
            quote(svc_desc),
            quote(context["PARAMETER_GRAPHS_PER_NOTIFICATION"]),
        ))

    try:
        with urlopen(url) as opened_file:
            json_data = opened_file.read()
    except Exception as e:
        if opt_debug:
            raise
        sys.stderr.write("ERROR: Failed to fetch graphs: %s\nURL: %s\n" %
                         (e, url))
        return []

    try:
        base64_strings = json.loads(json_data)
    except Exception as e:
        if opt_debug:
            raise
        sys.stderr.write(
            "ERROR: Failed to decode graphs: %s\nURL: %s\nData: %r\n" %
            (e, url, json_data))
        return []

    return [base64.b64decode(s) for s in base64_strings]
Esempio n. 3
0
def test_get_apache_port() -> None:
    assert site.get_apache_port() == 5002