Exemplo n.º 1
0
def test_compute_state():
    local_result = local.LocalResult(
        cached=None,
        item="Some_other_Service",
        state='P',
        text="Result is computed from two values",
        perfdata=[
            local.Perfdata(
                name="value1",
                value=10,
                levels=(30, 50, None, None),
                tuple=("value1", 10, 30, 50, None, None),
            ),
            local.Perfdata(
                name="value2",
                value=20,
                levels=(20, 50, 10, 0),
                tuple=("value2", 20, 20, 50, 0, 100),
            )
        ],
    )

    assert list(local.check_local("", {}, {"": local_result})) == [
        Result(state=state.OK, summary="Result is computed from two values"),
        Result(state=state.OK, summary="value1: 10.00"),
        Metric("value1", 10, levels=(30, 50)),
        Result(state=state.WARN, summary="value2: 20.00 (warn/crit at 20.00/50.00)"),
        Metric("value2", 20, levels=(20, 50), boundaries=(0, 100)),
    ]
Exemplo n.º 2
0
def test_compute_state():
    local_result = local.LocalResult(
        cache_info=None,
        item="Some_other_Service",
        state=State.OK,
        apply_levels=True,
        text="Result is computed from two values",
        perfdata=[
            local.Perfdata(
                name="value1",
                value=10,
                levels_upper=(30, 50),
                levels_lower=None,
                boundaries=(None, None),
            ),
            local.Perfdata(
                name="value2",
                value=20,
                levels_upper=(20, 50),
                levels_lower=(10, 0),
                boundaries=(0, 100),
            ),
        ],
    )

    assert list(
        local.check_local("", {}, local.LocalSection(errors=[], data={"": local_result}))
    ) == [
        Result(state=State.OK, summary="Result is computed from two values"),
        Result(state=State.OK, summary="Value 1: 10.00"),
        Metric("value1", 10, levels=(30.0, 50.0)),
        Result(state=State.WARN, summary="Value 2: 20.00 (warn/crit at 20.00/50.00)"),
        Metric("value2", 20, levels=(20, 50), boundaries=(0, 100)),
    ]
Exemplo n.º 3
0
def test_fix_state():
    local_result = local.LocalResult(
        cached=None,
        item="NotGood",
        state=State.CRIT,
        apply_levels=False,
        text="A critical check",
        perfdata=[
            local.Perfdata(
                name="V",
                value=120,
                levels_upper=(50, 100),
                levels_lower=None,
                boundaries=(0, 1000),
            )
        ],
    )

    assert list(
        local.check_local(
            "NotGood", {},
            local.LocalSection(errors=[],
                               data={"NotGood": local_result}))) == [
                                   Result(state=State.CRIT,
                                          summary="A critical check"),
                                   Result(state=State.OK, summary='V: 120.00'),
                                   Metric("V", 120, boundaries=(0, 1000)),
                               ]
Exemplo n.º 4
0
def test_fix_state():
    local_result = local.LocalResult(
        cached=None,
        item="NotGood",
        state=2,
        text="A critical check",
        perfdata=[
            local.Perfdata(
                name="V",
                value=120,
                levels=(50, 100, None, None),
                tuple=("V", 120, 50, 100, 0, 1000),
            )
        ],
    )

    assert list(local.check_local("NotGood", {},
                                  {"NotGood": local_result})) == [
                                      Result(state=state.CRIT,
                                             summary="A critical check"),
                                      Metric("V",
                                             120,
                                             levels=(50, 100),
                                             boundaries=(0, 1000)),
                                  ]
Exemplo n.º 5
0
@pytest.mark.parametrize(
    "string_table_row,expected_parsed_data",
    [
        (
            ['0', 'Service_FOO', 'V=1', 'This', 'Check', 'is', 'OK'],
            {
                "Service_FOO": local.LocalResult(
                    cached=None,
                    item="Service_FOO",
                    state=0,
                    text="This Check is OK",
                    perfdata=[
                        local.Perfdata(
                            name="V",
                            value=1.0,
                            levels=(None, None, None, None),
                            tuple=("V", 1.0, None, None, None, None),
                        )
                    ],
                )
            },
        ),
        (
            ['0 "Service FOO" V=1 This Check is OK'],  # 1.7: sep(0) + shlex
            {
                "Service FOO": local.LocalResult(
                    cached=None,
                    item="Service FOO",
                    state=0,
                    text="This Check is OK",
                    perfdata=[
Exemplo n.º 6
0
 (
     ['0', 'Service_FOO', 'V=1', 'This', 'Check', 'is', 'OK'],
     local.LocalSection(errors=[],
                        data={
                            "Service_FOO":
                            local.LocalResult(
                                cached=None,
                                item="Service_FOO",
                                state=State.OK,
                                apply_levels=False,
                                text="This Check is OK",
                                perfdata=[
                                    local.Perfdata(
                                        name="V",
                                        value=1.0,
                                        levels_upper=None,
                                        levels_lower=None,
                                        boundaries=(None, None),
                                    )
                                ],
                            )
                        }),
 ),
 (
     ['0 "Service FOO" V=1 This Check is OK'],  # 1.7: sep(0) + shlex
     local.LocalSection(errors=[],
                        data={
                            "Service FOO":
                            local.LocalResult(
                                cached=None,
                                item="Service FOO",