Ejemplo n.º 1
0
def test_check_fileinfo_group_patterns(info, group_pattern, expected_result):
    assert expected_result == list(
        fileinfo_plugin.check_fileinfo_groups(
            "banana",
            group_pattern,
            fileinfo_utils.parse_fileinfo(info),
        ))
Ejemplo n.º 2
0
def test_check_fileinfo_group_no_files(info, parsed, discovery_params, expected_result):
    """Test that the check returns an OK status when there are no files."""
    assert fileinfo_utils.parse_fileinfo(info) == parsed
    assert not list(fileinfo_plugin.discovery_fileinfo_groups(discovery_params, parsed))
    assert expected_result == list(
        fileinfo_plugin.check_fileinfo_groups(
            "banana",
            {"group_patterns": [("/banana/*", "")]},
            parsed,
        )
    )
Ejemplo n.º 3
0
def test_check_fileinfo_group_no_matching_files(info, parsed, expected_result):
    """Test that the check returns an OK status if there are no matching files."""

    actual_parsed = fileinfo_utils.parse_fileinfo(info)
    assert parsed.reftime == actual_parsed.reftime
    assert list(parsed.files) == list(actual_parsed.files)
    assert expected_result == list(
        fileinfo_plugin.check_fileinfo_groups(
            "banana",
            {"group_patterns": [("/banana/*", "")]},
            parsed,
        ))
Ejemplo n.º 4
0
def test_parse_fileinfo(info, expected_result):
    assert parse_fileinfo(info) == expected_result
Ejemplo n.º 5
0
def test_fileinfo_group_discovery(info, params, expected_result):
    section = fileinfo_utils.parse_fileinfo(info)

    discovery_result = fileinfo_utils.discovery_fileinfo_groups(
        params, section)
    assert list(discovery_result) == expected_result
Ejemplo n.º 6
0
def test_fileinfo_check(info, item, params, expected_result):
    section = fileinfo_utils.parse_fileinfo(info)

    check_result = fileinfo_plugin.check_fileinfo(item, params, section)
    assert list(check_result) == expected_result
Ejemplo n.º 7
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'.

    item = "c:\\filetest\\check_mk.txt"
    parsed = fileinfo_utils.parse_fileinfo([
        ["8"],
        ["c:\\filetest\\check_mk.txt", "7", "5"],
    ])

    size_result = [
        Result(state=State.OK, summary="Size: 7 B"),
        Metric("size", 7)
    ]

    # minage matches
    output_minage = fileinfo_plugin.check_fileinfo(
        item,
        {
            "minage": (5, 1),
        },
        parsed,
    )

    # In 1.6.0 warn, crit of minage was added, but now we use the
    # generic check_levels function.
    output_minage == size_result + [
        Result(state=State.WARN,
               summary="Age: 3.00 s (warn/crit below 5.00 s/1.00 s)"),
        Metric("age", 3),
    ]

    # maxage matches
    output_maxage = fileinfo_plugin.check_fileinfo(
        item,
        {
            "maxage": (1, 2),
        },
        parsed,
    )

    output_maxage == size_result + [
        Result(state=State.CRIT,
               summary="Age: 3.00 s (warn/crit at 1.00 s/2.00 s)"),
        Metric("age", 3),
    ]

    # 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 = fileinfo_plugin.check_fileinfo(
        item,
        {
            "minage": (5, 1),
            "maxage": (1, 2),
        },
        parsed,
    )

    output_both == size_result + [
        Result(state=State.CRIT,
               summary="Age: 3.00 s (warn/crit at 1.00 s/2.00 s)"),
        Metric("age", 3),
    ]