コード例 #1
0
def configure_service_tags_fixture(site, web, default_cfg):  # noqa: F811 # pylint: disable=redefined-outer-name
    web.set_ruleset(
        "service_tag_rules",
        {
            "ruleset": {
                "": [
                    {
                        "value": [("criticality", "prod")],
                        "condition": {
                            "host_name": ["livestatus-test-host"],
                            "service_description": [{
                                "$regex": "CPU load$",
                            }],
                        },
                    },
                ],
            }
        },
    )
    web.activate_changes()
    yield
    web.set_ruleset(
        "service_tag_rules",
        {"ruleset": {
            "": [],
        }},
    )
    web.activate_changes()
コード例 #2
0
def default_cfg_fixture(request, site, web):  # noqa: F811 # pylint: disable=redefined-outer-name
    site.ensure_running()
    config = DefaultConfig(core=request.param)
    site.set_config("CORE", config.core, with_restart=True)

    print("Applying default config (%s)" % config.core)
    create_linux_test_host(request, web, site, "livestatus-test-host")
    create_linux_test_host(request, web, site, "livestatus-test-host.domain")
    web.discover_services("livestatus-test-host")
    web.activate_changes()
    return config
コード例 #3
0
def cfg_setup_fixture(request, web, site: Site):  # noqa: F811 # pylint: disable=redefined-outer-name
    hostname = "test-prediction"

    # Enforce use of the pre-created RRD file from the git. The restart of the core
    # is needed to make it renew it's internal RRD file cache
    site.makedirs("var/check_mk/rrd/test-prediction")
    with open(site.path("var/check_mk/rrd/test-prediction/CPU_load.rrd"),
              "wb") as f:
        f.write(
            open(
                "%s/tests/integration/cmk/base/test-files/CPU_load.rrd" %
                repo_path(), "rb").read())

    site.write_text_file(
        "var/check_mk/rrd/test-prediction/CPU_load.info",
        open("%s/tests/integration/cmk/base/test-files/CPU_load.info" %
             repo_path()).read(),
    )

    site.restart_core()

    create_linux_test_host(request, web, site, "test-prediction")

    site.write_text_file(
        "etc/check_mk/conf.d/linux_test_host_%s_cpu_load.mk" % hostname,
        """
globals().setdefault('custom_checks', [])

custom_checks = [
    ( {'service_description': u'CPU load', 'has_perfdata': True}, [], ALL_HOSTS, {} ),
] + custom_checks
""",
    )

    web.activate_changes()

    yield

    # Cleanup
    site.delete_file("etc/check_mk/conf.d/linux_test_host_%s_cpu_load.mk" %
                     hostname)
    site.delete_dir("var/check_mk/rrd")
コード例 #4
0
def scenario_fixture(request, web, site: Site):  # noqa: F811 # pylint: disable=redefined-outer-name
    core = request.param.core
    unreachable_enabled = request.param.unreachable_enabled
    site.set_core(core)

    try:
        print("Applying test config")

        web.add_host(
            "notify-test-parent",
            attributes={
                "ipaddress": "127.0.0.1",
            },
        )

        web.add_host(
            "notify-test-child",
            attributes={
                "ipaddress": "127.0.0.1",
                "parents": ["notify-test-parent"],
            },
        )

        if unreachable_enabled:
            notification_options = "d,u,r,f,s"
        else:
            notification_options = "d,r,f,s"

        rule_result = web.get_ruleset("extra_host_conf:notification_options")
        rule_result["ruleset"] = {
            "": [{"condition": {}, "options": {}, "value": notification_options}]
        }
        web.set_ruleset("extra_host_conf:notification_options", rule_result)

        web.activate_changes()

        site.live.command("[%d] DISABLE_HOST_CHECK;notify-test-parent" % time.time())
        site.live.command("[%d] DISABLE_SVC_CHECK;notify-test-parent;PING" % time.time())
        site.live.command(
            "[%d] DISABLE_SVC_CHECK;notify-test-parent;Check_MK Discovery" % time.time()
        )

        site.live.command("[%d] DISABLE_HOST_CHECK;notify-test-child" % time.time())
        site.live.command("[%d] DISABLE_SVC_CHECK;notify-test-child;PING" % time.time())
        site.live.command(
            "[%d] DISABLE_SVC_CHECK;notify-test-child;Check_MK Discovery" % time.time()
        )

        site.live.command("[%d] DISABLE_FLAP_DETECTION" % time.time())

        yield request.param
    finally:
        #
        # Cleanup code
        #
        print("Cleaning up default config")

        site.live.command("[%d] ENABLE_FLAP_DETECTION" % time.time())
        site.live.command("[%d] ENABLE_HOST_CHECK;notify-test-child" % time.time())
        site.live.command("[%d] ENABLE_HOST_CHECK;notify-test-parent" % time.time())

        web.delete_host("notify-test-child")
        web.delete_host("notify-test-parent")

        web.activate_changes()
コード例 #5
0
ファイル: test_modes.py プロジェクト: PLUTEX/checkmk
def test_cfg_fixture(web, site: Site):  # noqa: F811 # pylint: disable=redefined-outer-name
    print("Applying default config")
    web.add_host(
        "modes-test-host",
        attributes={
            "ipaddress": "127.0.0.1",
        },
    )
    web.add_host(
        "modes-test-host2",
        attributes={
            "ipaddress": "127.0.0.1",
            "tag_criticality": "test",
        },
    )
    web.add_host(
        "modes-test-host3",
        attributes={
            "ipaddress": "127.0.0.1",
            "tag_criticality": "test",
        },
    )
    web.add_host(
        "modes-test-host4",
        attributes={
            "ipaddress": "127.0.0.1",
            "tag_criticality": "offline",
        },
    )

    site.write_text_file(
        "etc/check_mk/conf.d/modes-test-host.mk",
        "datasource_programs.append(('cat ~/var/check_mk/agent_output/<HOST>', [], ALL_HOSTS))\n",
    )

    site.makedirs("var/check_mk/agent_output/")
    site.write_text_file("var/check_mk/agent_output/modes-test-host",
                         get_standard_linux_agent_output())
    site.write_text_file("var/check_mk/agent_output/modes-test-host2",
                         get_standard_linux_agent_output())
    site.write_text_file("var/check_mk/agent_output/modes-test-host3",
                         get_standard_linux_agent_output())

    web.discover_services("modes-test-host")
    web.discover_services("modes-test-host2")
    web.discover_services("modes-test-host3")

    try:
        web.activate_changes()
        yield None
    finally:
        #
        # Cleanup code
        #
        print("Cleaning up test config")

        site.delete_dir("var/check_mk/agent_output")

        site.delete_file("etc/check_mk/conf.d/modes-test-host.mk")

        web.delete_host("modes-test-host")
        web.delete_host("modes-test-host2")
        web.delete_host("modes-test-host3")
        web.delete_host("modes-test-host4")

        web.activate_changes()