Esempio n. 1
0
def _realhost_scenario(monkeypatch):
    hostname = "test-realhost"
    ipaddress = "1.2.3.4"
    ts = Scenario().add_host(hostname, ipaddress=ipaddress)
    ts.set_ruleset("inventory_df_rules", [{
        'value': {
            'ignore_fs_types': ['tmpfs', 'nfs', 'smbfs', 'cifs', 'iso9660'],
            'never_ignore_mountpoints': ['~.*/omd/sites/[^/]+/tmp$']
        },
        'condition': {
            'host_labels': {
                'cmk/check_mk_server': 'yes'
            }
        }
    }])
    ts.apply(monkeypatch)

    def fake_lookup_ip_address(*_a, **_kw):
        return ipaddress

    monkeypatch.setattr(ip_lookup, "lookup_ip_address", fake_lookup_ip_address)

    DiscoveredHostLabelsStore(hostname).save({
        'existing_label': {
            'plugin_name': 'foo',
            'value': 'bar',
        },
        'another_label': {
            'plugin_name': 'labels',
            'value': 'true',
        }
    })

    broker = ParsedSectionsBroker()
    broker.update({
        HostKey(hostname=hostname,
                ipaddress=ipaddress,
                source_type=SourceType.HOST):
        AgentHostSections(
            sections={
                SectionName("labels"): [
                    [
                        '{"cmk/check_mk_server":"yes"}',
                    ],
                ],
                SectionName("df"): [
                    [
                        '/dev/sda1',
                        'vfat',
                        '523248',
                        '3668',
                        '519580',
                        '1%',
                        '/boot/test-efi',
                    ],
                    [
                        'tmpfs',
                        'tmpfs',
                        '8152916',
                        '244',
                        '8152672',
                        '1%',
                        '/opt/omd/sites/test-heute/tmp',
                    ],
                ],
            })
    })

    return RealHostScenario(hostname, ipaddress, broker)
Esempio n. 2
0
def _cluster_scenario(monkeypatch):
    hostname = "test-clusterhost"
    ipaddress = "1.2.3.4"
    node1_hostname = 'test-node1'
    node2_hostname = 'test-node2'

    def fake_lookup_ip_address(host_config, *, family, for_mgmt_board=True):
        return ipaddress

    monkeypatch.setattr(ip_lookup, "lookup_ip_address", fake_lookup_ip_address)

    ts = Scenario()
    ts.add_host(node1_hostname)
    ts.add_host(node2_hostname)
    ts.add_cluster(hostname, nodes=[node1_hostname, node2_hostname])
    ts.set_ruleset("inventory_df_rules", [{
        'value': {
            'ignore_fs_types': ['tmpfs', 'nfs', 'smbfs', 'cifs', 'iso9660'],
            'never_ignore_mountpoints': ['~.*/omd/sites/[^/]+/tmp$']
        },
        'condition': {
            'host_labels': {
                'cmk/check_mk_server': 'yes'
            }
        }
    }])
    ts.set_ruleset("clustered_services", [([], [node1_hostname], ['fs_'])])
    host_config = ts.apply(monkeypatch).get_host_config(hostname)

    DiscoveredHostLabelsStore(node1_hostname).save({
        'node1_existing_label': {
            'plugin_name': 'node1_plugin',
            'value': 'true',
        }
    })

    DiscoveredHostLabelsStore(hostname).save({
        'existing_label': {
            'plugin_name': 'foo',
            'value': 'bar',
        },
        'another_label': {
            'plugin_name': 'labels',
            'value': 'true',
        }
    })

    broker = ParsedSectionsBroker()
    broker.update({
        HostKey(hostname=node1_hostname,
                ipaddress=ipaddress,
                source_type=SourceType.HOST):
        AgentHostSections(
            sections={
                SectionName("labels"): [
                    [
                        '{"cmk/check_mk_server":"yes"}',
                    ],
                ],
                SectionName("df"): [
                    [
                        '/dev/sda1',
                        'vfat',
                        '523248',
                        '3668',
                        '519580',
                        '1%',
                        '/boot/test-efi',
                    ],
                    [
                        'tmpfs',
                        'tmpfs',
                        '8152916',
                        '244',
                        '8152672',
                        '1%',
                        '/opt/omd/sites/test-heute/tmp',
                    ],
                ],
            }),
        HostKey(hostname=node2_hostname,
                ipaddress=ipaddress,
                source_type=SourceType.HOST):
        AgentHostSections(
            sections={
                SectionName("labels"): [
                    [
                        '{"node2_live_label":"true"}',
                    ],
                ],
                SectionName("df"): [
                    [
                        '/dev/sda1',
                        'vfat',
                        '523248',
                        '3668',
                        '519580',
                        '1%',
                        '/boot/test-efi',
                    ],
                    [
                        'tmpfs',
                        'tmpfs',
                        '8152916',
                        '244',
                        '8152672',
                        '1%',
                        '/opt/omd/sites/test-heute2/tmp',
                    ],
                ],
            }),
    })

    return ClusterScenario(
        host_config,
        ipaddress,
        broker,
        node1_hostname,
        node2_hostname,
    )
Esempio n. 3
0
def test_get_check_table(monkeypatch, hostname, expected_result):
    autochecks = {
        "ping-host": [
            Service(
                CheckPluginName("smart_temp"),
                "bla",
                u'Temperature SMART bla',
                {},
            )
        ],
        "autocheck-overwrite": [
            Service(
                CheckPluginName('smart_temp'),
                '/dev/sda',
                u'Temperature SMART /dev/sda',
                {"is_autocheck": True},
            ),
            Service(
                CheckPluginName('smart_temp'),
                '/dev/sdb',
                u'Temperature SMART /dev/sdb',
                {"is_autocheck": True},
            ),
        ],
        "ignore-not-existing-checks": [
            Service(
                CheckPluginName("bla_blub"),
                "ITEM",
                u'Blub ITEM',
                {},
            ),
        ],
        "node1": [
            Service(
                CheckPluginName("smart_temp"),
                "auto-clustered",
                u"Temperature SMART auto-clustered",
                {},
            ),
            Service(
                CheckPluginName("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, []))

    assert check_table.get_check_table(hostname) == expected_result
Esempio n. 4
0
def test_is_ipv6_primary_host(monkeypatch, hostname, tags, result, ruleset):
    ts = Scenario().add_host(hostname, tags)
    ts.set_ruleset("primary_address_family", ruleset)
    config_cache = ts.apply(monkeypatch)
    assert config_cache.get_host_config(hostname).is_ipv6_primary == result