def _show_backup_codes(self, backup_codes: Sequence[str]) -> None: forms.header(_("Backup codes")) forms.section(_("Backup codes"), simple=True) if backup_codes: html.p( _("You have %d unused backup codes left.") % len(backup_codes)) html.i( _("If you regenerate backup codes, you automatically invalidate old codes." )) else: html.i(_("No backup codes created yet.")) forms.end()
def _show_webauthn_credentials( self, webauthn_credentials: dict[str, WebAuthnCredential] ) -> None: html.div("", id_="webauthn_message") forms.header(_("WebAuthn credentials")) forms.section(_("Registered credentials"), simple=True) if webauthn_credentials: self._show_credentials(webauthn_credentials) else: html.i(_("No credentials registered")) forms.end()
def _show_extra_page_elements(self): super(ModeEditContactgroup, self)._show_extra_page_elements() forms.header(_("Permissions")) forms.section(_("Permitted HW/SW inventory paths")) self._vs_inventory_paths().render_input( 'inventory_paths', self.group.get('inventory_paths')) if self._get_nagvis_maps(): forms.section(_("Access to NagVis Maps")) html.help(_("Configure access permissions to NagVis maps.")) self._vs_nagvis_maps().render_input( 'nagvis_maps', self.group.get('nagvis_maps', []))
def _show_extra_page_elements(self) -> None: super()._show_extra_page_elements() forms.header(_("Permissions")) forms.section(_("Permitted HW/SW inventory paths")) self._vs_inventory_paths_and_keys().render_input( "inventory_paths", self.group.get("inventory_paths")) if self._get_nagvis_maps(): forms.section(_("Access to NagVis Maps")) html.help(_("Configure access permissions to NagVis maps.")) self._vs_nagvis_maps().render_input( "nagvis_maps", self.group.get("nagvis_maps", []))
def _show_host_info(self): host_info = analyse_host( self._host.site_id(), self._hostname, ) if not host_info: return forms.header(_("Host information"), isopen=True, narrow=True, css="rulesettings") self._show_labels(host_info.labels, "host", host_info.label_sources)
def _show_host_info(self): host_info = watolib.check_mk_automation(self._host.site_id(), "analyse-host", [self._hostname]) if not host_info: return forms.header(_("Host information"), isopen=True, narrow=True, css="rulesettings") self._show_labels(host_info["labels"], "host", host_info["label_sources"])
def _show_form(self, profile_changed: bool) -> None: assert config.user.id is not None users = userdb.load_users() if profile_changed: flash(_("Successfully updated user profile.")) # Ensure theme changes are applied without additional user interaction html.reload_whole_page() if html.has_user_errors(): html.show_user_errors() user = users.get(config.user.id) if user is None: html.show_warning(_("Sorry, your user account does not exist.")) html.footer() return html.begin_form("profile", method="POST") html.prevent_password_auto_completion() html.open_div(class_="wato") forms.header(_("Personal settings")) forms.section(_("Name"), simple=True) html.write_text(user.get("alias", config.user.id)) select_language(user) # Let the user configure how he wants to be notified rulebased_notifications = rulebased_notifications_enabled() if (not rulebased_notifications and config.user.may('general.edit_notifications') and user.get("notifications_enabled")): forms.section(_("Notifications")) html.help( _("Here you can configure how you want to be notified about host and service problems and " "other monitoring events.")) watolib.get_vs_flexible_notifications().render_input("notification_method", user.get("notification_method")) if config.user.may('general.edit_user_attributes'): custom_user_attr_topics = get_user_attributes_by_topic() _show_custom_user_attr(user, custom_user_attr_topics.get("personal", [])) forms.header(_("User interface settings")) _show_custom_user_attr(user, custom_user_attr_topics.get("interface", [])) forms.end() html.close_div() html.hidden_fields() html.end_form() html.footer()
def page(self): html.open_div(class_="diag_host") html.open_table() html.open_tr() html.open_td() html.begin_form('diag_host', method="POST") html.prevent_password_auto_completion() forms.header(_('Host Properties')) forms.section(legend=False) # The diagnose page shows both snmp variants at the same time # We need to analyse the preconfigured community and set either the # snmp_community or the snmp_v3_credentials vs_dict = {} for key, value in self._host.attributes().items(): if key == "snmp_community" and isinstance(value, tuple): vs_dict["snmp_v3_credentials"] = value continue vs_dict[key] = value vs_host = self._vs_host() vs_host.render_input("vs_host", vs_dict) html.help(vs_host.help()) forms.end() html.open_div(style="margin-bottom:10px") html.button("_save", _("Save & Exit")) html.close_div() forms.header(_('Options')) value = {} forms.section(legend=False) vs_rules = self._vs_rules() vs_rules.render_input("vs_rules", value) html.help(vs_rules.help()) forms.end() html.button("_try", _("Test")) html.hidden_fields() html.end_form() html.close_td() html.open_td(style="padding-left:10px;") self._show_diagnose_output()
def _activation_form(self): if not config.user.may("wato.activate"): html.show_warning( _("You are not permitted to activate configuration changes.")) return if not self._changes: return if not config.user.may("wato.activateforeign") \ and self._has_foreign_changes_on_any_site(): html.show_warning( _("Sorry, you are not allowed to activate changes of other users." )) return valuespec = _vs_activation(self.title(), self.has_foreign_changes()) html.begin_form("activate", method="POST", action="") html.hidden_field("activate_until", self._get_last_change_id(), id_="activate_until") if valuespec: title = valuespec.title() assert title is not None forms.header(title) valuespec.render_input("activate", self._value) valuespec.set_focus("activate") html.help(valuespec.help()) if self.has_foreign_changes(): if config.user.may("wato.activateforeign"): html.show_warning( _("There are some changes made by your colleagues that you will " "activate if you proceed. You need to enable the checkbox above " "to confirm the activation of these changes.")) else: html.show_warning( _("There are some changes made by your colleagues that you can not " "activate because you are not permitted to. You can only activate " "the changes on the sites that are not affected by these changes. " "<br>" "If you need to activate your changes on all sites, please contact " "a permitted user to do it for you.")) forms.end() html.hidden_field("selection_id", weblib.selection_id()) html.hidden_fields() html.end_form() init_rowselect(self.name())
def _show_form(self) -> None: assert user.id is not None users = userdb.load_users() change_reason = request.get_ascii_input("reason") if change_reason == "expired": html.p( _("Your password is too old, you need to choose a new password." )) elif change_reason == "enforced": html.p( _("You are required to change your password before proceeding." )) user_spec = users.get(user.id) if user_spec is None: html.show_warning(_("Sorry, your user account does not exist.")) html.footer() return locked_attributes = userdb.locked_attributes( user_spec.get("connector")) if "password" in locked_attributes: raise MKUserError( "cur_password", _("You can not change your password, because it is " "managed by another system."), ) html.begin_form("profile", method="POST") html.prevent_password_auto_completion() html.open_div(class_="wato") forms.header(self._page_title()) forms.section(_("Current Password")) html.password_input("cur_password", autocomplete="new-password") forms.section(_("New Password")) html.password_input("password", autocomplete="new-password") forms.section(_("New Password Confirmation")) html.password_input("password2", autocomplete="new-password") forms.end() html.close_div() html.hidden_fields() html.end_form() html.footer()
def page(self): hosts = get_hosts_from_checkboxes() html.p( _("You have selected <b>%d</b> hosts for bulk cleanup. This means removing " "explicit attribute values from hosts. The hosts will then inherit attributes " "configured at the host list or folders or simply fall back to the builtin " "default values.") % len(hosts)) html.begin_form("bulkcleanup", method="POST") forms.header(_("Attributes to remove from hosts")) self._select_attributes_for_bulk_cleanup(hosts) html.hidden_fields() html.end_form()
def _show_form(self) -> None: assert user.id is not None users = userdb.load_users() user_spec: Optional[UserSpec] = users.get(user.id) if user_spec is None: html.show_warning(_("Sorry, your user account does not exist.")) html.footer() return html.begin_form("profile", method="POST") html.prevent_password_auto_completion() html.open_div(class_="wato") forms.header(_("Personal settings")) forms.section(_("Name"), simple=True) html.write_text(user_spec.get("alias", user.id)) select_language(user_spec) # Let the user configure how he wants to be notified rulebased_notifications = rulebased_notifications_enabled() if ( not rulebased_notifications and user.may("general.edit_notifications") and user_spec.get("notifications_enabled") ): forms.section(_("Notifications")) html.help( _( "Here you can configure how you want to be notified about host and service problems and " "other monitoring events." ) ) watolib.get_vs_flexible_notifications().render_input( "notification_method", user_spec.get("notification_method") ) if user.may("general.edit_user_attributes"): custom_user_attr_topics = get_user_attributes_by_topic() _show_custom_user_attr(user_spec, custom_user_attr_topics.get("personal", [])) forms.header(_("User interface settings")) _show_custom_user_attr(user_spec, custom_user_attr_topics.get("interface", [])) forms.end() html.close_div() html.hidden_fields() html.end_form() html.footer()
def _activation_form(self): if not config.user.may("wato.activate"): html.show_warning(_("You are not permitted to activate configuration changes.")) return if not self._changes: html.show_info(_("Currently there are no changes to activate.")) return if not config.user.may("wato.activateforeign") \ and self._has_foreign_changes_on_any_site(): html.show_warning(_("Sorry, you are not allowed to activate changes of other users.")) return valuespec = self._vs_activation() html.begin_form("activate", method="POST", action="") html.hidden_field("activate_until", self._get_last_change_id(), id_="activate_until") forms.header(valuespec.title()) valuespec.render_input("activate", self._value) valuespec.set_focus("activate") html.help(valuespec.help()) if self.has_foreign_changes(): if config.user.may("wato.activateforeign"): html.show_warning( _("There are some changes made by your colleagues that you will " "activate if you proceed. You need to enable the checkbox above " "to confirm the activation of these changes.")) else: html.show_warning( _("There are some changes made by your colleagues that you can not " "activate because you are not permitted to. You can only activate " "the changes on the sites that are not affected by these changes. " "<br>" "If you need to activate your changes on all sites, please contact " "a permitted user to do it for you.")) forms.end() html.jsbutton( "activate_affected", _("Activate affected"), "cmk.activation.activate_changes(\"affected\")", cssclass="hot") html.jsbutton("activate_selected", _("Activate selected"), "cmk.activation.activate_changes(\"selected\")") html.hidden_fields() html.end_form()
def page(self): # TODO: remove subclass specific things specifict things (everything with _type == 'user') html.begin_form("attr") forms.header(_("Properties")) forms.section(_("Name"), simple=not self._new, is_required=True) html.help( _( "The name of the attribute is used as an internal key. It cannot be " "changed later." ) ) if self._new: html.text_input("name", self._attr.get("name", "")) html.set_focus("name") else: html.write_text(self._name) html.set_focus("title") forms.section(_("Title") + "<sup>*</sup>", is_required=True) html.help(_("The title is used to label this attribute.")) html.text_input("title", self._attr.get("title", "")) forms.section(_("Topic")) html.help(_("The attribute is added to this section in the edit dialog.")) html.dropdown("topic", self._topics, deflt=self._attr.get("topic", self._default_topic)) forms.section(_("Help Text") + "<sup>*</sup>") html.help(_("You might want to add some helpful description for the attribute.")) html.text_area("help", self._attr.get("help", "")) forms.section(_("Data type")) html.help(_("The type of information to be stored in this attribute.")) if self._new: html.dropdown("type", custom_attr_types(), deflt=self._attr.get("type", "")) else: html.write_text(dict(custom_attr_types())[self._attr.get("type")]) self._add_extra_form_sections() self._show_in_table_option() forms.section(_("Add to monitoring configuration")) html.help(self._macro_help) html.checkbox( "add_custom_macro", self._attr.get("add_custom_macro", False), label=self._macro_label ) forms.end() html.show_localization_hint() html.hidden_fields() html.end_form()
def show_create_view_dialog(next_url=None): vs_ds = DatasourceSelection() ds = "services" # Default selection title = _("Create view") breadcrumb = visuals.visual_page_breadcrumb("views", title, "create") make_header( html, title, breadcrumb, make_simple_form_page_menu( _("View"), breadcrumb, form_name="create_view", button_name="_save", save_title=_("Continue"), ), ) if request.var("_save") and transactions.check_transaction(): try: ds = vs_ds.from_html_vars("ds") vs_ds.validate_value(ds, "ds") if not next_url: next_url = makeuri( request, [("datasource", ds)], filename="create_view_infos.py", ) else: next_url = next_url + "&datasource=%s" % ds raise HTTPRedirect(next_url) except MKUserError as e: html.user_error(e) html.begin_form("create_view") html.hidden_field("mode", "create") forms.header(_("Select Datasource")) forms.section(vs_ds.title()) vs_ds.render_input("ds", ds) html.help(vs_ds.help()) forms.end() html.hidden_fields() html.end_form() html.footer()
def page(self): is_configured = self._is_configured() is_configured_globally = self._varname in self._global_settings default_values = watolib.ABCConfigDomain.get_all_default_globals() defvalue = default_values[self._varname] value = self._current_settings.get(self._varname, self._global_settings.get(self._varname, defvalue)) html.begin_form("value_editor", method="POST") title = self._valuespec.title() assert isinstance(title, str) forms.header(title) if not config.wato_hide_varnames: forms.section(_("Configuration variable:")) html.tt(self._varname) forms.section(_("Current setting")) self._valuespec.render_input("ve", value) self._valuespec.set_focus("ve") html.help(self._valuespec.help()) if is_configured_globally: self._show_global_setting() forms.section(_("Factory setting")) html.write_html(HTML(self._valuespec.value_to_text(defvalue))) forms.section(_("Current state")) if is_configured_globally: html.write_text( _("This variable is configured in <a href=\"%s\">global settings</a>.") % ("wato.py?mode=edit_configvar&varname=%s" % self._varname)) elif not is_configured: html.write_text(_("This variable is at factory settings.")) else: curvalue = self._current_settings[self._varname] if is_configured_globally and curvalue == self._global_settings[self._varname]: html.write_text(_("Site setting and global setting are identical.")) elif curvalue == defvalue: html.write_text(_("Your setting and factory settings are identical.")) else: html.write(self._valuespec.value_to_text(curvalue)) forms.end() html.hidden_fields() html.end_form()
def page(self): html.help( _("The renaming of hosts is a complex operation since a host's name is being " "used as a unique key in various places. It also involves stopping and starting " "of the monitoring core. You cannot rename a host while you have pending changes.")) html.begin_form("rename_host", method="POST") forms.header(_("Rename host %s") % self._host.name()) forms.section(_("Current name")) html.write_text(self._host.name()) forms.section(_("New name")) html.text_input("newname", "") forms.end() html.set_focus("newname") html.hidden_fields() html.end_form()
def page(self): html.begin_form("random") forms.header(_("Add random hosts")) forms.section(_("Number to create")) html.write_text("%s: " % _("Hosts to create in each folder")) html.text_input("count", default_value="10", cssclass="number") html.set_focus("count") html.br() html.write_text("%s: " % _("Number of folders to create in each level")) html.text_input("folders", default_value="10", cssclass="number") html.br() html.write_text("%s: " % _("Levels of folders to create")) html.text_input("levels", default_value="1", cssclass="number") forms.end() html.hidden_fields() html.end_form()
def page(self): new = self._folder.name() is None watolib.Folder.current().show_breadcrump() watolib.Folder.current().need_permission("read") if new and watolib.Folder.current().locked(): watolib.Folder.current().show_locking_information() html.begin_form("edit_host", method="POST") # title forms.header(_("Title")) forms.section(_("Title")) TextUnicode().render_input("title", self._folder.title()) html.set_focus("title") # folder name (omit this for root folder) if new or not watolib.Folder.current().is_root(): if not config.wato_hide_filenames: forms.section(_("Internal directory name")) if new: html.text_input("name") else: html.write_text(self._folder.name()) html.help( _("This is the name of subdirectory where the files and " "other folders will be created. You cannot change this later." )) # Attributes inherited to hosts if new: parent = watolib.Folder.current() myself = None else: parent = watolib.Folder.current().parent() myself = watolib.Folder.current() configure_attributes(new, {"folder": myself}, "folder", parent, myself) forms.end() if new or not watolib.Folder.current().locked(): html.button("save", _("Save & Finish"), "submit") html.hidden_fields() html.end_form()
def page(self): html.begin_form("random") forms.header(_("Create Random Hosts")) forms.section(_("Number to create")) html.write_text("%s: " % _("Hosts to create in each folder")) html.number_input("count", 10) html.set_focus("count") html.br() html.write_text("%s: " % _("Number of folders to create in each level")) html.number_input("folders", 10) html.br() html.write_text("%s: " % _("Levels of folders to create")) html.number_input("levels", 1) forms.end() html.button("start", _("Start!"), "submit") html.hidden_fields() html.end_form()
def _show_try_form(self): html.begin_form('try') forms.header(_('Try Pattern Match')) forms.section(_('Hostname')) self._vs_host().render_input("host", self._hostname) forms.section(_('Logfile')) html.text_input('file') forms.section(_('Text to match')) html.help( _('You can insert some text (e.g. a line of the logfile) to test the patterns defined ' 'for this logfile. All patterns for this logfile are listed below. Matching patterns ' 'will be highlighted after clicking the "Try out" button.')) html.text_input('match', cssclass='match', size=100) forms.end() html.button('_try', _('Try out')) html.request.del_var('folder') # Never hand over the folder here html.hidden_fields() html.end_form()
def _show_try_form(self): html.begin_form("try") forms.header(_("Try Pattern Match")) forms.section(_("Hostname")) self._vs_host().render_input("host", self._hostname) forms.section(_("Logfile")) html.help(_("Here you need to insert the original file or pathname")) html.text_input("file", size=80) forms.section(_("Text to match")) html.help( _("You can insert some text (e.g. a line of the logfile) to test the patterns defined " "for this logfile. All patterns for this logfile are listed below. Matching patterns " 'will be highlighted after clicking the "Try out" button.')) html.text_input("match", cssclass="match", size=100) forms.end() html.button("_try", _("Try out")) request.del_var("folder") # Never hand over the folder here html.hidden_fields() html.end_form()
def _download_table(self, title: str, paths: List[str]) -> None: forms.header(title) forms.container() for path in paths: os_path = path relpath = path.replace(cmk.utils.paths.agents_dir + '/', '') filename = path.split('/')[-1] file_size = os.stat(os_path).st_size # FIXME: Rename classes etc. to something generic html.open_div(class_="ruleset") html.open_div(style="width:300px;", class_="text") html.a(filename, href="agents/%s" % relpath, download=filename) html.span("." * 200, class_="dots") html.close_div() html.div(cmk.utils.render.fmt_bytes(file_size), style="width:60px;", class_="rulecount") html.close_div() html.close_div() forms.end()
def page(self): self._folder.show_breadcrump() # Show search form html.begin_form("edit_host", method="GET") html.prevent_password_auto_completion() forms.header(_("General Properties")) forms.section(_("Hostname")) html.text_input("host_search_host") html.set_focus("host_search_host") # Attributes configure_attributes(False, {}, "host_search", parent=None, varprefix="host_search_") # Button forms.end() html.button("_local", _("Search in %s") % self._folder.title(), "submit") html.hidden_field("host_search", "1") html.hidden_fields() html.end_form()
def page(self): all_rulesets = watolib.AllRulesets() all_rulesets.load() for_host: bool = not self._service # Object type specific detail information if for_host: self._show_host_info() else: self._show_service_info(all_rulesets) last_maingroup = None for groupname in sorted( rulespec_group_registry.get_host_rulespec_group_names( for_host)): maingroup = groupname.split("/")[0] for rulespec in sorted(rulespec_registry.get_by_group(groupname), key=lambda x: x.title or ""): if (rulespec.item_type == "service") == (not self._service): continue # This rule is not for hosts/services # Open form for that group here, if we know that we have at least one rule if last_maingroup != maingroup: last_maingroup = maingroup rulegroup = watolib.get_rulegroup(maingroup) forms.header( rulegroup.title, isopen=maingroup == "monconf", narrow=True, css="rulesettings", ) html.help(rulegroup.help) self._output_analysed_ruleset(all_rulesets, rulespec, svc_desc_or_item=self._service, svc_desc=self._service) forms.end()
def _show_form(self) -> None: assert user.id is not None credentials = load_two_factor_credentials(user.id) webauthn_credentials = credentials["webauthn_credentials"] backup_codes = credentials["backup_codes"] html.begin_form("two_factor", method="POST") html.div("", id_="webauthn_message") forms.header(_("Credentials")) forms.section(_("Registered credentials"), simple=True) if webauthn_credentials: self._show_credentials(webauthn_credentials) else: html.i(_("No credentials registered")) forms.section(_("Backup codes"), simple=True) if backup_codes: html.p( _( "You have %d unused backup codes left. You can use them as one-time password " "if your key is not available." ) % len(backup_codes) ) html.i( _( "If you regenerate backup codes, you automatically invalidate the existing codes." ) ) else: html.i(_("No backup codes created yet.")) forms.end() html.hidden_fields() html.end_form() html.footer()
def page(self) -> None: html.begin_form("group") forms.header(_("Properties")) forms.section(_("Name"), simple=not self._new, is_required=True) html.help( _("The name of the group is used as an internal key. It cannot be " "changed later. It is also visible in the status GUI.")) if self._new: html.text_input("name") html.set_focus("name") else: html.write_text(self._name) html.set_focus("alias") forms.section(_("Alias"), is_required=True) html.help(_("An alias or description of this group.")) html.text_input("alias", self.group["alias"]) self._show_extra_page_elements() forms.end() html.hidden_fields() html.end_form()
def _show_service_info(self, all_rulesets): serviceinfo = watolib.check_mk_automation( self._host.site_id(), "analyse-service", [self._hostname, self._service]) if not serviceinfo: return forms.header(_("Check origin and parameters"), isopen=True, narrow=True, css="rulesettings") origin = serviceinfo["origin"] origin_txt = { "active": _("Active check"), "static": _("Manual check"), "auto": _("Inventorized check"), "classic": _("Classical check"), }[origin] self._render_rule_reason(_("Type of check"), None, "", "", False, origin_txt) # First case: discovered checks. They come from var/check_mk/autochecks/HOST. if origin == "auto": checkgroup = serviceinfo["checkgroup"] checktype = serviceinfo["checktype"] if not checkgroup: self._render_rule_reason( _("Parameters"), None, "", "", True, _("This check is not configurable via WATO")) # Logwatch needs a special handling, since it is not configured # via checkgroup_parameters but via "logwatch_rules" in a special # WATO module. elif checkgroup == "logwatch": rulespec = rulespec_registry["logwatch_rules"] self._output_analysed_ruleset( all_rulesets, rulespec, svc_desc_or_item=serviceinfo["item"], svc_desc=self._service, known_settings=serviceinfo["parameters"]) else: # Note: some discovered checks have a check group but # *no* ruleset for discovered checks. One example is "ps". # That can be configured as a manual check or created by # inventory. But in the later case all parameters are set # by the inventory. This will be changed in a later version, # but we need to address it anyway. grouprule = "checkgroup_parameters:" + checkgroup if grouprule not in rulespec_registry: try: rulespec = rulespec_registry["static_checks:" + checkgroup] except KeyError: rulespec = None if rulespec: url = watolib.folder_preserving_link([ ('mode', 'edit_ruleset'), ('varname', "static_checks:" + checkgroup), ('host', self._hostname) ]) self._render_rule_reason( _("Parameters"), url, _("Determined by discovery"), None, False, rulespec.valuespec._elements[2].value_to_text( serviceinfo["parameters"])) else: self._render_rule_reason( _("Parameters"), None, "", "", True, _("This check is not configurable via WATO")) else: rulespec = rulespec_registry[grouprule] self._output_analysed_ruleset( all_rulesets, rulespec, svc_desc_or_item=serviceinfo["item"], svc_desc=self._service, known_settings=serviceinfo["parameters"]) elif origin == "static": checkgroup = serviceinfo["checkgroup"] checktype = serviceinfo["checktype"] if not checkgroup: html.write_text(_("This check is not configurable via WATO")) else: rulespec = rulespec_registry["static_checks:" + checkgroup] itemspec = rulespec.item_spec if itemspec: item_text = itemspec.value_to_text(serviceinfo["item"]) title = rulespec.item_spec.title() else: item_text = serviceinfo["item"] title = _("Item") self._render_rule_reason(title, None, "", "", False, item_text) self._output_analysed_ruleset( all_rulesets, rulespec, svc_desc_or_item=serviceinfo["item"], svc_desc=self._service, known_settings=self._PARAMETERS_OMIT) html.write(rulespec.valuespec._elements[2].value_to_text( serviceinfo["parameters"])) html.close_td() html.close_tr() html.close_table() elif origin == "active": checktype = serviceinfo["checktype"] rulespec = rulespec_registry["active_checks:" + checktype] self._output_analysed_ruleset( all_rulesets, rulespec, svc_desc_or_item=None, svc_desc=None, known_settings=serviceinfo["parameters"]) elif origin == "classic": ruleset = all_rulesets.get("custom_checks") origin_rule_result = self._get_custom_check_origin_rule( ruleset, self._hostname, self._service) if origin_rule_result is None: raise MKUserError( None, _("Failed to determine origin rule of %s / %s") % (self._hostname, self._service)) rule_folder, rule_index, _rule = origin_rule_result url = watolib.folder_preserving_link([('mode', 'edit_ruleset'), ('varname', "custom_checks"), ('host', self._hostname)]) forms.section(html.render_a(_("Command Line"), href=url)) url = watolib.folder_preserving_link([('mode', 'edit_rule'), ('varname', "custom_checks"), ('rule_folder', rule_folder.path()), ('rulenr', rule_index), ('host', self._hostname)]) html.open_table(class_="setting") html.open_tr() html.open_td(class_="reason") html.a("%s %d %s %s" % (_("Rule"), rule_index + 1, _("in"), rule_folder.title()), href=url) html.close_td() html.open_td(class_=["settingvalue", "used"]) if "command_line" in serviceinfo: html.tt(serviceinfo["command_line"]) else: html.write_text(_("(no command line, passive check)")) html.close_td() html.close_tr() html.close_table() self._show_labels(serviceinfo.get("labels", {}), "service", serviceinfo.get("label_sources", {}))
def page(self): search = get_search_expression() html.begin_form("role", method="POST") # ID forms.header(_("Basic properties"), css="wide") forms.section(_("Internal ID"), simple="builtin" in self._role, is_required=True) if self._role.get("builtin"): html.write_text("%s (%s)" % (self._role_id, _("builtin role"))) html.hidden_field("id", self._role_id) else: html.text_input("id", self._role_id) html.set_focus("id") # Alias forms.section(_("Alias")) html.help(_("An alias or description of the role")) html.text_input("alias", self._role.get("alias", ""), size=50) # Based on if not self._role.get("builtin"): forms.section(_("Based on role")) html.help( _("Each user defined role is based on one of the builtin roles. " "When created it will start with all permissions of that role. When due to a software " "update or installation of an addons new permissions appear, the user role will get or " "not get those new permissions based on the default settings of the builtin role it's " "based on.")) role_choices: Choices = [(i, r["alias"]) for i, r in self._roles.items() if r.get("builtin")] html.dropdown("basedon", role_choices, deflt=self._role.get("basedon", "user"), ordered=True) forms.end() html.h2(_("Permissions")) # Permissions base_role_id = self._role.get("basedon", self._role_id) html.help( _("When you leave the permissions at "default" then they get their " "settings from the factory defaults (for builtin roles) or from the " "factory default of their base role (for user define roles). Factory defaults " "may change due to software updates. When choosing another base role, all " "permissions that are on default will reflect the new base role." )) for section in permission_section_registry.get_sorted_sections(): # Now filter by the optional search term filtered_perms = [] for perm in permission_registry.get_sorted_permissions(section): if search and (search not in perm.title.lower() and search not in perm.name.lower()): continue filtered_perms.append(perm) if not filtered_perms: continue forms.header(section.title, isopen=search is not None, css="wide") for perm in filtered_perms: forms.section(perm.title) pvalue = self._role["permissions"].get(perm.name) def_value = base_role_id in perm.defaults choices: Choices = [ ("yes", _("yes")), ("no", _("no")), ("default", _("default (%s)") % (def_value and _("yes") or _("no"))), ] deflt = {True: "yes", False: "no"}.get(pvalue, "default") html.dropdown("perm_" + perm.name, choices, deflt=deflt, style="width: 130px;") html.help(perm.description) forms.end() html.hidden_fields() html.end_form()
def _show_configuration_variables(self, groups): search = self._search at_least_one_painted = False html.open_div(class_="globalvars") for group in sorted(groups, key=lambda g: g.sort_index()): header_is_painted = False # needed for omitting empty groups for config_variable_class in group.config_variables(): config_variable = config_variable_class() varname = config_variable.ident() valuespec = config_variable.valuespec() if not config_variable.domain().enabled(): continue if config_variable.domain( ) == watolib.ConfigDomainCore and varname not in self._default_values: if config.debug: raise MKGeneralException( "The configuration variable <tt>%s</tt> is unknown to " "your local Check_MK installation" % varname) continue if not config_variable.in_global_settings(): continue if self._show_only_modified and varname not in self._current_settings: continue help_text = valuespec.help() or '' title_text = valuespec.title() if search and search not in group.title().lower() \ and search not in config_variable.domain().ident.lower() \ and search not in varname \ and search not in help_text.lower() \ and search not in title_text.lower(): continue # skip variable when search is performed and nothing matches at_least_one_painted = True if not header_is_painted: # always open headers when searching forms.header(group.title(), isopen=search or self._show_only_modified) header_is_painted = True default_value = self._default_values[varname] edit_url = watolib.folder_preserving_link([("mode", self._edit_mode()), ("varname", varname), ("site", html.request.var("site", ""))]) title = html.render_a( title_text, href=edit_url, class_="modified" if varname in self._current_settings else None, title=escaping.strip_tags(help_text)) if varname in self._current_settings: value = self._current_settings[varname] elif varname in self._global_settings: value = self._global_settings[varname] else: value = default_value try: to_text = valuespec.value_to_text(value) except Exception: logger.exception("error converting %r to text", value) to_text = html.render_error(_("Failed to render value: %r") % value) # Is this a simple (single) value or not? change styling in these cases... simple = True if '\n' in to_text or '<td>' in to_text: simple = False forms.section(title, simple=simple) if varname in self._current_settings: modified_cls: Optional[str] = "modified" value_title: Optional[str] = _("This option has been modified.") elif varname in self._global_settings: modified_cls = "modified globally" value_title = _("This option has been modified in global settings.") else: modified_cls = None value_title = None if is_a_checkbox(valuespec): html.open_div(class_=["toggle_switch_container", modified_cls]) html.toggle_switch( enabled=value, help_txt=_("Immediately toggle this setting"), href=html.makeactionuri([("_action", "toggle"), ("_varname", varname)]), class_=modified_cls, title=value_title, ) html.close_div() else: html.a(HTML(to_text), href=edit_url, class_=modified_cls, title=value_title) if header_is_painted: forms.end() if not at_least_one_painted and search: html.show_message(_('Did not find any global setting matching your search.')) html.close_div()