Exemplo n.º 1
0
    def _get_filter_headers_of_context(self, datasource_name, context, single_infos):
        try:
            from cmk.gui.cee.plugins.metrics.graphs import get_matching_filters
        except ImportError:
            raise MKGeneralException(_("Currently not supported with this Check_MK Edition"))

        datasource = data_source_registry[datasource_name]()

        # Note: our context/visuals/filters systems is not yet independent of
        # URL variables. This is not nice but needs a greater refactoring, so
        # we need to live with the current situation for the while.
        with html.stashed_vars():
            visuals.add_context_to_uri_vars(context, single_infos)

            # Prepare Filter headers for Livestatus
            filter_headers = ""
            for filt in get_matching_filters(datasource.infos):
                filter_headers += filt.filter(datasource.table)

            if html.request.var("site"):
                only_sites = [html.request.var("site")]
            else:
                only_sites = None

            return filter_headers, only_sites
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(what, site, host, service):
        return {
            ("s", "h", "srv1"): True
        }.get((site, host, service), False)

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

    with html.stashed_vars(), on_time('2018-04-15 16:50', 'CET'):
        html.request.del_vars()
        for key, val in test.request_vars:
            html.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):
    with html.stashed_vars():
        html.request.del_vars()

        for filt in cmk.gui.plugins.visuals.utils.filter_registry.values():
            with html.plugged():
                filt.display()
Exemplo n.º 4
0
def test_filters_display_with_empty_request(register_builtin_html, live):
    with live, html.stashed_vars():
        html.request.del_vars()

        for filt in cmk.gui.plugins.visuals.utils.filter_registry.values():
            with html.plugged():
                _set_expected_queries(filt.ident, live)
                filt.display()
Exemplo n.º 5
0
 def breadcrumb(self) -> Breadcrumb:
     # The ModeEditRuleset.breadcrumb_item does not know anything about the fact that this mode
     # is a child of the logwatch_rules ruleset. It can not construct the correct link to the
     # logwatch_rules ruleset in the breadcrumb. We hand over the ruleset variable name that we
     # are interested in to the mode. It's a bit hacky to do it this way, but it's currently the
     # only way to get these information to the modes breadcrumb method.
     with html.stashed_vars():
         html.request.set_var("varname", "logwatch_rules")
         return super().breadcrumb()
Exemplo n.º 6
0
def test_filters_display_with_empty_request(register_builtin_html):
    with html.stashed_vars():
        html.request.del_vars()

        for filter_class in cmk.gui.plugins.visuals.utils.filter_registry.values():
            # FIXME: register instances in filter_registry (CMK-5137)
            filt = filter_class()  # type: ignore[call-arg]
            with html.plugged():
                filt.display()
Exemplo n.º 7
0
def test_filters_filter_with_empty_request(register_builtin_html, filter_ident):
    if filter_ident == "hostgroupvisibility":
        expected_filter = "Filter: hostgroup_num_hosts > 0\n"
    else:
        expected_filter = ""

    with html.stashed_vars():
        html.request.del_vars()

        filt = cmk.gui.plugins.visuals.utils.filter_registry[filter_ident]()
        assert filt.filter(infoname="bla") == expected_filter
Exemplo n.º 8
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 html.stashed_vars(), on_time('2018-04-15 16:50', 'CET'):
        html.request.del_vars()
        for key, val in test.request_vars:
            html.request.set_var(key, val)

        filt = cmk.gui.plugins.visuals.utils.filter_registry[test.ident]()
        assert filt.filter(infoname="bla") == test.expected_filters
Exemplo n.º 9
0
 def breadcrumb(self) -> Breadcrumb:
     # To be able to calculate the breadcrumb with ModeCheckPluginTopic as parent, we need to
     # ensure that the topic is available.
     with html.stashed_vars():
         html.request.set_var("topic", self._manpage["header"]["catalog"])
         return super().breadcrumb()