コード例 #1
0
ファイル: pages.py プロジェクト: troelsarvin/checkmk
    def handle_page(self) -> None:
        """The page handler, called by the page registry"""
        # FIXME: cyclical link between crash_reporting.py and pages.py
        from cmk.gui.crash_reporting import handle_exception_as_gui_crash_report

        response.set_content_type("application/json")
        try:
            action_response = self.page()
            resp = {"result_code": 0, "result": action_response, "severity": "success"}
        except MKMissingDataError as e:
            resp = {"result_code": 1, "result": str(e), "severity": "success"}
        except MKException as e:
            resp = {"result_code": 1, "result": str(e), "severity": "error"}

        except Exception as e:
            if config.debug:
                raise
            logger.exception("error calling AJAX page handler")
            handle_exception_as_gui_crash_report(
                plain_error=True,
                show_crash_link=getattr(g, "may_see_crash_reports", False),
            )
            resp = {"result_code": 1, "result": str(e), "severity": "error"}

        response.set_data(json.dumps(resp))
コード例 #2
0
def handle_unhandled_exception() -> Response:
    handle_exception_as_gui_crash_report(
        plain_error=plain_error(),
        fail_silently=fail_silently(),
        show_crash_link=getattr(g, "may_see_crash_reports", False),
    )
    # This needs to be cleaned up.
    return html.response
コード例 #3
0
 def handle_page(self) -> None:
     try:
         response.set_content_type("application/cbor")
         response.set_data(cbor.encode(self.page()))
     except Exception as e:
         response.status_code = http_client.INTERNAL_SERVER_ERROR
         handle_exception_as_gui_crash_report(
             plain_error=True,
             show_crash_link=getattr(g, "may_see_crash_reports", False),
         )
         response.set_data(str(e))
コード例 #4
0
def _process_request():  # pylint: disable=too-many-branches
    try:
        config.initialize()
        html.init_modes()

        # Make sure all plugins are available as early as possible. At least
        # we need the plugins (i.e. the permissions declared in these) at the
        # time before the first login for generating auth.php.
        _load_all_plugins()

        page_handler = get_and_wrap_page(html.myfile)
        page_handler()
        # If page_handler didn't raise we assume everything is OK.
        response.status_code = six.moves.http_client.OK

    except HTTPRedirect as e:
        response.status_code = e.status
        response.headers["Location"] = e.url

    except FinalizeRequest as e:
        response.status_code = e.status

    except livestatus.MKLivestatusNotFoundError as e:
        _render_exception(e, title=_("Data not found"))

    except MKUserError as e:
        _render_exception(e, title=_("Invalid user Input"))

    except MKAuthException as e:
        _render_exception(e, title=_("Permission denied"))

    except livestatus.MKLivestatusException as e:
        _render_exception(e, title=_("Livestatus problem"))
        response.status_code = six.moves.http_client.BAD_GATEWAY

    except MKUnauthenticatedException as e:
        _render_exception(e, title=_("Not authenticated"))
        response.status_code = six.moves.http_client.UNAUTHORIZED

    except MKConfigError as e:
        _render_exception(e, title=_("Configuration error"))
        logger.error("MKConfigError: %s", e)

    except MKGeneralException as e:
        _render_exception(e, title=_("General error"))
        logger.error("MKGeneralException: %s", e)

    except Exception:
        crash_reporting.handle_exception_as_gui_crash_report(
            _plain_error(), _fail_silently())
コード例 #5
0
ファイル: pages.py プロジェクト: bbaumer/checkmk
 def _handle_exc(self, method) -> None:
     # FIXME: cyclical link between crash_reporting.py and pages.py
     from cmk.gui.crash_reporting import handle_exception_as_gui_crash_report
     try:
         # FIXME: These methods write to the response themselves. This needs to be refactored.
         method()
     except MKException as e:
         response.status_code = http_client.BAD_REQUEST
         html.write_text(str(e))
     except Exception as e:
         response.status_code = http_client.INTERNAL_SERVER_ERROR
         if config.debug:
             raise
         logger.exception("error calling AJAX page handler")
         handle_exception_as_gui_crash_report(
             plain_error=True,
             show_crash_link=getattr(g, "may_see_crash_reports", False),
         )
         html.write_text(str(e))
コード例 #6
0
    def handle_page(self) -> None:
        """The page handler, called by the page registry"""
        # FIXME: cyclical link between crash_reporting.py and pages.py
        from cmk.gui.crash_reporting import handle_exception_as_gui_crash_report
        html.set_output_format("json")
        try:
            action_response = self.page()
            response = {"result_code": 0, "result": action_response}
        except MKException as e:
            response = {"result_code": 1, "result": "%s" % e}

        except Exception as e:
            if config.debug:
                raise
            logger.exception("error calling AJAX page handler")
            handle_exception_as_gui_crash_report(
                plain_error=True,
                show_crash_link=getattr(g, "may_see_crash_reports", False),
            )
            response = {"result_code": 1, "result": "%s" % e}

        html.write(json.dumps(response))
コード例 #7
0
def _process_request(environ, start_response):  # pylint: disable=too-many-branches
    try:
        html.init_modes()

        # Make sure all plugins are available as early as possible. At least
        # we need the plugins (i.e. the permissions declared in these) at the
        # time before the first login for generating auth.php.
        _load_all_plugins()

        page_handler = get_and_wrap_page(html.myfile)
        response = page_handler()
        # If page_handler didn't raise we assume everything is OK.
        response.status_code = http_client.OK
    except HTTPRedirect as e:
        # This can't be a new Response as it can have already cookies set/deleted by the pages.
        # We can't return the response because the Exception has been raised instead.
        # TODO: Remove all HTTPRedirect exceptions from all pages. Making the Exception a subclass
        #       of Response may also work as it can then be directly returned from here.
        response = html.response
        response.status_code = e.status
        response.headers["Location"] = e.url

    except FinalizeRequest as e:
        # This doesn't seem to serve much purpose anymore.
        # TODO: Remove all FinalizeRequest exceptions from all pages and replace it with a `return`.
        #       It may be necessary to rewire the control-flow a bit as this exception could have
        #       been used to short-circuit some code and jump directly to the response. This
        #       needs to be changed as well.
        response = html.response
        response.status_code = e.status

    except livestatus.MKLivestatusNotFoundError as e:
        response = _render_exception(e, title=_("Data not found"))

    except MKUserError as e:
        response = _render_exception(e, title=_("Invalid user Input"))

    except MKAuthException as e:
        response = _render_exception(e, title=_("Permission denied"))

    except livestatus.MKLivestatusException as e:
        response = _render_exception(e, title=_("Livestatus problem"))
        response.status_code = http_client.BAD_GATEWAY

    except MKUnauthenticatedException as e:
        response = _render_exception(e, title=_("Not authenticated"))
        response.status_code = http_client.UNAUTHORIZED

    except MKConfigError as e:
        response = _render_exception(e, title=_("Configuration error"))
        logger.error("MKConfigError: %s", e)

    except MKGeneralException as e:
        response = _render_exception(e, title=_("General error"))
        logger.error("MKGeneralException: %s", e)

    except Exception:
        crash_reporting.handle_exception_as_gui_crash_report(
            _plain_error(), _fail_silently())
        # This needs to be cleaned up.
        response = html.response

    return response(environ, start_response)