Beispiel #1
0
    def _page_menu_entries_related(self) -> Iterator[PageMenuEntry]:
        if bakery.has_agent_bakery():
            yield PageMenuEntry(
                title=_("Windows, Linux, Solaris, AIX"),
                icon_name="agents",
                item=make_simple_link(
                    folder_preserving_link([("mode", "agents")])),
            )

        if self.name() != "download_agents_windows":
            yield PageMenuEntry(
                title=_("Windows files"),
                icon_name="download_agents",
                item=make_simple_link(
                    folder_preserving_link([("mode", "download_agents_windows")
                                            ])),
            )

        if self.name() != "download_agents_linux":
            yield PageMenuEntry(
                title=_("Linux, Solaris, AIX files"),
                icon_name="download_agents",
                item=make_simple_link(
                    folder_preserving_link([("mode", "download_agents_linux")
                                            ])),
            )

        if self.name() != "download_agents":
            yield PageMenuEntry(
                title=_("Other operating systems"),
                icon_name="download_agents",
                item=make_simple_link(
                    folder_preserving_link([("mode", "download_agents")])),
            )
Beispiel #2
0
    def page(self):
        with table_element() as table:
            for index, connection in enumerate(load_connection_config()):
                table.row()

                table.cell(_("Actions"), css=["buttons"])
                edit_url = folder_preserving_link([("mode",
                                                    "edit_ldap_connection"),
                                                   ("id", connection["id"])])
                delete_url = make_confirm_link(
                    url=make_action_link([("mode", "ldap_config"),
                                          ("_delete", index)]),
                    message=
                    _("Do you really want to delete the LDAP connection <b>%s</b>?"
                      ) % connection["id"],
                )
                drag_url = make_action_link([("mode", "ldap_config"),
                                             ("_move", index)])
                clone_url = folder_preserving_link([
                    ("mode", "edit_ldap_connection"),
                    ("clone", connection["id"])
                ])

                html.icon_button(edit_url, _("Edit this LDAP connection"),
                                 "edit")
                html.icon_button(clone_url,
                                 _("Create a copy of this LDAP connection"),
                                 "clone")
                html.element_dragger_url("tr", base_url=drag_url)
                html.icon_button(delete_url, _("Delete this LDAP connection"),
                                 "delete")

                table.cell("", css=["narrow"])
                if connection.get("disabled"):
                    html.icon(
                        "disabled",
                        _("This connection is currently not being used for synchronization."
                          ),
                    )
                else:
                    html.empty_icon_button()

                table.cell(_("ID"), connection["id"])

                if cmk_version.is_managed_edition():
                    table.cell(_("Customer"),
                               managed.get_customer_name(connection))

                table.cell(_("Description"))
                url = connection.get("docu_url")
                if url:
                    html.icon_button(
                        url,
                        _("Context information about this connection"),
                        "url",
                        target="_blank")
                    html.write_text("&nbsp;")
                html.write_text(connection["description"])
Beispiel #3
0
 def page_menu(self, breadcrumb: Breadcrumb) -> PageMenu:
     return PageMenu(
         dropdowns=[
             PageMenuDropdown(
                 name="tags",
                 title=_("Tags"),
                 topics=[
                     PageMenuTopic(
                         title=_("Add tags"),
                         entries=[
                             PageMenuEntry(
                                 title=_("Add tag group"),
                                 icon_name="new",
                                 item=make_simple_link(
                                     folder_preserving_link([
                                         ("mode", "edit_tag")
                                     ])),
                                 is_shortcut=True,
                                 is_suggested=True,
                             ),
                             PageMenuEntry(
                                 title=_("Add aux tag"),
                                 icon_name={
                                     "icon": "tag",
                                     "emblem": "add"
                                 },
                                 item=make_simple_link(
                                     folder_preserving_link([
                                         ("mode", "edit_auxtag")
                                     ])),
                                 is_shortcut=True,
                                 is_suggested=True,
                             ),
                         ],
                     ),
                     PageMenuTopic(
                         title=_("Analyze"),
                         entries=[
                             PageMenuEntry(
                                 title=_("Tag usage"),
                                 icon_name={
                                     "icon": "tag",
                                     "emblem": "search",
                                 },
                                 item=make_simple_link(
                                     folder_preserving_link([
                                         ("mode", "tag_usage")
                                     ])),
                             ),
                         ],
                     ),
                 ],
             ),
         ],
         breadcrumb=breadcrumb,
     )
Beispiel #4
0
    def page(self):
        with table_element("roles") as table:

            users = userdb.load_users()
            for rid, role in sorted(self._roles.items(), key=lambda a: (a[1]["alias"], a[0])):
                table.row()

                # Actions
                table.cell(_("Actions"), css=["buttons"])
                edit_url = folder_preserving_link([("mode", "edit_role"), ("edit", rid)])
                clone_url = make_action_link([("mode", "roles"), ("_clone", rid)])
                delete_url = make_confirm_link(
                    url=make_action_link([("mode", "roles"), ("_delete", rid)]),
                    message=_("Do you really want to delete the role %s?") % rid,
                )
                html.icon_button(edit_url, _("Properties"), "edit")
                html.icon_button(clone_url, _("Clone"), "clone")
                if not role.get("builtin"):
                    html.icon_button(delete_url, _("Delete this role"), "delete")

                # ID
                table.cell(_("Name"), rid)

                # Alias
                table.cell(_("Alias"), role["alias"])

                # Type
                table.cell(_("Type"), _("builtin") if role.get("builtin") else _("custom"))

                # Modifications
                table.cell(
                    _("Modifications"),
                    HTMLWriter.render_span(
                        str(len(role["permissions"])),
                        title=_("That many permissions do not use the factory defaults."),
                    ),
                )

                # Users
                table.cell(
                    _("Users"),
                    HTML(", ").join(
                        [
                            HTMLWriter.render_a(
                                user.get("alias", user_id),
                                folder_preserving_link([("mode", "edit_user"), ("edit", user_id)]),
                            )
                            for (user_id, user) in users.items()
                            if rid in user["roles"]
                        ]
                    ),
                )
Beispiel #5
0
 def _page_menu_entries_related(self) -> Iterator[PageMenuEntry]:
     yield PageMenuEntry(
         title=_("Host groups"),
         icon_name="hostgroups",
         item=make_simple_link(
             folder_preserving_link([("mode", "host_groups")])),
     )
Beispiel #6
0
    def _show_tag_icons(self, tag_group, nr):
        # Tag groups were made builtin with ~1.4. Previously users could modify
        # these groups.  These users now have the modified tag groups in their
        # user configuration and should be able to cleanup this using the GUI
        # for the moment. Make the buttons available to the users.
        if self._builtin_config.tag_group_exists(
                tag_group.id) and not self._tag_config.tag_group_exists(
                    tag_group.id):
            html.i("(%s)" % _("builtin"))
            return

        edit_url = folder_preserving_link([("mode", "edit_tag"),
                                           ("edit", tag_group.id)])
        html.icon_button(edit_url, _("Edit this tag group"), "edit")

        html.element_dragger_url("tr",
                                 base_url=make_action_link([("mode", "tags"),
                                                            ("_move", nr)]))

        delete_url = make_confirm_link(
            url=make_action_link([("mode", "tags"),
                                  ("_delete", tag_group.id)]),
            message=_("Do you really want to delete the tag group '%s'?") %
            tag_group.id,
        )
        html.icon_button(delete_url, _("Delete this tag group"), "delete")
Beispiel #7
0
 def _find_usages_in_time_specific_parameters(
         self, tpname: str) -> List[TimeperiodUsage]:
     used_in: List[TimeperiodUsage] = []
     rulesets = AllRulesets()
     rulesets.load()
     for ruleset in rulesets.get_rulesets().values():
         vs = ruleset.valuespec()
         if not isinstance(vs,
                           cmk.gui.plugins.wato.utils.TimeperiodValuespec):
             continue
         for rule_folder, rule_index, rule in ruleset.get_rules():
             if not vs.is_active(rule.value):
                 continue
             for index, (rule_tp_name,
                         _value) in enumerate(rule.value["tp_values"]):
                 if rule_tp_name != tpname:
                     continue
                 edit_url = folder_preserving_link([
                     ("mode", "edit_rule"),
                     ("back_mode", "timeperiods"),
                     ("varname", ruleset.name),
                     ("rulenr", rule_index),
                     ("rule_folder", rule_folder.path()),
                 ])
                 used_in.append(
                     (_("Time specific check parameter #%d") % (index + 1),
                      edit_url))
     return used_in
Beispiel #8
0
 def _page_menu_entries_setup(self) -> Iterator[PageMenuEntry]:
     if user.may("wato.sites"):
         yield PageMenuEntry(
             title=_("View changes"),
             icon_name="activate",
             item=make_simple_link(folder_preserving_link([("mode", "changelog")])),
         )
Beispiel #9
0
 def page_menu(self, breadcrumb: Breadcrumb) -> PageMenu:
     menu = PageMenu(
         dropdowns=[
             PageMenuDropdown(
                 name="roles",
                 title=_("Roles"),
                 topics=[
                     PageMenuTopic(
                         title=_("Overview"),
                         entries=[
                             PageMenuEntry(
                                 title=_("Permission matrix"),
                                 icon_name="matrix",
                                 item=make_simple_link(
                                     folder_preserving_link([("mode", "role_matrix")])
                                 ),
                             ),
                         ],
                     ),
                 ],
             ),
         ],
         breadcrumb=breadcrumb,
         inpage_search=PageMenuSearch(),
     )
     return menu
Beispiel #10
0
    def _show_aux_tag_icons(self, aux_tag: cmk.utils.tags.AuxTag) -> None:
        if aux_tag.id in self._builtin_config.aux_tag_list.get_tag_ids():
            html.i("(%s)" % _("builtin"))
            return

        edit_url = folder_preserving_link([("mode", "edit_auxtag"),
                                           ("edit", aux_tag.id)])
        html.icon_button(edit_url, _("Edit this auxiliary tag"), "edit")
Beispiel #11
0
def find_usages_of_contact_group(name):
    # Part 1: Rules
    used_in = _find_usages_of_group_in_rules(
        name, ['host_contactgroups', 'service_contactgroups'])

    # Is the contactgroup assigned to a user?
    users = userdb.load_users()
    entries = users.items()
    for userid, user in sorted(entries, key=lambda x: x[1].get("alias", x[0])):
        cgs = user.get("contactgroups", [])
        if name in cgs:
            used_in.append(('%s: %s' % (_('User'), user.get('alias', userid)),
                            folder_preserving_link([('mode', 'edit_user'),
                                                    ('edit', userid)])))

    global_config = load_configuration_settings()

    # Used in default_user_profile?
    config_variable = config_variable_registry['default_user_profile']()
    domain = config_variable.domain()
    configured = global_config.get('default_user_profile', {})
    default_value = domain().default_globals()["default_user_profile"]
    if (configured and name in configured['contactgroups']) \
       or name in  default_value['contactgroups']:
        used_in.append(
            ('%s' % (_('Default User Profile')),
             folder_preserving_link([('mode', 'edit_configvar'),
                                     ('varname', 'default_user_profile')])))

    # Is the contactgroup used in mkeventd notify (if available)?
    if 'mkeventd_notify_contactgroup' in config_variable_registry:
        config_variable = config_variable_registry[
            'mkeventd_notify_contactgroup']()
        domain = config_variable.domain()
        configured = global_config.get('mkeventd_notify_contactgroup')
        default_value = domain().default_globals(
        )["mkeventd_notify_contactgroup"]
        if (configured and name == configured) \
           or name == default_value:
            used_in.append(('%s' % (config_variable.valuespec().title()),
                            folder_preserving_link([
                                ('mode', 'edit_configvar'),
                                ('varname', 'mkeventd_notify_contactgroup')
                            ])))

    return used_in
Beispiel #12
0
def _find_usages_of_contact_group_in_users(name):
    """Is the contactgroup assigned to a user?"""
    used_in = []
    users = userdb.load_users()
    for userid, user in sorted(users.items(), key=lambda x: x[1].get("alias", x[0])):
        cgs = user.get("contactgroups", [])
        if name in cgs:
            used_in.append(('%s: %s' % (_('User'), user.get('alias', userid)),
                            folder_preserving_link([('mode', 'edit_user'), ('edit', userid)])))
    return used_in
Beispiel #13
0
    def _show_row_cells(self, table: Table, name: GroupName,
                        group: GroupSpec) -> None:
        table.cell(_("Actions"), css=["buttons"])
        edit_url = folder_preserving_link([("mode",
                                            "edit_%s_group" % self.type_name),
                                           ("edit", name)])
        delete_url = make_confirm_link(
            url=makeactionuri(request, transactions, [("_delete", name)]),
            message=_('Do you really want to delete the %s group "%s"?') %
            (self.type_name, name),
        )
        clone_url = folder_preserving_link([("mode",
                                             "edit_%s_group" % self.type_name),
                                            ("clone", name)])
        html.icon_button(edit_url, _("Properties"), "edit")
        html.icon_button(clone_url, _("Create a copy of this group"), "clone")
        html.icon_button(delete_url, _("Delete"), "delete")

        table.cell(_("Name"), name)
        table.cell(_("Alias"), group["alias"])
Beispiel #14
0
def _show_affected_rulesets(affected_rulesets: List[Ruleset]) -> None:
    html.open_ul()
    for ruleset in affected_rulesets:
        html.open_li()
        html.a(
            ruleset.title(),
            href=folder_preserving_link([("mode", "edit_ruleset"),
                                         ("varname", ruleset.name)]),
        )
        html.close_li()
    html.close_ul()
Beispiel #15
0
 def _show_row_cells(self, table: Table, name: GroupName,
                     group: GroupSpec) -> None:
     super()._show_row_cells(table, name, group)
     table.cell(_("Members"))
     html.write_html(
         HTML(", ").join([
             HTMLWriter.render_a(
                 alias,
                 href=folder_preserving_link([("mode", "edit_user"),
                                              ("edit", userid)]),
             ) for userid, alias in self._members.get(name, [])
         ]))
Beispiel #16
0
    def _action_buttons(self, name):
        edit_url = folder_preserving_link([
            ("mode", "edit_timeperiod"),
            ("edit", name),
        ])
        clone_url = folder_preserving_link([
            ("mode", "edit_timeperiod"),
            ("clone", name),
        ])
        delete_url = make_confirm_link(
            url=make_action_link([
                ("mode", "timeperiods"),
                ("_delete", name),
            ]),
            message=_("Do you really want to delete the time period '%s'?") %
            name,
        )

        html.icon_button(edit_url, _("Properties"), "edit")
        html.icon_button(clone_url, _("Create a copy"), "clone")
        html.icon_button(delete_url, _("Delete"), "delete")
Beispiel #17
0
def _find_usages_of_group_in_rules(name, varnames):
    used_in = []
    rulesets = AllRulesets()
    rulesets.load()
    for varname in varnames:
        ruleset = rulesets.get(varname)
        for _folder, _rulenr, rule in ruleset.get_rules():
            if rule.value == name:
                used_in.append(("%s: %s" % (_("Ruleset"), ruleset.title()),
                                folder_preserving_link([("mode", "edit_ruleset"),
                                                        ("varname", varname)])))
    return used_in
Beispiel #18
0
 def _find_usages_in_other_timeperiods(
         self, tpname: str) -> List[TimeperiodUsage]:
     used_in: List[TimeperiodUsage] = []
     for tpn, tp in watolib.timeperiods.load_timeperiods().items():
         if tpname in tp.get("exclude", []):
             used_in.append((
                 "%s: %s (%s)" %
                 (_("Timeperiod"), timeperiod_spec_alias(
                     tp, tpn), _("excluded")),
                 folder_preserving_link([("mode", "edit_timeperiod"),
                                         ("edit", tpn)]),
             ))
     return used_in
Beispiel #19
0
 def _find_usages_in_ec_rules(self, tpname: str) -> List[TimeperiodUsage]:
     used_in: List[TimeperiodUsage] = []
     rule_packs = mkeventdstore.load_mkeventd_rules()
     for rule_pack in rule_packs:
         for rule_index, rule in enumerate(rule_pack["rules"]):
             if rule.get("match_timeperiod") == tpname:
                 url = folder_preserving_link([
                     ("mode", "mkeventd_edit_rule"),
                     ("edit", rule_index),
                     ("rule_pack", rule_pack["id"]),
                 ])
                 used_in.append((_("Event console rule"), url))
     return used_in
Beispiel #20
0
def _find_usages_of_contact_group_in_default_user_profile(name, global_config):
    """Used in default_user_profile?"""
    used_in = []
    config_variable = config_variable_registry['default_user_profile']()
    domain = config_variable.domain()
    configured = global_config.get('default_user_profile', {})
    default_value = domain().default_globals()["default_user_profile"]
    if (configured and name in configured['contactgroups']) \
       or name in  default_value['contactgroups']:
        used_in.append(('%s' % (_('Default User Profile')),
                        folder_preserving_link([('mode', 'edit_configvar'),
                                                ('varname', 'default_user_profile')])))
    return used_in
Beispiel #21
0
 def page_menu(self, breadcrumb: Breadcrumb) -> PageMenu:
     return PageMenu(
         dropdowns=[
             PageMenuDropdown(
                 name="groups",
                 title=self.title(),
                 topics=[
                     PageMenuTopic(
                         title=_("Add"),
                         entries=[
                             PageMenuEntry(
                                 title=_("Add group"),
                                 icon_name="new",
                                 item=make_simple_link(
                                     folder_preserving_link([
                                         ("mode",
                                          "edit_%s_group" % self.type_name)
                                     ])),
                                 is_shortcut=True,
                                 is_suggested=True,
                             ),
                         ],
                     ),
                     PageMenuTopic(
                         title=_("Assign to group"),
                         entries=[
                             PageMenuEntry(
                                 title=_("Rules"),
                                 icon_name="rulesets",
                                 item=make_simple_link(self._rules_url()),
                                 is_shortcut=True,
                                 is_suggested=True,
                             ),
                         ],
                     ),
                 ],
             ),
             PageMenuDropdown(
                 name="related",
                 title=_("Related"),
                 topics=[
                     PageMenuTopic(
                         title=_("Setup"),
                         entries=list(self._page_menu_entries_related()),
                     ),
                 ],
             ),
         ],
         breadcrumb=breadcrumb,
         inpage_search=PageMenuSearch(),
     )
Beispiel #22
0
 def page_menu(self, breadcrumb: Breadcrumb) -> PageMenu:
     return PageMenu(
         dropdowns=[
             PageMenuDropdown(
                 name="timeperiods",
                 title=_("Time periods"),
                 topics=[
                     PageMenuTopic(
                         title=_("Add time period"),
                         entries=[
                             PageMenuEntry(
                                 title=_("Add time period"),
                                 icon_name="new",
                                 item=make_simple_link(
                                     folder_preserving_link([
                                         ("mode", "edit_timeperiod")
                                     ])),
                                 is_shortcut=True,
                                 is_suggested=True,
                             ),
                             PageMenuEntry(
                                 title=_("Import iCalendar"),
                                 icon_name="ical",
                                 item=make_simple_link(
                                     folder_preserving_link([
                                         ("mode", "import_ical")
                                     ])),
                                 is_shortcut=True,
                                 is_suggested=True,
                             ),
                         ],
                     ),
                 ],
             ),
         ],
         breadcrumb=breadcrumb,
         inpage_search=PageMenuSearch(),
     )
Beispiel #23
0
 def _find_usages_in_alert_handler_rules(
         self, tpname: str) -> List[TimeperiodUsage]:
     used_in: List[TimeperiodUsage] = []
     if cmk_version.is_raw_edition():
         return used_in
     for index, rule in enumerate(
             alert_handling.load_alert_handler_rules()):
         if rule.get("match_timeperiod") == tpname:
             url = folder_preserving_link([
                 ("mode", "alert_handler_rule"),
                 ("edit", index),
             ])
             used_in.append((_("Alert handler rule"), url))
     return used_in
Beispiel #24
0
    def _show_aux_tag_icons(self, aux_tag: cmk.utils.tags.AuxTag) -> None:
        if aux_tag.id in self._builtin_config.aux_tag_list.get_tag_ids():
            html.i("(%s)" % _("builtin"))
            return

        edit_url = folder_preserving_link([("mode", "edit_auxtag"),
                                           ("edit", aux_tag.id)])
        delete_url = make_confirm_link(
            url=make_action_link([("mode", "tags"), ("_del_aux", aux_tag.id)]),
            message=_("Do you really want to delete the auxiliary tag '%s'?") %
            aux_tag.id,
        )
        html.icon_button(edit_url, _("Edit this auxiliary tag"), "edit")
        html.icon_button(delete_url, _("Delete this auxiliary tag"), "delete")
Beispiel #25
0
 def rule_url(rule: Rule) -> str:
     return folder_preserving_link([
         ("mode", "edit_rule"),
         ("varname", varname),
         ("rule_folder", rule.folder.path()),
         ("rule_id", rule.id),
         ("host", self._hostname),
         (
             "item",
             mk_repr(svc_desc_or_item).decode()
             if svc_desc_or_item else "",
         ),
         ("service", mk_repr(svc_desc).decode() if svc_desc else ""),
     ])
Beispiel #26
0
def _find_usages_of_contact_group_in_users(name: GroupName) -> List[Tuple[str, str]]:
    """Is the contactgroup assigned to a user?"""
    used_in = []
    users = userdb.load_users()
    for userid, user_spec in sorted(users.items(), key=lambda x: x[1].get("alias", x[0])):
        cgs = user_spec.get("contactgroups", [])
        if name in cgs:
            used_in.append(
                (
                    "%s: %s" % (_("User"), user_spec.get("alias", userid)),
                    folder_preserving_link([("mode", "edit_user"), ("edit", userid)]),
                )
            )
    return used_in
Beispiel #27
0
def _find_usages_of_contact_group_in_mkeventd_notify_contactgroup(name, global_config):
    """Is the contactgroup used in mkeventd notify (if available)?"""
    used_in = []
    if 'mkeventd_notify_contactgroup' in config_variable_registry:
        config_variable = config_variable_registry['mkeventd_notify_contactgroup']()
        domain = config_variable.domain()
        configured = global_config.get('mkeventd_notify_contactgroup')
        default_value = domain().default_globals()["mkeventd_notify_contactgroup"]
        if (configured and name == configured) \
           or name == default_value:
            used_in.append(('%s' % (config_variable.valuespec().title()),
                            folder_preserving_link([('mode', 'edit_configvar'),
                                                    ('varname', 'mkeventd_notify_contactgroup')])))
    return used_in
Beispiel #28
0
    def _find_usages_in_users(self, tpname: str) -> List[TimeperiodUsage]:
        used_in: List[TimeperiodUsage] = []
        for userid, user in userdb.load_users().items():
            tp = user.get("notification_period")
            if tp == tpname:
                used_in.append((
                    "%s: %s" % (_("User"), userid),
                    folder_preserving_link([("mode", "edit_user"),
                                            ("edit", userid)]),
                ))

            for index, rule in enumerate(user.get("notification_rules", [])):
                used_in += self._find_usages_in_notification_rule(
                    tpname, index, rule, user_id=userid)
        return used_in
Beispiel #29
0
    def _show_tag_group_icons(self,
                              tag_group: cmk.utils.tags.TagGroup) -> None:
        # Tag groups were made builtin with ~1.4. Previously users could modify
        # these groups.  These users now have the modified tag groups in their
        # user configuration and should be able to cleanup this using the GUI
        # for the moment. Make the buttons available to the users.
        if self._builtin_config.tag_group_exists(
                tag_group.id) and not self._tag_config.tag_group_exists(
                    tag_group.id):
            html.i("(%s)" % _("builtin"))
            return

        edit_url = folder_preserving_link([("mode", "edit_tag"),
                                           ("edit", tag_group.id)])
        html.icon_button(edit_url, _("Edit this tag group"), "edit")
Beispiel #30
0
def _find_usages_of_contact_group_in_default_user_profile(
        name: GroupName,
        global_config: GlobalSettings) -> List[Tuple[str, str]]:
    """Used in default_user_profile?"""
    used_in = []
    config_variable = config_variable_registry["default_user_profile"]()
    domain = config_variable.domain()
    configured = global_config.get("default_user_profile", {})
    default_value = domain().default_globals()["default_user_profile"]
    if (configured and name in configured["contactgroups"]
        ) or name in default_value["contactgroups"]:
        used_in.append((
            "%s" % (_("Default User Profile")),
            folder_preserving_link([("mode", "edit_configvar"),
                                    ("varname", "default_user_profile")]),
        ))
    return used_in