def test_apc_netbotz_drycontact_check(item, params, data, expected):

    check = Check("apc_netbotz_drycontact")
    assert check.run_check(item, params, data) == expected
def test_apc_netbotz_drycontact_inventory(parsed, expected):

    check = Check("apc_netbotz_drycontact")
    assert list(check.run_discovery(parsed)) == expected
Beispiel #3
0
def test_parse_multipath(test_data: TupleTestData) -> None:
    check = Check("multipath")
    result = check.run_parse(
        [re.split(' +', line.strip()) for line in test_data.input])
    assert test_data.output == result
def test_check(params, parsed, expected):
    check = Check(CHECK_NAME)
    actual = list(check.run_check(None, params, parsed))
    assert actual == expected
def test_wmi_cpu_load_discovery(info, item, expected_item_data):
    check = Check("f5_bigip_vserver")
    assert sorted(check.run_parse(info)[item].items()) == sorted(
        expected_item_data.items())
Beispiel #6
0
def test_health_parse_yields_with_volume_name_as_items():
    info = [["volume", "1", "volume-name", "Foo"]]
    expected_yield = {'Foo': {'volume-name': 'Foo'}}
    check = Check("hp_msa_volume")
    parse_result = check.run_parse(info)
    assert parse_result == expected_yield
Beispiel #7
0
def test_parse_sap_hana_ess_migration(info, expected_result):
    result = Check("sap_hana_ess_migration").run_parse(info)
    assert result == expected_result
Beispiel #8
0
def test_wmi_cpu_load_discovery(check_name, info, expected):
    check = Check(check_name)
    discovery_result = DiscoveryResult(
        check.run_discovery(check.run_parse(info)))
    discovery_expected = DiscoveryResult(expected)
    assertDiscoveryResultsEqual(check, discovery_result, discovery_expected)
Beispiel #9
0
def test_unavailability_levels(max_unavailable, total, expected):
    check = Check('k8s_replicas')
    crit_lower = check.context['parse_k8s_unavailability'](max_unavailable, total)
    assert crit_lower == expected
Beispiel #10
0
def test_fileinfo_min_max_age_levels():
    # This test has the following purpose:
    # For each file attr (size or age) the levels 'min*', 'max*' are evaluated.
    # 'min*' is evaluated first and if 'max*' returns state '0' (eg. not set)
    # the service state is also '0'.

    check = Check("fileinfo")
    item = u'c:\\filetest\\check_mk.txt'
    parsed = check.run_parse([
        [u'8'],
        [u'c:\\filetest\\check_mk.txt', u'7', u'5'],
    ])

    size_result = BasicCheckResult(
        0,
        "Size: 7 B",
        [
            PerfValue('size', 7, None, None, None, None),
        ],
    )

    # minage matches
    output_minage = check.run_check(item, {
        'minage': (5, 1),
    }, parsed)

    # In 1.6.0 warn, crit of minage was added, but now we use the
    # generic check_levels function.
    assertCheckResultsEqual(
        CheckResult(output_minage),
        CheckResult([
            size_result,
            BasicCheckResult(
                1,
                "Age: 3.00 s (warn/crit below 5.00 s/1.00 s)",
                [
                    PerfValue('age', 3, None, None, None, None),
                ],
            ),
        ]))

    # maxage matches
    output_maxage = check.run_check(item, {
        'maxage': (1, 2),
    }, parsed)

    assertCheckResultsEqual(
        CheckResult(output_maxage),
        CheckResult([
            size_result,
            BasicCheckResult(
                2,
                "Age: 3.00 s (warn/crit at 1.00 s/2.00 s)",
                [
                    PerfValue('age', 3, 1, 2, None, None),
                ],
            ),
        ]))

    # both match
    # This should never happen (misconfiguration), but test the order
    # of min* vs. max* and perfdata (always take the upper levels)
    # In 1.6.0 levels text of minage was added, but now we use the
    # generic check_levels function.
    output_both = check.run_check(item, {
        'minage': (5, 1),
        'maxage': (1, 2),
    }, parsed)

    assertCheckResultsEqual(
        CheckResult(output_both),
        CheckResult([
            size_result,
            BasicCheckResult(
                2,
                "Age: 3.00 s (warn/crit at 1.00 s/2.00 s)",
                [
                    PerfValue('age', 3, 1, 2, None, None),
                ],
            ),
        ]))
Beispiel #11
0
def test_surge_levels(max_surge, total, expected):
    check = Check('k8s_replicas')
    crit = check.context['parse_k8s_surge'](max_surge, total)
    assert crit == expected
Beispiel #12
0
def test_df_discovery_yields_volume_name_as_item():
    parsed = {'Foo': {'durable-id': 'Bar'}}
    expected_yield: Tuple[str, Dict[Any, Any]] = ('Foo', {})
    check = Check("hp_msa_volume.df")
    for item in check.run_discovery(parsed):
        assert item == expected_yield
Beispiel #13
0
def test_multipath_parse_groups(group, result):
    check = Check("multipath")
    assert result in check.run_parse([group])
def test_apc_netbotz_drycontact_parse(info, expected):

    check = Check("apc_netbotz_drycontact")
    assert check.run_parse(info) == expected
def test_ra32e_power_discovery(info, result):
    check = Check(RA32E_POWER)
    assert check.run_discovery(info) == result
Beispiel #16
0
def test_zfsget_discovery(info, expected_discovery_result):
    check_zfsget = Check("zfsget")
    discovery_result = DiscoveryResult(check_zfsget.run_discovery(check_zfsget.run_parse(info)))
    assertDiscoveryResultsEqual("zfsget", discovery_result,
                                DiscoveryResult(expected_discovery_result))
def test_ra32e_power_check_acpower():
    check = Check(RA32E_POWER)
    result = BasicCheckResult(*check.run_check(None, {}, [['1']]))

    assert result.status == 0
    assert 'AC/Utility' in result.infotext
Beispiel #18
0
def test_wmi_cpuload_timeout_exceptions(check_name, info, expected):
    check = Check(check_name)
    with pytest.raises(MKCounterWrapped):
        CheckResult(check.run_check(None, {}, check.run_parse(info)))
def test_ra32e_power_check_nodata():
    check = Check(RA32E_POWER)
    result = BasicCheckResult(*check.run_check(None, {}, [['']]))

    assert result.status == 3
    assert 'unknown' in result.infotext
Beispiel #20
0
def test_io_discovery_yields_summary():
    parsed = {'Foo': {'durable-id': 'Bar'}}
    expected_yield = ('SUMMARY', 'diskstat_default_levels')
    check = Check("hp_msa_volume.io")
    for item in check.run_discovery(parsed):
        assert item == expected_yield
Beispiel #21
0
def test_parse_netstat(info, expected_parsed):
    parsed = Check('netstat').run_parse(info)
    assert parsed == expected_parsed
Beispiel #22
0
def test_health_discovery_forwards_info():
    info = [["volume", "1", "volume-name", "Foo"]]
    check = Check("hp_msa_volume")
    discovery_result = check.run_discovery(info)
    assert discovery_result == [(info[0], None)]
Beispiel #23
0
def test_mkbackup_parse(info):
    check = Check("mkbackup")
    check.run_parse(info)