Example #1
0
def test_check_postgres_stats_no_data():
    assert list(
        postgres_stats._check_postgres_stats(
            item="ANALYZE this",
            params={},
            section=SECTION,
            value_store={},
            now=NOW,
        )) == [IgnoreResults("Login into database failed")]
def test_discover_docker_container_status_health():
    _test_discovery(
        docker.discover_docker_container_status_health,
        PARSED,
        [Service()],
    )


@pytest.mark.parametrize("section, expected", [
    (PARSED, [
        Result(state=state.CRIT,
               summary='Health status: Unhealthy',
               details='Health status: Unhealthy'),
        Result(state=state.OK,
               summary='Last health report: mysqld is alive',
               details='Last health report: mysqld is alive'),
        Result(state=state.CRIT, summary='Failing streak: 0'),
        Result(state=state.OK,
               summary='Health test: CMD-SHELL /healthcheck.sh',
               details='Health test: CMD-SHELL /healthcheck.sh')
    ]),
    (PARSED_NOT_RUNNING, [
        IgnoreResults("Container is not running"),
    ]),
])
def test_check_docker_container_status_health(section, expected):
    import pprint as pp
    pp.pprint(section)
    yielded_results = list(docker.check_docker_container_status_health(section))
    assert repr(yielded_results) == repr(expected)
def test_parse_function():
    assert winperf_processor.parse_winperf_processor(INFO) == SECTION


def test_discovery():
    assert list(
        winperf_processor.discover_winperf_processor_util(SECTION)) == [
            Service(),
        ]


@pytest.mark.parametrize(
    "value_store, params, result",
    [
        ({}, {}, [
            IgnoreResults("Initialized: 'util'"),
            IgnoreResults("Initialized: 'user'"),
            IgnoreResults("Initialized: 'privileged'"),
            Result(state=State.OK, notice='Number of processors: 4'),
            Metric('cpus', 4),
        ]),
        (
            VALUE_STORE,
            {},
            [
                Result(state=State.OK, summary='Total CPU: 99.99983%'),
                Metric('util', 99.99983122362869,
                       boundaries=(0, 4)),  # boundaries: 4 as in 4 CPUs
                Result(state=State.OK, notice='User: 0.00051%'),
                Metric('user', 0.0005063291139240507),
                Result(state=State.OK, notice='Privileged: 0.000017%'),
        }
    }, [Service(item=ITEM)]),
])
def test_discovery(section, expected):
    yielded_services = list(
        oracle_asm_diskgroup.discovery_oracle_asm_diskgroup(section))
    assert yielded_services == expected


@pytest.mark.parametrize(
    "section, params, expected",
    [
        (
            SECTION_UNKNOWN_ITEM,
            oracle_asm_diskgroup.ASM_DISKGROUP_DEFAULT_LEVELS,
            [(IgnoreResults('Diskgroup %s not found' % ITEM))],
        ),
        (
            SECTION_OLD_DISMOUNTED,
            oracle_asm_diskgroup.ASM_DISKGROUP_DEFAULT_LEVELS,
            [Result(state=state.CRIT, summary="Diskgroup dismounted")],
        ),
        (
            SECTION_OLD_MOUNTED,
            oracle_asm_diskgroup.ASM_DISKGROUP_DEFAULT_LEVELS,
            [
                Metric(
                    'fs_used',
                    316283.0,
                    levels=(2097152.0, 2359296.0),
                    boundaries=(0.0, 2621440.0),
Example #5
0
    print(",\n".join(str(r) for r in results))
    assert results == expected_results


@pytest.mark.parametrize("section,expected_services", [
    (big_parsed_data, [Service(item='MSSQL_VEEAMSQL2012')]),
])
def test_discovery_mssql_counters_locks_per_batch(section, expected_services):
    results = list(discovery_mssql_counters_locks_per_batch(section))
    print(",\n".join(str(r) for r in results))
    assert results == expected_services


@pytest.mark.parametrize("item,params,section,expected_results", [
    ("MSSQL_VEEAMSQL2012", {}, big_parsed_data, [
        IgnoreResults(value="Cannot calculate rates yet"),
        Result(state=state.OK, summary='0.0'),
        Metric('locks_per_batch', 0.0, boundaries=(0.0, None)),
    ]),
])
def test_check_mssql_locks_per_batch(item, params, section, expected_results):
    # re-run check_locks_per_batch_base() once in order to get rates
    vs: Dict[str, Any] = {}
    results = []
    for _ in range(2):
        for result in check_locks_per_batch_base(vs, item, params, section):
            results.append(result)
    print(",\n".join(str(r) for r in results))
    assert results == expected_results

def test_check_postgres_query_duration_no_data():
    assert list(check_postgres_query_duration("item", {})) == [
        IgnoreResults("Login into database failed"),
    ]
Example #7
0
        }, [Service(item=ITEM)]),
    ],
)
def test_discovery(section, expected):
    yielded_services = list(
        oracle_asm_diskgroup.discovery_oracle_asm_diskgroup(section))
    assert yielded_services == expected


@pytest.mark.parametrize(
    "section, params, expected",
    [
        (
            SECTION_UNKNOWN_ITEM,
            oracle_asm_diskgroup.ASM_DISKGROUP_DEFAULT_LEVELS,
            [(IgnoreResults("Diskgroup %s not found" % ITEM))],
        ),
        (
            SECTION_OLD_DISMOUNTED,
            oracle_asm_diskgroup.ASM_DISKGROUP_DEFAULT_LEVELS,
            [Result(state=state.CRIT, summary="Diskgroup dismounted")],
        ),
        (
            SECTION_OLD_MOUNTED,
            oracle_asm_diskgroup.ASM_DISKGROUP_DEFAULT_LEVELS,
            [
                Metric(
                    "fs_used",
                    316283.0,
                    levels=(2097152.0, 2359296.0),
                    boundaries=(0.0, 2621440.0),