def _render_tag_list(self): with table_element( "tags", _("Tag groups"), help=(_("Tags are the basis of Check_MK's rule based configuration. " "If the first step you define arbitrary tag groups. A host " "has assigned exactly one tag out of each group. These tags can " "later be used for defining parameters for hosts and services, " "such as <i>disable notifications for all hosts with the tags " "<b>Network device</b> and <b>Test</b></i>.")), empty_text=_("You haven't defined any tag groups yet."), searchable=False, sortable=False) as table: for nr, tag_group in enumerate(self._effective_config.tag_groups): table.row() table.cell(_("Actions"), css="buttons") self._show_tag_icons(tag_group, nr) table.text_cell(_("ID"), tag_group.id) table.text_cell(_("Title"), tag_group.title) table.text_cell(_("Topic"), tag_group.topic or _("Tags")) table.cell(_("Demonstration"), sortable=False) html.begin_form("tag_%s" % tag_group.id) watolib.host_attribute("tag_%s" % tag_group.id).render_input("", None) html.end_form()
def _validate_general_host_attributes(host_attributes, new): # inventory_failed and site are no "real" host_attributes (TODO: Clean this up!) all_host_attribute_names = list( host_attribute_registry.keys()) + ["inventory_failed", "site"] for name, value in host_attributes.items(): if name not in all_host_attribute_names: raise MKUserError( None, _("Unknown attribute: %s") % escaping.escape_attribute(name)) # For real host attributes validate the values try: attr: Optional[ABCHostAttribute] = watolib.host_attribute(name) except KeyError: attr = None if attr is not None: if attr.needs_validation("host", new): attr.validate_input(value, "") # The site attribute gets an extra check if name == "site" and value not in allsites().keys(): raise MKUserError( None, _("Unknown site %s") % escaping.escape_attribute(value))
def _validate_general_host_attributes(host_attributes, new): """Check if the given attribute name exists, no type check""" all_host_attribute_names = _retrieve_host_attributes() # inventory_failed and site are no "real" host_attributes (TODO: Clean this up!) all_host_attribute_names.extend(["inventory_failed", "site"]) for name, value in host_attributes.items(): if name not in all_host_attribute_names: raise MKUserError( None, _("Unknown attribute: %s") % escaping.escape_attribute(name)) # For real host attributes validate the values try: attr = watolib.host_attribute(name) except KeyError: attr = None if attr is not None: if attr.needs_validation("host", new): attr.validate_input(value, "") # The site attribute gets an extra check if name == "site" and value not in allsites().keys(): raise MKUserError( None, _("Unknown site %s") % escaping.escape_attribute(value))
def validate_custom_host_attributes(data: dict[str, str]) -> dict[str, str]: for name, value in data.items(): try: attribute = watolib.host_attribute(name) except KeyError: raise ValidationError(f"No such attribute, {name!r}", field_name=name) if attribute.topic( ) != watolib.host_attributes.HostAttributeTopicCustomAttributes: raise ValidationError(f"{name} is not a custom host attribute.") try: attribute.validate_input(value, "") except MKUserError as exc: raise ValidationError(str(exc)) return data