コード例 #1
0
ファイル: test_check_table.py プロジェクト: gradecke/checkmk
def test_cluster_ignores_nodes_parameters(monkeypatch: MonkeyPatch) -> None:

    node = HostName("node")
    cluster = HostName("cluster")

    service_id = CheckPluginName("smart_temp"), "auto-clustered"

    ts = Scenario()
    ts.add_host("node")
    ts.add_cluster("cluster", nodes=["node"])
    ts.set_ruleset(
        "clustered_services",
        [([], ["node"], ["Temperature SMART auto-clustered$"])],
    )
    ts.set_autochecks("node", [Service(*service_id, "Temperature SMART auto-clustered", {})])
    ts.apply(monkeypatch)

    # a rule for the node:
    monkeypatch.setattr(
        config,
        "_update_with_configured_check_parameters",
        lambda host, plugin, item, params, configured_params: {"levels_for_node": (1, 2), **params}
        if host == node
        else params,
    )

    clustered_service = check_table.get_check_table(cluster)[service_id]
    assert clustered_service.parameters == {"levels": (35, 40)}
コード例 #2
0
ファイル: test_check_table.py プロジェクト: LinuxHaus/checkmk
def test_cluster_ignores_nodes_parameters(monkeypatch: MonkeyPatch) -> None:

    node = HostName("node")
    cluster = HostName("cluster")

    service_id = CheckPluginName("smart_temp"), "auto-clustered"

    ts = Scenario()
    ts.add_host("node")
    ts.add_cluster("cluster", nodes=["node"])
    ts.set_ruleset(
        "clustered_services",
        [([], ["node"], ["Temperature SMART auto-clustered$"])],
    )
    ts.set_autochecks("node", [AutocheckEntry(*service_id, {}, {})])
    ts.apply(monkeypatch)

    # a rule for the node:
    monkeypatch.setattr(
        config,
        "_get_configured_parameters",
        lambda host, plugin, item:
        (TimespecificParameters((TimespecificParameterSet.from_parameters(
            {"levels_for_node": (1, 2)}), ))
         if host == node else TimespecificParameters()),
    )

    clustered_service = check_table.get_check_table(cluster)[service_id]
    assert clustered_service.parameters.entries == (
        TimespecificParameterSet.from_parameters({"levels": (35, 40)}), )
コード例 #3
0
ファイル: test_core_nagios.py プロジェクト: LinuxHaus/checkmk
def test_create_nagios_host_spec(hostname_str: str, result: Dict[str, str],
                                 monkeypatch: MonkeyPatch) -> None:
    if cmk_version.is_managed_edition():
        result = result.copy()
        result["_CUSTOMER"] = "provider"

    ts = Scenario()
    ts.add_host(HostName("localhost"))
    ts.add_host(HostName("host2"))
    ts.add_cluster(HostName("cluster1"))

    ts.add_cluster(HostName("cluster2"), nodes=["node1", "node2"])
    ts.add_host(HostName("node1"))
    ts.add_host(HostName("node2"))
    ts.add_host(HostName("switch"))
    ts.set_option(
        "ipaddresses",
        {
            HostName("node1"): "127.0.0.1",
            HostName("node2"): "127.0.0.2",
        },
    )

    ts.set_option(
        "extra_host_conf",
        {
            "alias": [
                ("lOCALhost", ["localhost"]),
            ],
        },
    )

    ts.set_option(
        "extra_host_conf",
        {
            "alias": [
                ("lOCALhost", ["host2"]),
                ("CLUSTer", ["cluster2"]),
            ],
            "parents": [
                ("switch", ["node1", "node2"]),
            ],
        },
    )

    hostname = HostName(hostname_str)
    outfile = io.StringIO()
    cfg = core_nagios.NagiosConfig(outfile, [hostname])

    config_cache = ts.apply(monkeypatch)
    host_attrs = core_config.get_host_attributes(hostname, config_cache)

    host_spec = core_nagios._create_nagios_host_spec(cfg, config_cache,
                                                     hostname, host_attrs)
    assert host_spec == result
コード例 #4
0
def scenario_fixture(monkeypatch):
    test_hosts = ["ds-test-host1", "ds-test-host2", "ds-test-node1", "ds-test-node2"]

    ts = Scenario()

    if is_enterprise_repo():
        ts.set_option("monitoring_core", "cmc")
    else:
        ts.set_option("monitoring_core", "nagios")

    for h in test_hosts:
        ts.add_host(h)

    ts.set_option("ipaddresses", dict((h, "127.0.0.1") for h in test_hosts))
    ts.add_cluster("ds-test-cluster1", nodes=["ds-test-node1", "ds-test-node2"])
    ts.fake_standard_linux_agent_output(*test_hosts)

    return ts.apply(monkeypatch)
コード例 #5
0
ファイル: test_check_table.py プロジェクト: gradecke/checkmk
def test_get_check_table(
    monkeypatch: MonkeyPatch, hostname_str: str, expected_result: HostCheckTable
) -> None:
    hostname = HostName(hostname_str)
    autochecks = {
        "ping-host": [
            Service(
                CheckPluginName("smart_temp"),
                "bla",
                "Temperature SMART bla",
                {},
            )
        ],
        "autocheck-overwrite": [
            Service(
                CheckPluginName("smart_temp"),
                "/dev/sda",
                "Temperature SMART /dev/sda",
                {"is_autocheck": True},
            ),
            Service(
                CheckPluginName("smart_temp"),
                "/dev/sdb",
                "Temperature SMART /dev/sdb",
                {"is_autocheck": True},
            ),
        ],
        "ignore-not-existing-checks": [
            Service(
                CheckPluginName("bla_blub"),
                "ITEM",
                "Blub ITEM",
                {},
            ),
        ],
        "node1": [
            Service(
                CheckPluginName("smart_temp"),
                "auto-clustered",
                "Temperature SMART auto-clustered",
                {},
            ),
            Service(
                CheckPluginName("smart_temp"),
                "auto-not-clustered",
                "Temperature SMART auto-not-clustered",
                {},
            ),
        ],
    }

    ts = Scenario().add_host(hostname, tags={"criticality": "test"})
    ts.add_host("ping-host", tags={"agent": "no-agent"})
    ts.add_host("node1")
    ts.add_cluster("cluster1", nodes=["node1"])
    ts.set_option(
        "static_checks",
        {
            "temperature": [
                (("smart.temp", "/dev/sda", {}), [], ["no-autochecks", "autocheck-overwrite"]),
                (("blub.bla", "ITEM", {}), [], ["ignore-not-existing-checks"]),
                (("smart.temp", "ITEM1", {}), [], ["ignore-disabled-rules"], {"disabled": True}),
                (("smart.temp", "ITEM2", {}), [], ["ignore-disabled-rules"]),
                (("smart.temp", "/dev/sda", {"rule": 1}), [], ["static-check-overwrite"]),
                (("smart.temp", "/dev/sda", {"rule": 2}), [], ["static-check-overwrite"]),
                (("smart.temp", "static-node1", {}), [], ["node1"]),
                (("smart.temp", "static-cluster", {}), [], ["cluster1"]),
            ]
        },
    )
    ts.set_ruleset(
        "clustered_services",
        [
            ([], ["node1"], ["Temperature SMART auto-clustered$"]),
        ],
    )
    config_cache = ts.apply(monkeypatch)
    monkeypatch.setattr(config_cache, "get_autochecks_of", lambda h: autochecks.get(h, []))

    assert check_table.get_check_table(hostname) == expected_result
コード例 #6
0
ファイル: test_check_table.py プロジェクト: LinuxHaus/checkmk
def test_get_check_table(monkeypatch: MonkeyPatch, hostname_str: str,
                         expected_result: HostCheckTable) -> None:
    hostname = HostName(hostname_str)

    ts = Scenario()
    ts.add_host(hostname, tags={"criticality": "test"})
    ts.add_host("ping-host", tags={"agent": "no-agent"})
    ts.add_host("node1")
    ts.add_cluster("cluster1", nodes=["node1"])
    ts.set_option(
        "static_checks",
        {
            "temperature": [
                (("smart.temp", "/dev/sda", {}), [],
                 ["no-autochecks", "autocheck-overwrite"]),
                (("blub.bla", "ITEM", {}), [], ["ignore-not-existing-checks"]),
                (("smart.temp", "ITEM1", {}), [], ["ignore-disabled-rules"], {
                    "disabled": True
                }),
                (("smart.temp", "ITEM2", {}), [], ["ignore-disabled-rules"]),
                (("smart.temp", "/dev/sda", {
                    "rule": 1
                }), [], ["static-check-overwrite"]),
                (("smart.temp", "/dev/sda", {
                    "rule": 2
                }), [], ["static-check-overwrite"]),
                (("smart.temp", "static-node1", {}), [], ["node1"]),
                (("smart.temp", "static-cluster", {}), [], ["cluster1"]),
            ]
        },
    )
    ts.set_ruleset(
        "clustered_services",
        [
            ([], ["node1"], ["Temperature SMART auto-clustered$"]),
        ],
    )
    ts.set_autochecks(
        "ping-host",
        [
            AutocheckEntry(CheckPluginName("smart_temp"), "bla", {}, {}),
        ],
    )
    ts.set_autochecks(
        "autocheck-overwrite",
        [
            AutocheckEntry(CheckPluginName("smart_temp"), "/dev/sda",
                           {"is_autocheck": True}, {}),
            AutocheckEntry(CheckPluginName("smart_temp"), "/dev/sdb",
                           {"is_autocheck": True}, {}),
        ],
    )
    ts.set_autochecks(
        "ignore-not-existing-checks",
        [
            AutocheckEntry(CheckPluginName("bla_blub"), "ITEM", {}, {}),
        ],
    )
    ts.set_autochecks(
        "node1",
        [
            AutocheckEntry(CheckPluginName("smart_temp"), "auto-clustered", {},
                           {}),
            AutocheckEntry(CheckPluginName("smart_temp"), "auto-not-clustered",
                           {}, {}),
        ],
    )

    ts.apply(monkeypatch)

    assert set(check_table.get_check_table(hostname)) == set(expected_result)
    for key, value in check_table.get_check_table(hostname).items():
        assert key in expected_result
        assert expected_result[key] == value
コード例 #7
0
 def config_cache(self, cluster, nodes, monkeypatch):
     ts = Scenario()
     ts.add_cluster(cluster, nodes=nodes.keys())
     return ts.apply(monkeypatch)