示例#1
0
def _get_generic_crash_info(type_name, details):
    # type: (Text, Dict) -> Dict
    """Produces the crash info data structure.

    The top level keys of the crash info dict are standardized and need
    to be set for all crash reports."""
    exc_type, exc_value, exc_traceback = sys.exc_info()

    tb_list = traceback.extract_tb(exc_traceback)

    # TODO: This ma be cleaned up by using reraising with python 3
    # MKParseFunctionError() are re raised exceptions originating from the
    # parse functions of checks. They have the original traceback object saved.
    # The formated stack of these tracebacks is somehow relative to the calling
    # function. To get the full stack trace instead of this relative one we need
    # to concatenate the traceback of the MKParseFunctionError() and the original
    # exception.
    # Re-raising exceptions will be much easier with Python 3.x.
    if exc_type and exc_value and exc_type.__name__ == "MKParseFunctionError":
        tb_list += traceback.extract_tb(
            exc_value.exc_info()[2])  # type: ignore

    # Unify different string types from exception messages to a unicode string
    # HACK: copy-n-paste from cmk.utils.exception.MKException.__str__ below.
    # Remove this after migration...
    if exc_value is None or not exc_value.args:
        exc_txt = six.text_type("")
    elif len(exc_value.args) == 1 and isinstance(exc_value.args[0],
                                                 six.binary_type):
        try:
            exc_txt = exc_value.args[0].decode("utf-8")
        except UnicodeDecodeError:
            exc_txt = u"b%s" % repr(exc_value.args[0])
    elif len(exc_value.args) == 1:
        exc_txt = six.text_type(exc_value.args[0])
    else:
        exc_txt = six.text_type(exc_value.args)

    return {
        "id": str(uuid.uuid1()),
        "crash_type": type_name,
        "time": time.time(),
        "os": _get_os_info(),
        "version": cmk.__version__,
        "edition": cmk.edition_short(),
        "core": _current_monitoring_core(),
        "python_version": sys.version,
        "python_paths": sys.path,
        "exc_type": exc_type.__name__ if exc_type else None,
        "exc_value": exc_txt,
        "exc_traceback": tb_list,
        "local_vars": _get_local_vars_of_last_exception(),
        "details": details,
    }
示例#2
0
def search(user=None, token_info=None):
    return {
        "site": cmk.omd_site(),
        "group": request.environ.get('mod_wsgi.application_group', 'unknown'),
        "versions": {
            "apache": request.environ.get('apache.version', 'unknown'),
            "checkmk": cmk.omd_version(),
            "python": sys.version,
            'mod_wsgi': request.environ.get('mod_wsgi.version', 'unknown'),
            'wsgi': request.environ['wsgi.version'],
        },
        "edition": cmk.edition_short(),
        "demo": cmk.is_demo(),
    }
示例#3
0
def search(param):
    if request.args.get('fail'):
        raise Exception("This is an intentional failure.")
    return {
        "site": cmk.omd_site(),
        "group": request.environ.get('mod_wsgi.application_group', 'unknown'),
        "versions": {
            "apache": request.environ.get('apache.version', 'unknown'),
            "checkmk": cmk.omd_version(),
            "python": sys.version,
            'mod_wsgi': request.environ.get('mod_wsgi.version', 'unknown'),
            'wsgi': request.environ['wsgi.version'],
        },
        "edition": cmk.edition_short(),
        "demo": cmk.is_demo(),
    }
示例#4
0
    def page(self):
        if not config.user.may("wato.automation"):
            raise MKAuthException(
                _("This account has no permission for automation."))

        html.set_output_format("python")

        if not html.request.has_var("_version"):
            # Be compatible to calls from sites using versions before 1.5.0p10.
            # Deprecate with 1.7 by throwing an exception in this situation.
            response = _get_login_secret(create_on_demand=True)
        else:
            response = {
                "version": cmk.__version__,
                "edition_short": cmk.edition_short(),
                "login_secret": _get_login_secret(create_on_demand=True),
            }
        html.write_html(repr(response))
示例#5
0
def create_crash_info(crash_type, details=None, version=None):
    if details is None:
        details = {}

    if version is None:
        version = cmk.__version__

    exc_type, exc_value, exc_traceback = sys.exc_info()

    tb_list = traceback.extract_tb(exc_traceback)

    # MKParseFunctionError() are re raised exceptions originating from the
    # parse functions of checks. They have the original traceback object saved.
    # The formated stack of these tracebacks is somehow relative to the calling
    # function. To get the full stack trace instead of this relative one we need
    # to concatenate the traceback of the MKParseFunctionError() and the original
    # exception.
    # Re-raising exceptions will be much easier with Python 3.x.
    if exc_type.__name__ == "MKParseFunctionError":
        tb_list += traceback.extract_tb(exc_value.exc_info()[2])

    # Unify different string types from exception messages to a unicode string
    try:
        exc_txt = six.text_type(exc_value)
    except UnicodeDecodeError:
        exc_txt = str(exc_value).decode("utf-8")

    return {
        "crash_type": crash_type,
        "time": time.time(),
        "os": get_os_info(),
        "version": version,
        "edition": cmk.edition_short(),
        "core": _current_monitoring_core(),
        "python_version": sys.version,
        "python_paths": sys.path,
        "exc_type": exc_type.__name__,
        "exc_value": exc_txt,
        "exc_traceback": tb_list,
        "local_vars": get_local_vars_of_last_exception(),
        "details": details,
    }
示例#6
0
 def execute(self, _unused_request):
     return {
         "version": cmk.__version__,
         "edition": cmk.edition_short(),
     }