Example #1
0
def show_log_list():
    title = _("All problematic logfiles")
    breadcrumb = make_simple_page_breadcrumb(
        mega_menu_registry.menu_monitoring(), title)
    html.header(title, breadcrumb, _log_list_page_menu(breadcrumb))

    if request.has_var("_ack") and not request.var("_do_actions") == _("No"):
        do_log_ack(site=None, host_name=None, file_name=None)
        return

    for site, host_name, logs in all_logs():
        if not logs:
            continue

        all_logs_empty = not any(
            parse_file(site, host_name, file_name) for file_name in logs)

        if all_logs_empty:
            continue  # Logfile vanished

        html.h3(
            html.render_a(
                host_name,
                href=makeuri(
                    request,
                    [("site", site), ("host", host_name)],
                ),
            ),
            class_="table",
        )
        list_logs(site, host_name, logs)
    html.footer()
Example #2
0
def show_log_list():
    title = _("All problematic logfiles")
    breadcrumb = make_simple_page_breadcrumb(
        mega_menu_registry.menu_monitoring(), title)
    html.header(title, breadcrumb, _log_list_page_menu(breadcrumb))

    if html.request.has_var(
            '_ack') and not html.request.var("_do_actions") == _("No"):
        do_log_ack(site=None, host_name=None, file_name=None)
        return

    for site, host_name, logs in all_logs():
        if not logs:
            continue

        all_logs_empty = not any(
            [parse_file(site, host_name, file_name) for file_name in logs])

        if all_logs_empty:
            continue  # Logfile vanished

        html.h2(
            html.render_a(host_name,
                          href=html.makeuri([('site', site),
                                             ('host', host_name)])))
        list_logs(site, host_name, logs)
    html.footer()
Example #3
0
def page_notify():
    if not user.may("general.notify"):
        raise MKAuthException(_("You are not allowed to use the notification module."))

    title = _("Notify users")
    breadcrumb = make_simple_page_breadcrumb(mega_menu_registry.menu_setup(), title)
    menu = _page_menu(breadcrumb)
    html.header(title, breadcrumb, menu)

    vs_notify = _vs_notify()

    if transactions.check_transaction():
        try:
            msg = vs_notify.from_html_vars("_notify")
            vs_notify.validate_value(msg, "_notify")
            _process_notify_message(msg)
        except MKUserError as e:
            html.user_error(e)

    html.begin_form("notify", method="POST")
    vs_notify.render_input_as_form("_notify", {})

    html.hidden_fields()
    html.end_form()
    html.footer()
Example #4
0
    def page(self) -> None:
        watolib.init_wato_datastructures(with_wato_lock=True)

        profile_changed = False
        if html.request.has_var('_save') and html.check_transaction():
            try:
                profile_changed = self._action()
            except MKUserError as e:
                html.add_user_error(e.varname, e)

        if profile_changed and config.user.authorized_login_sites():
            title = _('Replicate new user profile')
        else:
            title = self._page_title()

        breadcrumb = make_simple_page_breadcrumb(
            mega_menu_registry.menu_user(), title)
        html.header(title, breadcrumb, self._page_menu(breadcrumb))

        # Now, if in distributed environment where users can login to remote sites, set the trigger for
        # pushing the new user profile to the remote sites asynchronously
        if profile_changed and config.user.authorized_login_sites():
            user_profile_async_replication_page()
            return

        self._show_form(profile_changed)
Example #5
0
    def page(self) -> None:
        acktime = request.get_float_input_mandatory('acktime', time.time())
        if request.var('_confirm'):
            _acknowledge_failed_notifications(acktime, time.time())

            if user.authorized_login_sites():
                watolib.init_wato_datastructures(with_wato_lock=True)

                title = _('Replicate user profile')
                breadcrumb = make_simple_page_breadcrumb(
                    mega_menu_registry.menu_monitoring(), title)
                html.header(title, breadcrumb)

                for message in get_flashed_messages():
                    html.show_message(message)
                # This local import is needed for the moment
                import cmk.gui.wato.user_profile  # pylint: disable=redefined-outer-name
                cmk.gui.wato.user_profile.user_profile_async_replication_page(
                    back_url="clear_failed_notifications.py")
                return

        failed_notifications = load_failed_notifications(
            before=acktime, after=acknowledged_time())
        self._show_page(acktime, failed_notifications)
        if request.var('_confirm'):
            html.reload_whole_page()
Example #6
0
    def page(self) -> cmk.gui.pages.PageResult:
        breadcrumb = make_simple_page_breadcrumb(
            mega_menu_registry["help_links"], _("Info"))
        make_header(
            html,
            self._title(),
            breadcrumb=breadcrumb,
        )

        html.open_div(id_="info_title")
        html.h1(_("Your monitoring machine"))
        html.a(
            HTMLWriter.render_img(theme.url("images/tribe29.svg")),
            "https://tribe29.com",
            target="_blank",
        )
        html.close_div()

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

        html.open_div(id_="info_intro_text")
        html.span(_("Open. Effective. Awesome."))
        html.span(
            _("May we present? Monitoring as it's supposed to be: "
              "incredibly quick to install, infinetely scalable, highly customizable and "
              "designed for admins."))
        html.span(
            _("Visit our %s to learn more about Checkmk and about the %s.") % (
                HTMLWriter.render_a(
                    _("website"), "https://checkmk.com", target="_blank"),
                HTMLWriter.render_a(
                    _("latest version"),
                    "https://checkmk.com/product/latest-version",
                    target="_blank",
                ),
            ))
        html.close_div()

        version_major_minor = re.sub(r".\d+$", "",
                                     Version(__version__).version_base)
        if version_major_minor:
            current_version_link = "https://checkmk.com/product/checkmk-%s" % version_major_minor
        else:
            current_version_link = "https://checkmk.com/product/latest-version"

        html.open_div(id="info_image")
        html.open_a(href=current_version_link, target="_blank")
        html.img(theme.url("images/monitoring-machine.png"))
        html.close_a()
        html.close_div()

        html.close_div()

        html.open_div(id_="info_footer")
        html.span(
            _("© %s tribe29 GmbH. All Rights Reserved.") % time.strftime("%Y"))
        html.a(_("License agreement"),
               href="https://checkmk.com/legal.html",
               target="_blank")
        html.close_div()
Example #7
0
def page_add_snapin() -> None:
    if not config.user.may("general.configure_sidebar"):
        raise MKGeneralException(
            _("You are not allowed to change the sidebar."))

    title = _("Available snapins")
    breadcrumb = make_simple_page_breadcrumb(
        mega_menu_registry.menu_customize(), title)
    html.header(title, breadcrumb, _add_snapins_page_menu(breadcrumb))

    used_snapins = _used_snapins()

    html.open_div(class_=["add_snapin"])
    for name, snapin_class in sorted(snapin_registry.items()):
        if name in used_snapins:
            continue
        if not config.user.may(snapin_class.permission_name()):
            continue  # not allowed for this user

        html.open_div(class_="snapinadder",
                      onmouseover="this.style.cursor=\'pointer\';",
                      onclick="window.top.cmk.sidebar.add_snapin('%s')" % name)

        html.open_div(class_=["snapin_preview"])
        html.div('', class_=["clickshield"])
        SidebarRenderer().render_snapin(
            UserSidebarSnapin.from_snapin_type_id(name))
        html.close_div()
        html.div(snapin_class.description(), class_=["description"])
        html.close_div()

    html.close_div()
    html.footer()
Example #8
0
def page_notify():
    if not config.user.may("general.notify"):
        raise MKAuthException(
            _("You are not allowed to use the notification module."))

    title = _('Notify users')
    breadcrumb = make_simple_page_breadcrumb(mega_menu_registry.menu_setup(),
                                             title)
    html.header(title, breadcrumb)

    html.begin_context_buttons()
    html.context_button(_("Users"), "wato.py?mode=users", "back")
    html.end_context_buttons()

    vs_notify = _vs_notify()

    if html.check_transaction():
        try:
            msg = vs_notify.from_html_vars("_notify")
            vs_notify.validate_value(msg, "_notify")
            _process_notify_message(msg)
        except MKUserError as e:
            html.user_error(e)

    html.begin_form("notify", method="POST")
    vs_notify.render_input_as_form("_notify", {})

    html.button("save", _("Send notification"))

    html.hidden_fields()
    html.end_form()
    html.footer()
Example #9
0
 def _breadcrumb(self) -> Breadcrumb:
     breadcrumb = make_simple_page_breadcrumb(mega_menu_registry.menu_user(), self._page_title())
     breadcrumb.insert(
         -1,
         BreadcrumbItem(
             title=_("Two-factor authentication"),
             url="user_two_factor_overview.py",
         ),
     )
     return breadcrumb
Example #10
0
    def _show_page(self, acktime: float, failed_notifications: LivestatusResponse) -> None:
        title = _("Confirm failed notifications")
        breadcrumb = make_simple_page_breadcrumb(mega_menu_registry.menu_monitoring(), title)

        page_menu = self._page_menu(acktime, failed_notifications, breadcrumb)

        make_header(html, title, breadcrumb, page_menu)

        self._show_notification_table(failed_notifications)

        html.footer()
Example #11
0
 def show_topology(self,
                   hostnames: List[HostName],
                   mode: str,
                   growth_auto_max_nodes: Optional[int] = None,
                   mesh_depth: int = 0,
                   max_nodes: int = 400) -> None:
     breadcrumb = make_simple_page_breadcrumb(mega_menu_registry.menu_monitoring(), "")
     html.header("", breadcrumb)
     self.show_topology_content(hostnames,
                                mode,
                                growth_auto_max_nodes=growth_auto_max_nodes,
                                mesh_depth=mesh_depth,
                                max_nodes=max_nodes)
Example #12
0
    def page(self) -> None:
        title = _("Replicate user profile")
        breadcrumb = make_simple_page_breadcrumb(
            mega_menu_registry.menu_user(), title)
        html.header(title, breadcrumb, self._page_menu(breadcrumb))

        for message in get_flashed_messages():
            html.show_message(message)

        # Now, if in distributed environment where users can login to remote sites, set the trigger for
        # pushing the new user profile to the remote sites asynchronously
        user_profile_async_replication_page(
            back_url=request.get_url_input("back", "user_profile.py"))
Example #13
0
def _bi_map() -> None:
    aggr_name = html.request.var("aggr_name")
    layout_id = html.request.var("layout_id")
    title = _("BI visualization")
    breadcrumb = make_simple_page_breadcrumb(mega_menu_registry.menu_monitoring(), title)
    html.header(title, breadcrumb)
    div_id = "node_visualization"
    html.div("", id=div_id)
    html.javascript("node_instance = new cmk.node_visualization.BIVisualization(%s);" %
                    json.dumps(div_id))

    html.javascript("node_instance.show_aggregations(%s, %s)" %
                    (json.dumps([aggr_name]), json.dumps(layout_id)))
Example #14
0
    def page(self) -> None:
        title = self._page_title()
        breadcrumb = make_simple_page_breadcrumb(mega_menu_registry.menu_user(), title)
        html.header(title, breadcrumb, self._page_menu(breadcrumb))

        if request.has_var("_save") and transactions.check_transaction():
            try:
                self._action()
            except MKUserError as e:
                user_errors.add(e)

        for message in get_flashed_messages():
            html.show_message(message)

        html.show_user_errors()

        self._show_form()
Example #15
0
def render_page_confirm(acktime, failed_notifications):
    title = _("Confirm failed notifications")
    breadcrumb = make_simple_page_breadcrumb(
        mega_menu_registry.menu_monitoring(), title)

    confirm_url = make_confirm_link(
        url=html.makeactionuri_contextless([
            ("mode", "clear_failed_notifications"),
            ("acktime", str(acktime)),
            ("_confirm", "1"),
        ]),
        message=
        _("Do you really want to acknowledge all failed notifications up to %s?"
          ) % cmk.utils.render.date_and_time(acktime),
    )

    page_menu = PageMenu(
        dropdowns=[
            PageMenuDropdown(
                name="actions",
                title=_("Actions"),
                topics=[
                    PageMenuTopic(
                        title=_("Actions"),
                        entries=[
                            PageMenuEntry(
                                title=_("Confirm"),
                                icon_name="save",
                                item=make_javascript_link(confirm_url),
                                is_shortcut=True,
                                is_suggested=True,
                                is_enabled=failed_notifications,
                            ),
                        ],
                    ),
                ],
            ),
        ],
        breadcrumb=breadcrumb,
    )
    html.header(title, breadcrumb, page_menu)

    render_notification_table(failed_notifications)

    html.footer()
Example #16
0
def render_page_confirm(acktime, prev_url, failed_notifications):
    title = _("Confirm failed notifications")
    breadcrumb = make_simple_page_breadcrumb(mega_menu_registry.menu_monitoring(), title)
    html.header(title, breadcrumb)

    if failed_notifications:
        html.open_div(class_="really")
        html.write_text(
            _("Do you really want to acknowledge all failed notifications up to %s?") %
            cmk.utils.render.date_and_time(acktime))
        html.begin_form("confirm", method="GET", action=prev_url)
        html.hidden_field('acktime', acktime)
        html.button('_confirm', _("Yes"))
        html.end_form()
        html.close_div()

    render_notification_table(failed_notifications)

    html.footer()
Example #17
0
    def page(self):
        title = _("Crash report: %s") % self._crash_id
        breadcrumb = make_simple_page_breadcrumb(
            mega_menu_registry.menu_monitoring(), title)
        html.header(title, breadcrumb)
        row = self._get_crash_row()
        crash_info = self._get_crash_info(row)

        # Do not reveal crash context information to unauthenticated users or not permitted
        # users to prevent disclosure of internal information
        if not config.user.may("general.see_crash_reports"):
            html.show_error("<b>%s:</b> %s" %
                            (_("Internal error"), crash_info["exc_value"]))
            html.p(
                _("An internal error occurred while processing your request. "
                  "You can report this issue to your Checkmk administrator. "
                  "Detailed information can be found on the crash report page "
                  "or in <tt>var/log/web.log</tt>."))
            html.footer()
            return

        self._show_context_buttons(crash_info)

        if html.request.has_var("_report") and html.check_transaction():
            details = self._handle_report_form(crash_info)
        else:
            details = {}

        if crash_info["crash_type"] == "gui":
            html.show_error("<b>%s:</b> %s" %
                            (_("Internal error"), crash_info["exc_value"]))
            html.p(
                _("An internal error occured while processing your request. "
                  "You can report this issue to the Checkmk team to help "
                  "fixing this issue. Please use the form below for reporting."
                  ))

        self._warn_about_local_files(crash_info)
        self._show_report_form(crash_info, details)
        self._show_crash_report(crash_info)
        self._show_crash_report_details(crash_info, row)

        html.footer()
Example #18
0
    def page(self) -> None:
        watolib.init_wato_datastructures(with_wato_lock=True)

        title = self._page_title()
        breadcrumb = make_simple_page_breadcrumb(mega_menu_registry.menu_user(), title)
        html.header(title, breadcrumb, self._page_menu(breadcrumb))

        if html.request.has_var('_save') and html.check_transaction():
            try:
                self._action()
            except MKUserError as e:
                html.add_user_error(e.varname, e)

        for message in get_flashed_messages():
            html.show_message(message)

        if html.has_user_errors():
            html.show_user_errors()

        self._show_form()
Example #19
0
    def page(self) -> None:
        acktime = request.get_float_input_mandatory("acktime", time.time())
        if request.var("_confirm"):
            _acknowledge_failed_notifications(acktime, time.time())

            if user.authorized_login_sites():
                title = _("Replicate user profile")
                breadcrumb = make_simple_page_breadcrumb(
                    mega_menu_registry.menu_monitoring(), title
                )
                make_header(html, title, breadcrumb)

                for message in get_flashed_messages():
                    html.show_message(message)
                user_profile_async_replication_page(back_url="clear_failed_notifications.py")
                return

        failed_notifications = load_failed_notifications(before=acktime, after=acknowledged_time())
        self._show_page(acktime, failed_notifications)
        if request.var("_confirm"):
            html.reload_whole_page()
Example #20
0
    def page(self) -> cmk.gui.pages.PageResult:
        breadcrumb = make_simple_page_breadcrumb(mega_menu_registry["help_links"], self._title())

        load_werks()
        werk_table_options = _werk_table_options_from_request()

        html.header(
            self._title(),
            breadcrumb,
            self._page_menu(breadcrumb, werk_table_options),
        )

        for message in get_flashed_messages():
            html.show_message(message)

        handle_acknowledgement()

        html.open_div(class_="wato")
        render_werks_table(werk_table_options)
        html.close_div()

        html.footer()
Example #21
0
def show_log_list():
    title = _("All problematic logfiles")
    breadcrumb = make_simple_page_breadcrumb(mega_menu_registry.menu_monitoring(), title)
    html.header(title, breadcrumb)

    html.begin_context_buttons()
    html.context_button(_("Analyze Patterns"),
                        "%swato.py?mode=pattern_editor" % html.request.var('master_url', ''),
                        'analyze')
    ack_button()
    html.end_context_buttons()

    for site, host_name, logs in all_logs():
        if not logs:
            continue

        all_logs_empty = not any([parse_file(site, host_name, file_name) for file_name in logs])

        if all_logs_empty:
            continue  # Logfile vanished

        html.h2(html.render_a(host_name, href=html.makeuri([('site', site), ('host', host_name)])))
        list_logs(site, host_name, logs)
    html.footer()
Example #22
0
 def _breadcrumb(self) -> Breadcrumb:
     return make_simple_page_breadcrumb(mega_menu_registry.menu_user(),
                                        self._page_title())
Example #23
0
 def page(self) -> None:
     breadcrumb = make_simple_page_breadcrumb(
         mega_menu_registry.menu_user(), _("Messages"))
     html.header(self.title(), breadcrumb, self.page_menu(breadcrumb))
     render_user_message_table("gui_hint")
Example #24
0
def do_log_ack(site, host_name, file_name):
    logs_to_ack = []
    if not host_name and not file_name:  # all logs on all hosts
        for this_site, this_host, logs in all_logs():
            for int_filename in logs:
                file_display = form_file_to_ext(int_filename)
                logs_to_ack.append((this_site, this_host, int_filename, file_display))
        ack_msg = _('all logfiles on all hosts')

    elif host_name and not file_name:  # all logs on one host
        for int_filename in logfiles_of_host(site, host_name):
            file_display = form_file_to_ext(int_filename)
            logs_to_ack.append((site, host_name, int_filename, file_display))
        ack_msg = _('all logfiles of host %s') % host_name

    elif host_name and file_name:  # one log on one host
        int_filename = form_file_to_int(file_name)
        logs_to_ack = [(site, host_name, int_filename, form_file_to_ext(int_filename))]
        ack_msg = _('the log file %s on host %s') % (file_name, host_name)

    else:
        for this_site, this_host, logs in all_logs():
            file_display = form_file_to_ext(file_name)
            if file_name in logs:
                logs_to_ack.append((this_site, this_host, file_name, file_display))
        ack_msg = _('log file %s on all hosts') % file_name

    title = _("Acknowledge %s") % html.render_text(ack_msg)

    if host_name:
        breadcrumb = make_host_breadcrumb(host_name)
    else:
        breadcrumb = make_simple_page_breadcrumb(mega_menu_registry.menu_monitoring(), title)

    html.header(title, breadcrumb)

    html.begin_context_buttons()
    button_all_logfiles()
    if host_name:
        html.context_button(_("All Logfiles of Host"), html.makeuri([('file', '')]))
    if host_name and file_name:
        html.context_button(_("Back to Logfile"), html.makeuri([]))
    html.end_context_buttons()

    ack = html.request.var('_ack')
    if not html.confirm(
            _("Do you really want to acknowledge %s by <b>deleting</b> all stored messages?") %
            ack_msg):
        html.footer()
        return

    if not config.user.may("general.act"):
        html.h1(_('Permission denied'), class_=["error"])
        html.div(_('You are not allowed to acknowledge %s') % ack_msg, class_=["error"])
        html.footer()
        return

    # filter invalid values
    if ack != '1':
        raise MKUserError('_ack', _('Invalid value for ack parameter.'))

    for this_site, this_host, int_filename, display_name in logs_to_ack:
        try:
            acknowledge_logfile(this_site, this_host, int_filename, display_name)
        except Exception as e:
            html.show_error(
                _('The log file <tt>%s</tt> of host <tt>%s</tt> could not be deleted: %s.') %
                (display_name, this_host, e))
            html.footer()
            return

    html.show_message(
        '<b>%s</b><p>%s</p>' %
        (_('Acknowledged %s') % ack_msg, _('Acknowledged all messages in %s.') % ack_msg))
    html.footer()