def _bulk_collect_cleaned_attributes(self): to_clean = [] for attr in host_attribute_registry.attributes(): attrname = attr.name() if html.get_checkbox("_clean_" + attrname) is True: to_clean.append(attrname) return to_clean
def _show_hosts(self): if not self._folder.has_hosts(): return hostnames = sorted(self._folder.hosts().keys(), key=utils.key_num_split) search_text = html.request.var("search") html.div("", id_="row_info") # Show table of hosts in this folder html.begin_form("hosts", method="POST") with table_element("hosts", title=_("Hosts"), searchable=False, omit_empty_columns=True) as table: # Compute colspan for bulk actions colspan = 6 for attr in host_attribute_registry.attributes(): if attr.show_in_table(): colspan += 1 if not self._folder.locked_hosts() and config.user.may( "wato.edit_hosts") and config.user.may("wato.move_hosts"): colspan += 1 if self._folder.is_search_folder(): colspan += 1 contact_group_names = load_contact_group_information() host_errors = self._folder.host_validation_errors() rendered_hosts: List[HostName] = [] # Now loop again over all hosts and display them max_hosts = len(hostnames) for hostname in hostnames: if table.limit_reached: table.limit_hint = max_hosts continue self._show_host_row(rendered_hosts, table, hostname, search_text, colspan, host_errors, contact_group_names) html.hidden_field("selection_id", weblib.selection_id()) html.hidden_fields() html.end_form() selected = config.user.get_rowselection(weblib.selection_id(), 'wato-folder-/' + self._folder.path()) row_count = len(hostnames) row_info = "%d %s" % (row_count, _("host") if row_count == 1 else _("hosts")) html.javascript("cmk.utils.update_row_info(%s);" % json.dumps(row_info)) selection_properties = { "page_id": "wato-folder-%s" % ('/' + self._folder.path()), "selection_id": weblib.selection_id(), "selected_rows": selected, } html.javascript('cmk.selection.init_rowselect(%s);' % (json.dumps(selection_properties)))
def _show_host_row(self, rendered_hosts, table, hostname, search_text, show_checkboxes, colspan, host_errors, contact_group_names): if search_text and (search_text.lower() not in hostname.lower()): return host = self._folder.host(hostname) rendered_hosts.append(hostname) effective = host.effective_attributes() table.row() # Column with actions (buttons) if show_checkboxes: table.cell(html.render_input( "_toggle_group", type_="button", class_="checkgroup", onclick="cmk.selection.toggle_all_rows();", value='X'), sortable=False, css="checkbox") # Use CSS class "failed" in order to provide information about # selective toggling inventory-failed hosts for Javascript html.input(name="_c_%s" % hostname, type_="checkbox", value=colspan, class_="failed" if host.discovery_failed() else None) html.label("", "_c_%s" % hostname) table.cell(_("Actions"), css="buttons", sortable=False) self._show_host_actions(host) # Hostname with link to details page (edit host) table.cell(_("Hostname")) errors = host_errors.get(hostname, []) + host.validation_errors() if errors: msg = _("Warning: This host has an invalid configuration: ") msg += ", ".join(errors) html.icon(msg, "validation_error") html.nbsp() if host.is_offline(): html.icon(_("This host is disabled"), "disabled") html.nbsp() if host.is_cluster(): html.icon( _("This host is a cluster of %s") % ", ".join(host.cluster_nodes()), "cluster") html.nbsp() html.a(hostname, href=host.edit_url()) # Show attributes for attr in host_attribute_registry.attributes(): if attr.show_in_table(): attrname = attr.name() if attrname in host.attributes(): tdclass, tdcontent = attr.paint( host.attributes()[attrname], hostname) else: tdclass, tdcontent = attr.paint(effective.get(attrname), hostname) tdclass += " inherited" table.cell(attr.title(), escaping.escape_attribute(tdcontent), css=tdclass) # Am I authorized? reason = host.reason_why_may_not("read") if not reason: icon = "authok" title = _("You have permission to this host.") else: icon = "autherr" title = escaping.strip_tags(reason) table.cell(_('Auth'), html.render_icon(icon, title), css="buttons", sortable=False) # Permissions and Contact groups - through complete recursion and inhertance permitted_groups, host_contact_groups, _use_for_services = host.groups( ) table.cell( _("Permissions"), HTML(", ").join([ self._render_contact_group(contact_group_names, g) for g in permitted_groups ])) table.cell( _("Contact Groups"), HTML(", ").join([ self._render_contact_group(contact_group_names, g) for g in host_contact_groups ])) if not config.wato_hide_hosttags: table.cell(_("Tags"), css="tag-ellipsis") tag_groups, show_all_code = self._limit_labels(host.tag_groups()) html.write( cmk.gui.view_utils.render_tag_groups(tag_groups, "host", with_links=False)) html.write(show_all_code) table.cell(_("Explicit labels"), css="tag-ellipsis") labels, show_all_code = self._limit_labels(host.labels()) html.write( cmk.gui.view_utils.render_labels( labels, "host", with_links=False, label_sources={k: "explicit" for k in labels.keys()})) html.write(show_all_code) # Located in folder if self._folder.is_search_folder(): table.cell(_("Folder")) html.a(host.folder().alias_path(), href=host.folder().url())
def _show_hosts(self): if not self._folder.has_hosts(): return show_checkboxes = html.request.var('show_checkboxes', '0') == '1' hostnames = sorted(self._folder.hosts().keys(), key=utils.key_num_split) search_text = html.request.var("search") # Helper function for showing bulk actions. This is needed at the bottom # of the table of hosts and - if there are more than just a few - also # at the top of the table. search_shown = False # Show table of hosts in this folder html.begin_form("hosts", method="POST") with table_element("hosts", title=_("Hosts"), searchable=False, omit_empty_columns=True) as table: # Remember if that host has a target folder (i.e. was imported with # a folder information but not yet moved to that folder). If at least # one host has a target folder, then we show an additional bulk action. at_least_one_imported = False more_than_ten_items = False for num, hostname in enumerate(hostnames): if search_text and (search_text.lower() not in hostname.lower()): continue host = self._folder.host(hostname) effective = host.effective_attributes() if effective.get("imported_folder"): at_least_one_imported = True if num == 11: more_than_ten_items = True # Compute colspan for bulk actions colspan = 6 for attr in host_attribute_registry.attributes(): if attr.show_in_table(): colspan += 1 if not self._folder.locked_hosts() and config.user.may( "wato.edit_hosts") and config.user.may("wato.move_hosts"): colspan += 1 if show_checkboxes: colspan += 1 if self._folder.is_search_folder(): colspan += 1 # Add the bulk action buttons also to the top of the table when this # list shows more than 10 rows if more_than_ten_items and \ (config.user.may("wato.edit_hosts") or config.user.may("wato.manage_hosts")): self._bulk_actions(table, at_least_one_imported, True, True, colspan, show_checkboxes) search_shown = True contact_group_names = load_contact_group_information() host_errors = self._folder.host_validation_errors() rendered_hosts = [] # Now loop again over all hosts and display them for hostname in hostnames: self._show_host_row(rendered_hosts, table, hostname, search_text, show_checkboxes, colspan, host_errors, contact_group_names) if config.user.may("wato.edit_hosts") or config.user.may( "wato.manage_hosts"): self._bulk_actions(table, at_least_one_imported, False, not search_shown, colspan, show_checkboxes) html.hidden_fields() html.end_form() selected = config.user.get_rowselection( weblib.selection_id(), 'wato-folder-/' + self._folder.path()) row_count = len(rendered_hosts) headinfo = "%d %s" % (row_count, _("host") if row_count == 1 else _("hosts")) html.javascript("cmk.utils.update_header_info(%s);" % json.dumps(headinfo)) if show_checkboxes: selection_properties = { "page_id": "wato-folder-%s" % ('/' + self._folder.path()), "selection_id": weblib.selection_id(), "selected_rows": selected, } html.javascript('cmk.selection.init_rowselect(%s);' % (json.dumps(selection_properties)))