コード例 #1
0
ファイル: test_http.py プロジェクト: n00rm/checkmk
def test_request_processing(register_builtin_html):
    html.request.set_var("varname", "1a")
    html.request.set_var("varname2", "1")

    html.get_unicode_input("varname", deflt="lol")
    html.get_integer_input("varname2")
    html.get_request(exclude_vars=["varname2"])
コード例 #2
0
    def _ajax_show_nagvis_maps_snapin(self):
        request = html.get_request()
        if request["type"] == "table":
            self._show_table(request)
        elif request["type"] == "tree":
            self._show_tree(request)
        else:
            raise NotImplementedError()

        self._show_footnote_links()
コード例 #3
0
def ajax_render_graph_content():
    html.set_output_format("json")
    try:
        request = html.get_request()
        response = {
            "result_code": 0,
            "result": render_graph_content_html(request["graph_recipe"],
                                                request["graph_data_range"],
                                                request["graph_render_options"]),
        }
    except Exception:
        logger.exception("could not render graph")
        response = {
            "result_code": 1,
            "result": _("Unhandled exception: %s") % traceback.format_exc(),
        }

    html.write(json.dumps(response))
コード例 #4
0
def page_host_inv_api():
    # The response is always a top level dict with two elements:
    # a) result_code - This is 0 for expected processing and 1 for an error
    # b) result      - In case of an error this is the error message, a UTF-8 encoded string.
    #                  In case of success this is a dictionary containing the host inventory.
    try:
        request = html.get_request()
        # The user can either specify a single host or provide a list of host names. In case
        # multiple hosts are handled, there is a top level dict added with "host > invdict" pairs
        hosts = request.get("hosts")
        if hosts:
            result = {}
            for host_name in hosts:
                result[host_name] = inventory_of_host(host_name, request)

        else:
            host_name = request.get("host")
            if host_name is None:
                raise MKUserError("host", _("You need to provide a \"host\"."))

            result = inventory_of_host(host_name, request)

            if not result and not has_inventory(host_name):
                raise MKGeneralException(
                    _("Found no inventory data for this host."))

        response = {"result_code": 0, "result": result}

    except MKException as e:
        response = {"result_code": 1, "result": "%s" % e}

    except Exception as e:
        if config.debug:
            raise
        response = {"result_code": 1, "result": "%s" % e}

    if html.output_format == "json":
        _write_json(response)
    elif html.output_format == "xml":
        _write_xml(response)
    else:
        _write_python(response)
コード例 #5
0
def _get_request(api_call):
    if api_call.get("dont_eval_request"):
        return html.request.var("request", {})
    return html.get_request(exclude_vars=["action", "pretty_print"])
コード例 #6
0
def _get_request(api_call):
    if api_call.get("dont_eval_request"):
        req = html.request.var("request")
        return {} if req is None else req
    return html.get_request(exclude_vars=["action", "pretty_print"])
コード例 #7
0
 def webapi_request(self):
     return html.get_request()
コード例 #8
0
 def webapi_request(self):
     # type: () -> Dict[str, str]
     return html.get_request()
コード例 #9
0
ファイル: pages.py プロジェクト: fayepal/checkmk
 def webapi_request(self):
     # type: () -> Dict[Text, Text]
     return html.get_request()
コード例 #10
0
 def webapi_request(self) -> Dict[str, str]:
     return html.get_request()