def test_check_oracle_instance_uptime_normal(
        fix_register: FixRegister) -> None:
    with on_time(1643360266, "UTC"):
        assert list(fix_register.check_plugins[CheckPluginName(
            "oracle_instance_uptime")].check_function(
                item="IC731",
                params={},
                section=parse_oracle_instance([[
                    "IC731",
                    "12.1.0.2.0",
                    "OPEN",
                    "ALLOWED",
                    "STARTED",
                    "2144847",
                    "3190399742",
                    "ARCHIVELOG",
                    "PRIMARY",
                    "YES",
                    "IC73",
                    "130920150251",
                ]]),
            )) == [
                Result(
                    state=State.OK,
                    summary=
                    "Up since 2022-01-03 13:10:19, uptime: 24 days, 19:47:27",
                ),
                Metric(
                    "uptime",
                    2144847.0,
                ),
            ]
def test_check_oracle_instance_uptime_error(fix_register: FixRegister) -> None:
    with pytest.raises(MKCounterWrapped):
        list(fix_register.check_plugins[CheckPluginName(
            "oracle_instance_uptime"
        )].check_function(
            item="IC731",
            params={},
            section=parse_oracle_instance([[
                "IC731",
                "FAILURE",
                "ORA-99999 tnsping failed for IC731 ERROR: ORA-28002: the password "
                "will expire within 1 days",
            ]]),
        ))
def test_check_oracle_instance(
    fix_register: FixRegister,
    agent_line: list[str],
    expected_result: CheckResult,
) -> None:
    assert (list(fix_register.check_plugins[CheckPluginName(
        "oracle_instance")].check_function(
            item="IC731",
            params={
                "logins": 2,
                "noforcelogging": 1,
                "noarchivelog": 1,
                "primarynotopen": 2,
            },
            section=parse_oracle_instance([agent_line]),
        )) == expected_result)
def test_inv_oracle_instance_multiline() -> None:
    lines = [
        [
            "SID",
            "VERSION",
            "OPENMODE",
            "LOGINS",
            "_ARCHIVER",
            "123",
            "_DBID",
            "LOGMODE",
            "_DATABASE_ROLE",
            "_FORCE_LOGGING",
            "_NAME",
            "080220151025",
            "_PLUGGABLE",
            "_CON_ID",
            "",
            "_PDBID",
            "_POPENMODE",
            "_PRESTRICTED",
            "_PTOTAL_SIZE",
            "_PRECOVERY_STATUS",
            "_PUP_SECONDS",
            "_PBLOCK_SIZE",
        ],
        [
            "SID",
            "VERSION",
            "_OPENMODE",
            "LOGINS",
            "_ARCHIVER",
            "_RAW_UP_SECONDS",
            "_DBID",
            "LOGMODE",
            "_DATABASE_ROLE",
            "_FORCE_LOGGING",
            "_NAME",
            "080220151026",
            "TRUE",
            "_CON_ID",
            "PNAME",
            "_PDBID",
            "POPENMODE",
            "_PRESTRICTED",
            "_PTOTAL_SIZE",
            "_PRECOVERY_STATUS",
            "456",
            "_PBLOCK_SIZE",
        ],
    ]
    expected_data = [
        TableRow(
            path=["software", "applications", "oracle", "instance"],
            key_columns={
                "sid": "SID",
            },
            inventory_columns={
                "pname": "",
                "version": "VERSION",
                "openmode": "OPENMODE",
                "logmode": "LOGMODE",
                "logins": "LOGINS",
                "db_creation_time": "2015-02-08 10:25",
            },
            status_columns={
                "db_uptime": 123,
            },
        ),
        TableRow(
            path=["software", "applications", "oracle", "instance"],
            key_columns={
                "sid": "SID",
            },
            inventory_columns={
                "pname": "PNAME",
                "version": "VERSION",
                "openmode": "POPENMODE",
                "logmode": "LOGMODE",
                "logins": "ALLOWED",
                "db_creation_time": "2015-02-08 10:26",
            },
            status_columns={
                "db_uptime": 456,
            },
        ),
    ]

    assert list(inventory_oracle_instance(
        parse_oracle_instance(lines))) == expected_data
def test_inv_oracle_instance(
    line: list[str],
    expected_data: InventoryResult,
) -> None:
    assert list(inventory_oracle_instance(parse_oracle_instance(
        [line]))) == expected_data
def test_parse_oracle_instance() -> None:
    assert parse_oracle_instance([
        [
            "XE",
            "11.2.0.2.0",
            "OPEN",
            "ALLOWED",
            "STOPPED",
            "1212537",
            "2858521146",
            "NOARCHIVELOG",
            "PRIMARY",
            "NO",
            "XE",
            "290520181207",
        ],
        [
            "IC731",
            "12.1.0.2.0",
            "OPEN",
            "ALLOWED",
            "STARTED",
            "2144847",
            "3190399742",
            "ARCHIVELOG",
            "PRIMARY",
            "YES",
            "IC73",
            "130920150251",
        ],
        ["I442", "FAILURE"],
        [
            "+ASM",
            "FAILURE",
            "ORA-99999 tnsping failed for +ASM ERROR: ORA-28002: the password will expire within 1 days",
        ],
    ]) == {
        "+ASM":
        GeneralError(
            "+ASM",
            "ORA-99999 tnsping failed for +ASM ERROR: ORA-28002: the password will expire within 1 days",
        ),
        "I442":
        InvalidData("I442"),
        "IC731":
        Instance(
            archiver="STARTED",
            database_role="PRIMARY",
            db_creation_time="130920150251",
            force_logging="YES",
            log_mode="ARCHIVELOG",
            logins="ALLOWED",
            name="IC73",
            old_agent=False,
            openmode="OPEN",
            pdb=False,
            pluggable="FALSE",
            pname=None,
            popenmode=None,
            prestricted=None,
            ptotal_size=None,
            pup_seconds=None,
            sid="IC731",
            up_seconds="2144847",
            version="12.1.0.2.0",
        ),
        "XE":
        Instance(
            archiver="STOPPED",
            database_role="PRIMARY",
            db_creation_time="290520181207",
            force_logging="NO",
            log_mode="NOARCHIVELOG",
            logins="ALLOWED",
            name="XE",
            old_agent=False,
            openmode="OPEN",
            pdb=False,
            pluggable="FALSE",
            pname=None,
            popenmode=None,
            prestricted=None,
            ptotal_size=None,
            pup_seconds=None,
            sid="XE",
            up_seconds="1212537",
            version="11.2.0.2.0",
        ),
    }
Example #7
0
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.

# yapf: disable
# type: ignore

import pytest

from tests.testlib import Check

from cmk.base.check_api import MKCounterWrapped
from cmk.base.plugins.agent_based.oracle_instance import parse_oracle_instance

pytestmark = pytest.mark.checks

PARSED = parse_oracle_instance([[
    '+ASM', 'FAILURE',
    'ORA-99999 tnsping failed for +ASM ERROR: ORA-28002: the password will expire within 1 days'
]])


def test_oracle_intance_uptime_discovery():
    check = Check('oracle_instance.uptime')
    assert list(check.run_discovery(PARSED)) == []


def test_oracle_instance_uptime_check_error():
    check = Check('oracle_instance.uptime')
    with pytest.raises(MKCounterWrapped):
        check.run_check("+ASM", {}, PARSED)
# yapf: disable
# type: ignore

from cmk.base.plugins.agent_based.oracle_instance import parse_oracle_instance

checkname = 'oracle_instance'

freeze_time = '2020-01-30 00:00:00'

parsed = parse_oracle_instance([
    [
        'TUX2', '12.1.0.1.0', 'OPEN', 'ALLOWED', 'STARTED', '6735',
        '1297771692', 'ARCHIVELOG', 'PRIMARY', 'NO', 'TUX2'
    ],
    [
        'TUX5', '12.1.0.1.1', 'MOUNTED', 'ALLOWED', 'STARTED', '82883',
        '1297771692', 'NOARCHIVELOG', 'PRIMARY', 'NO', '0', 'TUX5'
    ],
    [
        '+ASM', 'FAILURE',
        'ORA-99999 tnsping failed for +ASM ERROR: ORA-28002: the password will expire within 1 days'
    ]
])

discovery = {
    '': [('+ASM', {}), ('TUX2', {}), ('TUX5', {})],
    'uptime': [('TUX2', {}), ('TUX5', {})]
}

checks = {
    '': [
        (