示例#1
0
def test_get_check_table_of_mgmt_boards(monkeypatch, hostname, expected_result):
    autochecks = {
        "mgmt-board-ipmi": [
            Service("mgmt_ipmi_sensors", "TEMP X", "Management Interface: IPMI Sensor TEMP X", {}),
        ],
        "ipmi-host": [Service("ipmi_sensors", "TEMP Y", "IPMI Sensor TEMP Y", {}),]
    }

    ts = Scenario().add_host("mgmt-board-ipmi",
                             tags={
                                 'piggyback': 'auto-piggyback',
                                 'networking': 'lan',
                                 'address_family': 'no-ip',
                                 'criticality': 'prod',
                                 'snmp_ds': 'no-snmp',
                                 'site': 'heute',
                                 'agent': 'no-agent'
                             })
    ts.add_host("ipmi-host",
                tags={
                    'piggyback': 'auto-piggyback',
                    'networking': 'lan',
                    'agent': 'cmk-agent',
                    'criticality': 'prod',
                    'snmp_ds': 'no-snmp',
                    'site': 'heute',
                    'address_family': 'ip-v4-only'
                })
    ts.set_option("management_protocol", {"mgmt-board-ipmi": "ipmi"})

    config_cache = ts.apply(monkeypatch)
    monkeypatch.setattr(config_cache, "get_autochecks_of", lambda h: autochecks.get(h, []))

    CheckManager().load(["mgmt_ipmi_sensors", "ipmi_sensors"])
    assert check_table.get_check_table(hostname).keys() == expected_result
示例#2
0
def test_host_config_snmp_check_interval(monkeypatch, hostname, section_name, result):
    CheckManager().load(["uptime", "snmp_uptime"])
    ts = Scenario().add_host(hostname)
    ts.set_ruleset("snmp_check_interval", [
        (("snmp_uptime", 4), [], ["testhost2"], {}),
    ])
    config_cache = ts.apply(monkeypatch)
    assert config_cache.get_host_config(hostname).snmp_check_interval(section_name) == result
示例#3
0
def test_get_check_table(monkeypatch, hostname, expected_result):
    autochecks = {
        "ping-host":
        [Service("smart.temp", "bla", u'Temperature SMART bla', {})],
        "autocheck-overwrite": [
            Service('smart.temp', '/dev/sda', u'Temperature SMART /dev/sda',
                    {"is_autocheck": True}),
            Service('smart.temp', '/dev/sdb', u'Temperature SMART /dev/sdb',
                    {"is_autocheck": True}),
        ],
        "ignore-not-existing-checks": [
            Service("bla.blub", "ITEM", u'Blub ITEM', {}),
        ],
        "node1": [
            Service("smart.temp", "auto-clustered",
                    u"Temperature SMART auto-clustered", {}),
            Service("smart.temp", "auto-not-clustered",
                    u'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'], [u'Temperature SMART auto-clustered$']),
    ])
    config_cache = ts.apply(monkeypatch)
    monkeypatch.setattr(config_cache, "get_autochecks_of",
                        lambda h: autochecks.get(h, []))

    CheckManager().load(["smart"])
    assert check_table.get_check_table(hostname) == expected_result
示例#4
0
def test_config_cache_icons_and_actions(monkeypatch, hostname, result):
    CheckManager().load(["ps"])
    ts = Scenario().add_host(hostname)
    ts.set_ruleset("service_icons_and_actions", [
        ("icon1", [], ["testhost2"], "CPU load$", {}),
        ("icon1", [], ["testhost2"], "CPU load$", {}),
        ("icon2", [], ["testhost2"], "CPU load$", {}),
    ])
    config_cache = ts.apply(monkeypatch)
    assert sorted(config_cache.icons_and_actions_of_service(hostname, "CPU load", "ps",
                                                            {})) == sorted(result)
示例#5
0
def test_get_cmk_passive_service_attributes(monkeypatch, hostname, result):
    CheckManager().load(["cpu"])

    ts = Scenario().add_host("localhost")
    ts.add_host("blub")
    ts.set_option(
        "extra_service_conf", {
            "contact_groups": [(u'ding', ['localhost'], ["CPU load$"]),],
            "check_interval": [
                (40.0, ['blub'], ["Check_MK$"]),
                (33.0, ['localhost'], ["CPU load$"]),
            ],
        })
    config_cache = ts.apply(monkeypatch)
    host_config = config_cache.get_host_config(hostname)
    check_mk_attrs = core_config.get_service_attributes(hostname, "Check_MK", config_cache)

    service = Service("cpu.loads", None, "CPU load", {})
    service_spec = core_config.get_cmk_passive_service_attributes(config_cache, host_config,
                                                                  service, check_mk_attrs)
    assert service_spec == result
示例#6
0
def test_labels_of_service_discovered_labels(monkeypatch, tmp_path):
    CheckManager().load(["cpu"])
    ts = Scenario().add_host("test-host")

    monkeypatch.setattr(cmk.utils.paths, "autochecks_dir", str(tmp_path))
    autochecks_file = Path(cmk.utils.paths.autochecks_dir).joinpath("test-host.mk")
    with autochecks_file.open("w", encoding="utf-8") as f:  # pylint: disable=no-member
        f.write(u"""[
    {'check_plugin_name': 'cpu.loads', 'item': None, 'parameters': cpuload_default_levels, 'service_labels': {u'äzzzz': u'eeeeez'}},
]""")

    config_cache = ts.apply(monkeypatch)

    service = config_cache.get_autochecks_of("test-host")[0]
    assert service.description == u"CPU load"

    assert config_cache.labels_of_service("xyz", u"CPU load") == {}
    assert config_cache.label_sources_of_service("xyz", u"CPU load") == {}

    assert config_cache.labels_of_service("test-host", service.description) == {u"äzzzz": u"eeeeez"}
    assert config_cache.label_sources_of_service("test-host", service.description) == {
        u"äzzzz": u"discovered"
    }
示例#7
0
def test_config(monkeypatch):
    CheckManager().load(["df", "cpu", "chrony", "lnx_if"])
    ts = Scenario().add_host("host")
    return ts.apply(monkeypatch)
def load_plugins():
    CheckManager().load(
        ["df", "cpu", "chrony", "lnx_if", "livestatus_status", "omd_status"])
    InventoryPluginManager().load()
示例#9
0
def test_get_check_table_of_static_check(monkeypatch, hostname,
                                         expected_result):
    static_checks = {
        "df_host": [
            Service(CheckPluginName('df'), '/snap/core/9066',
                    u'Filesystem /snap/core/9066',
                    [{
                        'tp_values': [('24X7', {
                            'inodes_levels': None
                        })],
                        'tp_default_value': {}
                    }, {
                        'trend_range': 24,
                        'show_levels': 'onmagic',
                        'inodes_levels': (10.0, 5.0),
                        'magic_normsize': 20,
                        'show_inodes': 'onlow',
                        'levels': (80.0, 90.0),
                        'show_reserved': False,
                        'levels_low': (50.0, 60.0),
                        'trend_perfdata': True
                    }]),
        ],
        "df_host_1": [
            Service(
                CheckPluginName('df'), '/snap/core/9067',
                u'Filesystem /snap/core/9067', {
                    'trend_range': 24,
                    'show_levels': 'onmagic',
                    'inodes_levels': (10.0, 5.0),
                    'magic_normsize': 20,
                    'show_inodes': 'onlow',
                    'levels': (80.0, 90.0),
                    'tp_default_value': {
                        'levels': (87.0, 90.0)
                    },
                    'show_reserved': False,
                    'tp_values': [('24X7', {
                        'inodes_levels': None
                    })],
                    'levels_low': (50.0, 60.0),
                    'trend_perfdata': True
                })
        ],
        "df_host_2": [
            Service(CheckPluginName('df'), '/snap/core/9068',
                    u'Filesystem /snap/core/9068', None)
        ],
    }

    ts = Scenario().add_host(hostname, tags={"criticality": "test"})
    ts.add_host("df_host")
    ts.add_host("df_host_1")
    ts.add_host("df_host_2")
    ts.set_option(
        "static_checks",
        {
            "filesystem": [
                (('df', '/snap/core/9066', [{
                    'tp_values': [('24X7', {
                        'inodes_levels': None
                    })],
                    'tp_default_value': {}
                }, {
                    'trend_range': 24,
                    'show_levels': 'onmagic',
                    'inodes_levels': (10.0, 5.0),
                    'magic_normsize': 20,
                    'show_inodes': 'onlow',
                    'levels': (80.0, 90.0),
                    'show_reserved': False,
                    'levels_low': (50.0, 60.0),
                    'trend_perfdata': True
                }]), [], ["df_host"]),
                (('df', '/snap/core/9067', [{
                    'tp_values': [('24X7', {
                        'inodes_levels': None
                    })],
                    'tp_default_value': {}
                }, {
                    'trend_range': 24,
                    'show_levels': 'onmagic',
                    'inodes_levels': (10.0, 5.0),
                    'magic_normsize': 20,
                    'show_inodes': 'onlow',
                    'levels': (80.0, 90.0),
                    'show_reserved': False,
                    'levels_low': (50.0, 60.0),
                    'trend_perfdata': True
                }]), [], ["df_host_1"]),
                (('df', '/snap/core/9068', None), [], ["df_host_2"]),
            ],
        },
    )

    config_cache = ts.apply(monkeypatch)
    monkeypatch.setattr(config_cache, "get_autochecks_of",
                        lambda h: static_checks.get(h, []))

    CheckManager().load(["df"])
    assert list(
        check_table.get_check_table(hostname).keys()) == expected_result
示例#10
0
def load_plugins():
    CheckManager().load(["df", "cpu", "chrony", "lnx_if"])
    InventoryPluginManager().load()