Beispiel #1
0
def _process_notify_message(msg):
    msg['id'] = utils.gen_id()
    msg['time'] = time.time()

    if isinstance(msg['dest'], str):
        dest_what = msg['dest']
    else:
        dest_what = msg['dest'][0]

    if dest_what == 'broadcast':
        recipients = list(config.multisite_users.keys())
    elif dest_what == 'online':
        recipients = userdb.get_online_user_ids()
    elif dest_what == 'list':
        recipients = msg['dest'][1]
    else:
        recipients = []

    num_recipients = len(recipients)

    num_success = {}
    for method in msg['methods']:
        num_success[method] = 0

    # Now loop all notitification methods to send the notifications
    errors: Dict[str, List[Tuple]] = {}
    for user_id in recipients:
        for method in msg['methods']:
            try:
                handler = _notify_methods()[method]['handler']
                handler(user_id, msg)
                num_success[method] = num_success[method] + 1
            except MKInternalError as e:
                errors.setdefault(method, []).append((user_id, e))

    message = _('The notification has been sent via<br>')
    message += "<table>"
    for method in msg['methods']:
        message += "<tr><td>%s</td><td>to %d of %d recipients</td></tr>" %\
                        (_notify_methods()[method]["title"], num_success[method], num_recipients)
    message += "</table>"

    message += _('<p>Sent notification to: %s</p>') % ', '.join(recipients)
    message += '<a href="%s">%s</a>' % (html.makeuri(
        []), _('Back to previous page'))
    html.show_message(HTML(message))

    if errors:
        error_message = HTML()
        for method, method_errors in errors.items():
            error_message += _(
                "Failed to send %s notifications to the following users:"
            ) % method
            table_rows = HTML()
            for user, exception in method_errors:
                table_rows += html.render_tr(
                    html.render_td(html.render_tt(user)) +
                    html.render_td(exception))
            error_message += html.render_table(table_rows) + html.render_br()
        html.show_error(error_message)
Beispiel #2
0
    def _major_page(self) -> None:
        html.header(
            self._title(),
            breadcrumb=_release_notes_breadcrumb(),
            page_state=_release_switch(major=True),
        )

        html.open_div(id_="release_title")
        html.h1(escape_html(_("Everything")) + html.render_br() + escape_html(_("monitored")))
        html.img(theme.url("images/tribe29.svg"))
        html.close_div()

        html.div(None, id_="release_underline")

        html.open_div(id_="release_content")
        for icon, headline, subline in [
            ("release_deploy", _("Deploy in minutes"), _("From 0 to Monitoring in <10min")),
            ("release_scale", _("With unlimited scale"), _("Hundred thousands of hosts")),
            ("release_automated", _("Highly automated"), _("Let Checkmk do the work for you")),
        ]:
            html.open_div(class_="container")
            html.img(theme.url(f"images/{icon}.svg"))
            html.div(headline)
            html.div(subline)
            html.close_div()
        html.close_div()

        html.open_div(id_="release_footer")
        html.span(_("© 2020 tribe29 GmbH. All Rights Reserved."))
        html.a(_("License aggreement"), href="https://checkmk.com/legal.html", target="_blank")
        html.a(_("Imprint"), href="https://checkmk.com/impressum.html", target="_blank")
        html.close_div()
Beispiel #3
0
    def _show_crash_report(self, info: CrashInfo) -> None:
        html.h3(_("Crash Report"), class_="table")
        html.open_table(class_=["data", "crash_report"])

        _crash_row(
            _("Exception"), "%s (%s)" % (info["exc_type"], info["exc_value"]), odd=True, pre=True
        )
        _crash_row(
            _("Traceback"), self._format_traceback(info["exc_traceback"]), odd=False, pre=True
        )
        _crash_row(
            _("Local Variables"),
            format_local_vars(info["local_vars"]) if "local_vars" in info else "",
            odd=True,
            pre=True,
        )

        _crash_row(_("Crash Type"), info["crash_type"], odd=False, legend=True)
        _crash_row(
            _("Time"), time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(info["time"])), odd=True
        )
        _crash_row(_("Operating System"), info["os"], False)
        _crash_row(_("Checkmk Version"), info["version"], True)
        _crash_row(_("Edition"), info.get("edition", ""), False)
        _crash_row(_("Core"), info.get("core", ""), True)
        _crash_row(_("Python Version"), info.get("python_version", _("Unknown")), False)

        joined_paths = html.render_br().join(info.get("python_paths", [_("Unknown")]))
        _crash_row(_("Python Module Paths"), joined_paths, odd=False)

        html.close_table()
Beispiel #4
0
def _process_notify_message(msg):
    msg["id"] = utils.gen_id()
    msg["time"] = time.time()

    if isinstance(msg["dest"], str):
        dest_what = msg["dest"]
    else:
        dest_what = msg["dest"][0]

    if dest_what == "broadcast":
        recipients = list(config.multisite_users.keys())
    elif dest_what == "online":
        recipients = userdb.get_online_user_ids()
    elif dest_what == "list":
        recipients = msg["dest"][1]
    else:
        recipients = []

    num_recipients = len(recipients)

    num_success = {}
    for method in msg["methods"]:
        num_success[method] = 0

    # Now loop all notitification methods to send the notifications
    errors: Dict[str, List[Tuple]] = {}
    for user_id in recipients:
        for method in msg["methods"]:
            try:
                handler = _notify_methods()[method]["handler"]
                handler(user_id, msg)
                num_success[method] = num_success[method] + 1
            except MKInternalError as e:
                errors.setdefault(method, []).append((user_id, e))

    message = escape_html_permissive(_("The notification has been sent via"))
    message += html.render_br()

    parts = []
    for method in msg["methods"]:
        parts.append(
            html.render_tr(
                html.render_td(_notify_methods()[method]["title"])
                + html.render_td(
                    _("to %d of %d recipients") % (num_success[method], num_recipients)
                )
            )
        )
    message += html.render_table(HTML().join(parts))

    message += html.render_p(_("Sent notification to: %s") % ", ".join(recipients))
    message += html.render_a(_("Back to previous page"), href=makeuri(request, []))
    html.show_message(message)

    if errors:
        error_message = HTML()
        for method, method_errors in errors.items():
            error_message += _("Failed to send %s notifications to the following users:") % method
            table_rows = HTML()
            for user_id, exception in method_errors:
                table_rows += html.render_tr(
                    html.render_td(html.render_tt(user_id)) + html.render_td(exception)
                )
            error_message += html.render_table(table_rows) + html.render_br()
        html.show_error(error_message)
Beispiel #5
0
def _process_message_message(msg):
    msg["id"] = utils.gen_id()
    msg["time"] = time.time()

    if isinstance(msg["dest"], str):
        dest_what = msg["dest"]
    else:
        dest_what = msg["dest"][0]

    if dest_what == "all_users":
        recipients = list(config.multisite_users.keys())
    elif dest_what == "online":
        recipients = userdb.get_online_user_ids()
    elif dest_what == "list":
        recipients = msg["dest"][1]
    else:
        recipients = []

    num_recipients = len(recipients)

    num_success: Dict[str, int] = {}
    for method in msg["methods"]:
        num_success[method] = 0

    # Now loop all messaging methods to send the messages
    errors: Dict[str, List[Tuple]] = {}
    for user_id in recipients:
        for method in msg["methods"]:
            try:
                handler = _messaging_methods()[method]["handler"]
                handler(user_id, msg)
                num_success[method] = num_success[method] + 1
            except MKInternalError as e:
                errors.setdefault(method, []).append((user_id, e))

    message = escape_html_permissive(
        _("The message has successfully been sent..."))
    message += html.render_br()

    parts = []
    for method in msg["methods"]:
        parts.append(
            html.render_li(
                _messaging_methods()[method]["confirmation_title"] +
                (_(" for all recipients.") if num_success[method] ==
                 num_recipients else _(" for %d of %d recipients.") %
                 (num_success[method], num_recipients))))

    message += html.render_ul(HTML().join(parts))
    message += html.render_p(_("Recipients: %s") % ", ".join(recipients))
    html.show_message(message)

    if errors:
        error_message = HTML()
        for method, method_errors in errors.items():
            error_message += _(
                "Failed to send %s messages to the following users:") % method
            table_rows = HTML()
            for user_id, exception in method_errors:
                table_rows += html.render_tr(
                    html.render_td(html.render_tt(user_id)) +
                    html.render_td(str(exception)))
            error_message += html.render_table(table_rows) + html.render_br()
        html.show_error(error_message)