Exemplo n.º 1
0
    def page(self) -> None:
        host_names = get_hostnames_from_checkboxes()
        hosts = {host_name: watolib.Folder.current().host(host_name) for host_name in host_names}
        current_host_hash = sha256(ensure_binary(repr(hosts))).hexdigest()

        # When bulk edit has been made with some hosts, then other hosts have been selected
        # and then another bulk edit has made, the attributes need to be reset before
        # rendering the form. Otherwise the second edit will have the attributes of the
        # first set.
        host_hash = request.var("host_hash")
        if not host_hash or host_hash != current_host_hash:
            request.del_vars(prefix="attr_")
            request.del_vars(prefix="bulk_change_")

        html.p("%s%s %s" %
               (_("You have selected <b>%d</b> hosts for bulk edit. You can now change "
                  "host attributes for all selected hosts at once. ") % len(hosts),
                _("If a select is set to <i>don't change</i> then currenty not all selected "
                  "hosts share the same setting for this attribute. "
                  "If you leave that selection, all hosts will keep their individual settings."),
                _("In case you want to <i>unset</i> attributes on multiple hosts, you need to "
                  "use the <i>bulk cleanup</i> action instead of bulk edit.")))

        html.begin_form("edit_host", method="POST")
        html.prevent_password_auto_completion()
        html.hidden_field("host_hash", current_host_hash)
        configure_attributes(False, hosts, "bulk", parent=watolib.Folder.current())
        forms.end()
        html.hidden_fields()
        html.end_form()
Exemplo n.º 2
0
def test_filters_filter_table(register_builtin_html, test, monkeypatch):
    # Needed for DeploymentTristateFilter test
    def deployment_states(host_name):
        return {
            "abc": {
                "target_aghash": "abc",
            },
            "zzz": {},
        }[host_name]

    if not cmk_version.is_raw_edition():
        import cmk.gui.cee.agent_bakery as agent_bakery  # pylint: disable=redefined-outer-name,import-outside-toplevel,no-name-in-module
        monkeypatch.setattr(agent_bakery, "get_cached_deployment_status", deployment_states)

    # Needed for FilterInvFloat test
    monkeypatch.setattr(cmk.gui.inventory, "get_inventory_data", get_inventory_data_patch)

    # Needed for FilterAggrServiceUsed test
    def is_part_of_aggregation_patch(host, service):
        return {
            ("h", "srv1"): True
        }.get((host, service), False)

    monkeypatch.setattr(cmk.gui.bi, "is_part_of_aggregation", is_part_of_aggregation_patch)

    with request.stashed_vars(), on_time('2018-04-15 16:50', 'CET'):
        request.del_vars()
        for key, val in test.request_vars:
            request.set_var(key, val)

        # TODO: Fix this for real...
        if not cmk_version.is_raw_edition or test.ident != "deployment_has_agent":
            filt = cmk.gui.plugins.visuals.utils.filter_registry[test.ident]
            assert filt.filter_table({}, test.rows) == test.expected_rows
Exemplo n.º 3
0
def test_filters_display_with_empty_request(register_builtin_html, live):
    with live, request.stashed_vars():
        request.del_vars()

        for filt in cmk.gui.plugins.visuals.utils.filter_registry.values():
            with output_funnel.plugged():
                _set_expected_queries(filt.ident, live)
                filt.display()
Exemplo n.º 4
0
def test_filters_filter_with_empty_request(register_builtin_html, filter_ident, live):
    if filter_ident == "hostgroupvisibility":
        expected_filter = "Filter: hostgroup_num_hosts > 0\n"
    else:
        expected_filter = ""

    with live(expect_status_query=False), request.stashed_vars():
        request.del_vars()

        filt = cmk.gui.plugins.visuals.utils.filter_registry[filter_ident]
        assert filt.filter(infoname="bla") == expected_filter
Exemplo n.º 5
0
def test_filters_filter(register_builtin_html, test, monkeypatch):
    # Needed for ABCFilterCustomAttribute
    monkeypatch.setattr(cmk.gui.config, "wato_host_attrs", [{"name": "bla", "title": "Bla"}])

    # Need for ABCTagFilter
    monkeypatch.setattr(cmk.gui.config, "tags", cmk.utils.tags.BuiltinTagConfig())

    with request.stashed_vars(), on_time('2018-04-15 16:50', 'CET'):
        request.del_vars()
        for key, val in test.request_vars:
            request.set_var(key, val)

        filt = cmk.gui.plugins.visuals.utils.filter_registry[test.ident]
        assert filt.filter(infoname="bla") == test.expected_filters