Пример #1
0
def test_automation_update_dns_cache(test_cfg, site: Site):
    cache_path = "var/check_mk/ipaddresses.cache"

    if site.file_exists(cache_path):
        site.delete_file(cache_path)

    try:
        site.openapi.create_host("update-dns-cache-host")
        site.openapi.create_host("localhost")

        site.write_text_file(cache_path, "{('bla', 4): '127.0.0.1'}")

        result = _execute_automation(site, "update-dns-cache")
        assert isinstance(result, results.UpdateDNSCacheResult)

        assert result.n_updated > 0
        assert result.failed_hosts == ["update-dns-cache-host"]

        assert site.file_exists(cache_path)

        cache = eval(site.read_file(cache_path))  # pylint:disable=eval-used
        assert isinstance(cache, dict)
        assert cache[("localhost", 4)] == "127.0.0.1"
        assert ("bla", 4) not in cache

    finally:
        site.openapi.delete_host("localhost")
        site.openapi.delete_host("update-dns-cache-host")
Пример #2
0
def test_automation_set_autochecks(test_cfg, site: Site):
    hostname = HostName("blablahost")
    new_items: SetAutochecksTable = {
        ("df", "xxx"): ("Filesystem xxx", {}, {
            "xyz": "123"
        }, [hostname]),
        ("uptime", None): ("Uptime", None, {}, [hostname]),
    }

    try:
        assert isinstance(
            _execute_automation(
                site,
                "set-autochecks",
                args=[hostname],
                stdin=repr(new_items),
            ),
            results.SetAutochecksResult,
        )

        autochecks_file = "%s/%s.mk" % (cmk.utils.paths.autochecks_dir,
                                        hostname)
        assert os.path.exists(autochecks_file)

        data = autochecks.AutochecksStore(hostname).read()
        services = [(
            (str(s.check_plugin_name), s.item),
            s.parameters,
            s.service_labels,
        ) for s in data]
        assert sorted(services) == [
            (
                ("df", "xxx"),
                {},
                {
                    "xyz": "123"
                },
            ),
            (
                ("uptime", None),
                None,
                {},
            ),
        ]

        assert site.file_exists("var/check_mk/autochecks/%s.mk" % hostname)
    finally:
        if site.file_exists("var/check_mk/autochecks/%s.mk" % hostname):
            site.delete_file("var/check_mk/autochecks/%s.mk" % hostname)
Пример #3
0
def test_load_dashboard_plugin(request, site: Site):
    plugin_path = "local/lib/check_mk/gui/plugins/dashboard/test_plugin.py"

    def cleanup():
        site.delete_file(plugin_path)

    request.addfinalizer(cleanup)

    assert not site.file_exists("tmp/dashboard_test")

    site.write_text_file(
        plugin_path,
        """
with open("%s", "w") as f:
    f.write("ding")
""" % site.path("tmp/dashboard_test"),
    )

    # Reload site apache to trigger the reload of our plugin
    site.omd("reload", "apache")

    def file_created():
        return site.file_exists("tmp/dashboard_test")

    # We need to wait some time for apache to initialize our application
    wait_until(file_created, timeout=60, interval=1)
Пример #4
0
def test_automation_get_configuration(test_cfg, site: Site):
    variable_names = [
        "agent_port",
    ]

    automation_result = _execute_automation(
        site,
        "get-configuration",
        stdin=repr(variable_names),
    )
    assert isinstance(automation_result, results.GetConfigurationResult)
    assert automation_result.result["agent_port"] == 6556

    try:
        site.write_text_file("etc/check_mk/main.mk", "agent_port = 6558")

        result = _execute_automation(site,
                                     "get-configuration",
                                     stdin=repr(variable_names)).result
        assert result["agent_port"] == 6558

        site.write_text_file("etc/check_mk/conf.d/agent-port.mk",
                             "agent_port = 1234")

        result = _execute_automation(site,
                                     "get-configuration",
                                     stdin=repr(variable_names)).result
        assert result["agent_port"] == 6558

        site.write_text_file("etc/check_mk/main.mk", "")

        result = _execute_automation(site,
                                     "get-configuration",
                                     stdin=repr(variable_names)).result
        assert result["agent_port"] == 6556

        site.delete_file("etc/check_mk/conf.d/agent-port.mk")

        result = _execute_automation(site,
                                     "get-configuration",
                                     stdin=repr(variable_names)).result
        assert result["agent_port"] == 6556
    finally:
        if site.file_exists("etc/check_mk/conf.d/agent-port.mk"):
            site.delete_file("etc/check_mk/conf.d/agent-port.mk")

        site.write_text_file("etc/check_mk/main.mk", "")
Пример #5
0
def _create_cmk_backup(site: Site, execute):
    p = execute(["cmk", "--backup", "x.tgz"], cwd=site.root)
    assert p.returncode == 0, on_failure(p)
    assert p.stderr == ""
    assert p.stdout == ""
    assert site.file_exists("x.tgz")
Пример #6
0
def test_dcd_logrotate(site: Site):
    assert site.file_exists("etc/logrotate.d/dcd")
Пример #7
0
def test_dcd_exists(site: Site):
    assert site.file_exists("bin/dcd")