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 authorized_login_sites(self) -> SiteConfigurations: login_site_ids = sites.get_login_slave_sites() return self.authorized_sites({ site_id: s for site_id, s in sites.allsites().items() if site_id in login_site_ids })
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 authorized_sites( self, unfiltered_sites: Optional[SiteConfigurations] = None ) -> SiteConfigurations: if unfiltered_sites is None: unfiltered_sites = sites.allsites() authorized_sites = self.get_attribute("authorized_sites") if authorized_sites is None: return dict(unfiltered_sites) return { site_id: s for site_id, s in unfiltered_sites.items() if site_id in authorized_sites # }
def show(self): only_sites = snapin_site_choice("performance", sites.get_configured_site_choices()) def write_line(left, right, show_more): html.open_tr(class_="show_more_mode" if show_more else "basic") html.td(left, class_="left") html.td(html.render_strong(right), class_="right") html.close_tr() html.open_table(class_=["performance"]) try: sites.live().set_only_sites(only_sites) data = sites.live().query( "GET status\nColumns: service_checks_rate host_checks_rate " "external_commands_rate connections_rate forks_rate " "log_messages_rate cached_log_messages\n") finally: sites.live().set_only_sites(None) for what, show_more, col, format_str in \ [("Service checks", False, 0, "%.2f/s"), ("Host checks", False, 1, "%.2f/s"), ("External commands", True, 2, "%.2f/s"), ("Livestatus-conn.", True, 3, "%.2f/s"), ("Process creations", True, 4, "%.2f/s"), ("New log messages", True, 5, "%.2f/s"), ("Cached log messages", True, 6, "%d")]: write_line(what + ":", format_str % sum(row[col] for row in data), show_more=show_more) if only_sites is None and len(sites.allsites()) == 1: try: data = sites.live().query( "GET status\nColumns: external_command_buffer_slots " "external_command_buffer_max\n") finally: sites.live().set_only_sites(None) size = sum([row[0] for row in data]) maxx = sum([row[1] for row in data]) write_line(_('Com. buf. max/total'), "%d / %d" % (maxx, size), show_more=True) html.close_table()
def _validate(self, value): if value not in allsites().keys(): raise self.make_error("unknown_site", site=value)