Exemplo n.º 1
0
def test_ended_preemtively():
    lines = """\
QMNAME(MTAVBS0P)                                          STATUS(ENDED PREEMPTIVELY) DEFAULT(NO) STANDBY(NOT APPLICABLE) INSTNAME(Installation1) INSTPATH(/opt/mqm) INSTVER(7.5.0.2)
"""
    section = parse_info(lines, chr(10))
    check = Check(CHECK_NAME)
    parsed = check.run_parse(section)
    params = factory_settings['ibm_mq_managers_default_levels']
    actual = list(check.run_check('MTAVBS0P', params, parsed))
    expected = [
        (2, u'Status: ENDED PREEMPTIVELY'),
        (0, u'Version: 7.5.0.2'),
        (0, u'Installation: /opt/mqm (Installation1), Default: NO'),
    ]
    assert expected == actual

    lines = """\
QMNAME(MTAVBS0P)                                          STATUS(ENDED PRE-EMPTIVELY) DEFAULT(NO) STANDBY(NOT APPLICABLE) INSTNAME(Installation1) INSTPATH(/opt/mqm) INSTVER(8.0.0.1)
"""
    section = parse_info(lines, chr(10))
    check = Check(CHECK_NAME)
    parsed = check.run_parse(section)
    params = factory_settings['ibm_mq_managers_default_levels']
    actual = list(check.run_check('MTAVBS0P', params, parsed))
    expected = [
        (2, u'Status: ENDED PRE-EMPTIVELY'),
        (0, u'Version: 8.0.0.1'),
        (0, u'Installation: /opt/mqm (Installation1), Default: NO'),
    ]
    assert expected == actual
Exemplo n.º 2
0
def test_ended_preemtively():
    lines = """\
QMNAME(THE.ENDED.ONE)                                     STATUS(ENDED PREEMPTIVELY) DEFAULT(NO) STANDBY(NOT APPLICABLE) INSTNAME(Installation1) INSTPATH(/opt/mqm) INSTVER(7.5.0.2)
"""
    section = parse_info(lines, chr(10))
    check = Check(CHECK_NAME)
    parsed = check.run_parse(section)
    params: Dict[str, Any] = {}
    actual = list(check.run_check('THE.ENDED.ONE', params, parsed))
    expected = [
        (1, u'Status: ENDED PREEMPTIVELY'),
        (0, u'Version: 7.5.0.2'),
        (0, u'Installation: /opt/mqm (Installation1), Default: NO'),
    ]
    assert expected == actual

    lines = """\
QMNAME(THE.ENDED.ONE)                                     STATUS(ENDED PRE-EMPTIVELY) DEFAULT(NO) STANDBY(NOT APPLICABLE) INSTNAME(Installation1) INSTPATH(/opt/mqm) INSTVER(8.0.0.1)
"""
    section = parse_info(lines, chr(10))
    parsed = check.run_parse(section)
    actual = list(check.run_check('THE.ENDED.ONE', params, parsed))
    expected = [
        (1, u'Status: ENDED PRE-EMPTIVELY'),
        (0, u'Version: 8.0.0.1'),
        (0, u'Installation: /opt/mqm (Installation1), Default: NO'),
    ]
    assert expected == actual
Exemplo n.º 3
0
def test_check_win_license(capture, result):
    check = Check("win_license")
    output = check.run_check(None, result.parameters
                             or check.default_parameters(),
                             check.run_parse(splitter(capture)))

    assertCheckResultsEqual(CheckResult(output), result.check_output)
Exemplo n.º 4
0
def test_parse_svrconn_with_multiple_instances():
    lines = """\
QMNAME(MY.TEST)                                           STATUS(RUNNING) NOW(2020-04-03T17:27:02+0200)
5724-H72 (C) Copyright IBM Corp. 1994, 2015.
Starting MQSC for queue manager MY.TEST.

AMQ8417: Display Channel Status details.
   CHANNEL(XXXXXX.IIB.SVRCONN)             CHLTYPE(SVRCONN)
   CONNAME(10.25.19.182)                   CURRENT
   STATUS(RUNNING)                         SUBSTATE(RECEIVE)
AMQ8417: Display Channel Status details.
   CHANNEL(XXXXXX.IIB.SVRCONN)             CHLTYPE(SVRCONN)
   CONNAME(10.25.19.183)                   CURRENT
   STATUS(RUNNING)                         SUBSTATE(RECEIVE)
One MQSC commands read.
No commands have a syntax error.
All valid MQSC commands were processed.
"""
    section = parse_info(lines, chr(10))
    check = Check(CHECK_NAME)
    parsed = check.run_parse(section)
    attrs = parsed['MY.TEST:XXXXXX.IIB.SVRCONN']
    assert attrs['CHLTYPE'] == 'SVRCONN'
    assert attrs['STATUS'] == 'RUNNING'
    # Last entry of the instances defines the values
    assert attrs['CONNAME'] == '10.25.19.183'
Exemplo n.º 5
0
def test_parse():
    lines = """\
QMNAME(THE.LOCAL.ONE)                                     STATUS(RUNNING) DEFAULT(NO) STANDBY(NOT PERMITTED) INSTNAME(Installation1) INSTPATH(/opt/mqm) INSTVER(8.0.0.6) HA() DRROLE()
   INSTANCE(sb112233) MODE(ACTIVE)
QMNAME(THE.MULTI.INSTANCE.ONE)                            STATUS(RUNNING) DEFAULT(NO) STANDBY(PERMITTED) INSTNAME(Installation1) INSTPATH(/opt/mqm) INSTVER(8.0.0.6) HA() DRROLE()
   INSTANCE(sb112233) MODE(ACTIVE)
   INSTANCE(sb112255) MODE(STANDBY)
QMNAME(THE.RDQM.ONE)                                      STATUS(RUNNING) DEFAULT(NO) STANDBY(NOT PERMITTED) INSTNAME(Installation1) INSTPATH(/opt/mqm) INSTVER(9.1.0.4) HA(REPLICATED) DRROLE()
    INSTANCE(sb008877) MODE(ACTIVE)
QMNAME(THE.SLEEPING.ONE)                                  STATUS(ENDED NORMALLY) DEFAULT(NO) STANDBY(NOT APPLICABLE) INSTNAME(Installation1) INSTPATH(/opt/mqm) INSTVER(7.5.0.1) HA() DRROLE()
QMNAME(THE.CRASHED.ONE)                                   STATUS(ENDED UNEXPECTEDLY) DEFAULT(NO) STANDBY(NOT APPLICABLE) INSTNAME(Installation2) INSTPATH(/opt/mqm9) INSTVER(9.0.0.6) HA() DRROLE()
"""
    section = parse_info(lines, chr(10))
    check = Check(CHECK_NAME)
    parsed = check.run_parse(section)
    assert len(parsed) == 5

    attrs = parsed["THE.LOCAL.ONE"]
    assert attrs['STATUS'] == 'RUNNING'
    assert [(u'sb112233', u'ACTIVE')] == attrs['INSTANCES']

    attrs = parsed["THE.MULTI.INSTANCE.ONE"]
    assert [(u'sb112233', u'ACTIVE'), (u'sb112255', u'STANDBY')] \
            == attrs['INSTANCES']

    attrs = parsed["THE.CRASHED.ONE"]
    assert attrs['QMNAME'] == 'THE.CRASHED.ONE'
    assert attrs['STATUS'] == 'ENDED UNEXPECTEDLY'
    assert attrs['STANDBY'] == 'NOT APPLICABLE'
    assert 'INSTANCES' not in attrs
Exemplo n.º 6
0
def test_check_fileinfo_group_patterns(info, group_pattern, expected_result):
    fileinfo_groups_check = Check('fileinfo.groups')
    fileinfo_single_check = Check('fileinfo')
    assert expected_result == list(
        fileinfo_groups_check.run_check(
            'banana',
            group_pattern,
            fileinfo_single_check.run_parse(info),
        ))
Exemplo n.º 7
0
def test_parse():
    lines = """\
QMNAME(MY.TEST)                                           STATUS(RUNNING) NOW(2020-04-03T17:27:02+0200)
5724-H72 (C) Copyright IBM Corp. 1994, 2015.
Starting MQSC for queue manager MY.TEST.

AMQ8414: Display Channel details.
   CHANNEL(HERE.TO.THERE.ONE)              CHLTYPE(SDR)
   XMITQ(HERE.TO.THERE.ONE.XMIT)
AMQ8414: Display Channel details.
   CHANNEL(HERE.TO.THERE.TWO)              CHLTYPE(SDR)
   XMITQ(HERE.TO.THERE.TWO.XMIT)
AMQ8414: Display Channel details.
   CHANNEL(SYSTEM.DEF.SENDER)              CHLTYPE(SDR)
   XMITQ( )
AMQ8417: Display Channel Status details.
   CHANNEL(HERE.TO.THERE.TWO)              CHLTYPE(SDR)
   COMPRATE(0,0)                           COMPTIME(0,0)
   CONNAME(55.888.222.333(1414),22,333.444.555(1414))
   EXITTIME(0,0)                           MONCHL(OFF)
   CURRENT                                 RQMNAME( )
   STATUS(RETRYING)                        SUBSTATE( )
   XBATCHSZ(0,0)                           XMITQ(HERE.TO.THERE.TWO.XMIT)
   XQTIME(0,1)
AMQ8417: Display Channel Status details.
   CHANNEL(HERE.TO.THERE.ONE)              CHLTYPE(SDR)
   COMPRATE(0,0)                           COMPTIME(0,0)
   CONNAME(62.240.197.243(1414),62.240.197.244(1414))
   EXITTIME(0,0)                           MONCHL(OFF)
   CURRENT                                 RQMNAME( )
   STATUS(RETRYING)                        SUBSTATE(MQGET)
   XBATCHSZ(0,0)                           XMITQ(HERE.TO.THERE.TWO.XMIT)
   XQTIME(0,1)
5 MQSC commands read.
No commands have a syntax error.
All valid MQSC commands were processed.
"""
    section = parse_info(lines, chr(10))
    check = Check(CHECK_NAME)
    parsed = check.run_parse(section)
    assert 2 + 1 == len(parsed)

    attrs = parsed['MY.TEST']
    assert attrs['STATUS'] == 'RUNNING'
    assert attrs['NOW'] is not None

    attrs = parsed['MY.TEST:HERE.TO.THERE.TWO']
    assert attrs['CHLTYPE'] == 'SDR'
    assert attrs['STATUS'] == 'RETRYING'
    assert attrs['CONNAME'] == '55.888.222.333(1414),22,333.444.555(1414)'
    assert attrs['MONCHL'] == 'OFF'

    attrs = parsed['MY.TEST:HERE.TO.THERE.TWO']
    assert attrs['CHLTYPE'] == 'SDR'
    assert attrs['STATUS'] == 'RETRYING'
    assert attrs['CONNAME'] == '55.888.222.333(1414),22,333.444.555(1414)'
    assert attrs['MONCHL'] == 'OFF'
Exemplo n.º 8
0
def test_f5_bigip_mem_discovery(info, result):
    mem_total, mem_used, items = result
    check = Check("f5_bigip_mem")
    parsed = check.run_parse(info)

    assert list(check.run_discovery(parsed)) == items

    if items:
        assert parsed["total"] == (mem_total, mem_used)
def test_check_docker_node_disk_usage():
    check = Check("docker_node_disk_usage")
    result = list(check.run_check('volumes', {}, check.run_parse(AGENT_OUTPUT)))
    assert result == [
        (0, 'Size: 229.67 kB', [('size', 235177, None, None)]),
        (0, 'Reclaimable: 93.00 B', [('reclaimable', 93, None, None)]),
        (0, 'Count: 7', [('count', 7, None, None)]),
        (0, 'Active: 5', [('active', 5, None, None)]),
    ]
def test_docker_container_diskstat_check(mocker, monkeypatch):
    mocker.patch("cmk.base.item_state._get_counter", return_value=[None, 2.22])
    check = Check('docker_container_diskstat')
    result = check.run_check('dm-1', {}, check.run_parse(INFO))
    assert list(result) == [
        (0, 'Read: 2.22 B/s', [('disk_read_throughput', 2.22, None, None)]),
        (0, 'Write: 2.22 B/s', [('disk_write_throughput', 2.22, None, None)]),
        (0, 'Read operations: 2.22 1/s', [('disk_read_ios', 2.22, None, None)]),
        (0, 'Write operations: 2.22 1/s', [('disk_write_ios', 2.22, None, None)]),
    ]
def test_docker_container_diskstat_wrapped():
    check = Check('docker_container_diskstat')
    parsed = check.run_parse(INFO_MISSING_COUNTERS)

    with pytest.raises(MKCounterWrapped):
        check.run_check("SUMMARY", {}, parsed)

    with MockItemState((0, 0)):
        # raise MKCounterWrapped anyway, because counters are missing in info
        with pytest.raises(MKCounterWrapped):
            check.run_check("SUMMARY", {}, parsed)
Exemplo n.º 12
0
def test_health_parse_yields_volume_name_as_items_despite_of_durable_id():
    info = [["volume", "1", "durable-id", "Foo 1"], ["volume", "1", "volume-name", "Bar 1"],
            ["volume", "1", "any-key-1", "abc"], ["volume-statistics", "1", "volume-name", "Bar 1"],
            ["volume-statistics", "1", "any-key-2", "ABC"], ["volume", "2", "durable-id", "Foo 2"],
            ["volume", "2", "volume-name", "Bar 2"], ["volume", "2", "any-key-2", "abc"],
            ["volume-statistics", "2", "volume-name", "Bar 2"],
            ["volume-statistics", "2", "any-key-2", "ABC"]]
    check = Check("hp_msa_volume")
    parse_result = check.run_parse(info)
    parsed_items = sorted(parse_result.keys())
    expected_items = ['Bar 1', 'Bar 2']
    assert parsed_items == expected_items
Exemplo n.º 13
0
def test_check_fileinfo_group_no_files(info, parsed, expected_result):
    '''Test that the check returns an OK status when there are no files.'''

    fileinfo_groups_check = Check('fileinfo.groups')
    fileinfo_single_check = Check('fileinfo')
    assert fileinfo_single_check.run_parse(info) == parsed
    assert not fileinfo_groups_check.run_discovery(parsed)
    assert expected_result == list(
        fileinfo_groups_check.run_check(
            'banana',
            {'group_patterns': [('/banana/*', '')]},
            parsed,
        ))
Exemplo n.º 14
0
def test_wmi_msexch_isclienttype_wato_params(check_name, expected):
    check = Check(check_name)
    result = list(
        check.run_check(
            item="_total",
            params={
                'store_latency': (41.0, 51.0),
                'clienttype_latency': (40.0, 50.0),
                'clienttype_requests': (60, 70),
            },
            info=check.run_parse(info_msx_info_store_1),
        ))
    assert result == expected
Exemplo n.º 15
0
def test_hr_ps_discovery(info, discovery_params, expected_discovery_result):
    '''Test that the hr_ps check returns the correct discovery results given different
    discovery parameters.
    '''
    check = Check('hr_ps')

    with MockHostExtraConf(check, discovery_params, 'host_extra_conf'):
        actual_discovery_result = check.run_discovery(check.run_parse(info))

    assertDiscoveryResultsEqual(
        check,
        DiscoveryResult(actual_discovery_result),
        DiscoveryResult(expected_discovery_result),
    )
Exemplo n.º 16
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.'''

    fileinfo_groups_check = Check('fileinfo.groups')
    fileinfo_single_check = Check('fileinfo')
    actual_parsed = fileinfo_single_check.run_parse(info)
    assert parsed['reftime'] == actual_parsed['reftime']
    assert list(parsed['files']) == list(actual_parsed['files'])
    assert expected_result == list(
        fileinfo_groups_check.run_check(
            'banana',
            {'group_patterns': [('/banana/*', '')]},
            parsed,
        ))
Exemplo n.º 17
0
def test_parse():
    lines = """\
version: 2.0.4
dspmq: OK
runmqsc: Not executable
"""
    section = parse_info(lines, chr(58))
    check = Check(CHECK_NAME)
    actual = check.run_parse(section)
    expected = {
        'version': '2.0.4',
        'dspmq': 'OK',
        'runmqsc': 'Not executable',
    }
    assert actual == expected
Exemplo n.º 18
0
def test_parse():
    lines = """\
QMNAME(MY.TEST)                                           STATUS(RUNNING) NOW(2020-04-03T17:27:02+0200)
5724-H72 (C) Copyright IBM Corp. 1994, 2015.
Starting MQSC for queue manager MY.TEST.


AMQ8409: Display Queue details.
   QUEUE(MY.QUEUE.ONE)
   TYPE(QLOCAL)                            MAXDEPTH(5000)
AMQ8409: Display Queue details.
   QUEUE(MY.QUEUE.TWO)
   TYPE(QLOCAL)                            MAXDEPTH(200000)
AMQ8450: Display queue status details.
   QUEUE(MY.QUEUE.ONE)
   TYPE(QUEUE)                             CURDEPTH(0)
   LGETDATE( )                             LGETTIME( )
   LPUTDATE( )                             LPUTTIME( )
   MONQ(MEDIUM)                            MSGAGE(0)
   QTIME( , )
AMQ8450: Display queue status details.
   QUEUE(MY.QUEUE.TWO)
   TYPE(QUEUE)                             CURDEPTH(1400)
   LGETDATE(2017-03-09)                    LGETTIME(08.49.13)
   LPUTDATE( )                             LPUTTIME( )
   OPPROCS(0)                              IPPROCS(5)
   MONQ(MEDIUM)                            MSGAGE(2201)
   QTIME(999999999, 999999999)
2 MQSC commands read.
No commands have a syntax error.
All valid MQSC commands were processed.
"""
    section = parse_info(lines, chr(10))
    check = Check(CHECK_NAME)
    parsed = check.run_parse(section)
    assert 2 + 1 == len(parsed)

    attrs = parsed['MY.TEST']
    assert attrs['STATUS'] == 'RUNNING'
    assert attrs['NOW'] is not None

    attrs = parsed['MY.TEST:MY.QUEUE.TWO']
    assert attrs['CURDEPTH'] == '1400'
    assert attrs['LGETDATE'] == '2017-03-09'
    assert attrs['LGETTIME'] == '08.49.13'
    assert attrs['CURDEPTH'] == '1400'
    assert attrs['MAXDEPTH'] == '200000'
    assert attrs['MSGAGE'] == '2201'
Exemplo n.º 19
0
def test_version_mismatch():
    lines = """\
QMNAME(MTAVBS0P)                                          STATUS(RUNNING) DEFAULT(NO) STANDBY(NOT APPLICABLE) INSTNAME(Installation1) INSTPATH(/opt/mqm) INSTVER(7.5.0.2)
"""
    section = parse_info(lines, chr(10))
    check = Check(CHECK_NAME)
    parsed = check.run_parse(section)
    params = factory_settings['ibm_mq_managers_default_levels']
    params.update({'version': ('at_least', '8.0')})
    actual = list(check.run_check('MTAVBS0P', params, parsed))
    expected = [
        (0, u'Status: RUNNING'),
        (2, u'Version: 7.5.0.2 (should be at least 8.0)'),
        (0, u'Installation: /opt/mqm (Installation1), Default: NO'),
    ]
    assert expected == actual
Exemplo n.º 20
0
def test_version_mismatch():
    lines = """\
QMNAME(THE.RUNNING.ONE)                                   STATUS(RUNNING) DEFAULT(NO) STANDBY(NOT APPLICABLE) INSTNAME(Installation1) INSTPATH(/opt/mqm) INSTVER(7.5.0.2)
"""
    section = parse_info(lines, chr(10))
    check = Check(CHECK_NAME)
    parsed = check.run_parse(section)
    params: Dict[str, Any] = {}
    params.update({'version': (('at_least', '8.0'), 2)})
    actual = list(check.run_check('THE.RUNNING.ONE', params, parsed))
    expected = [
        (0, u'Status: RUNNING'),
        (2, u'Version: 7.5.0.2 (should be at least 8.0)'),
        (0, u'Installation: /opt/mqm (Installation1), Default: NO'),
    ]
    assert expected == actual
Exemplo n.º 21
0
def test_check_fileinfo_group_count_size(info, expected_result):
    '''Test that the fileinfo.groups check counts and adds up the size of all files
    within the file group, regardless of any additional rules. Test that it counts
    the files and adds the file size of files within file groups correctly.'''
    fileinfo_groups_check = Check('fileinfo.groups')
    fileinfo_single_check = Check('fileinfo')
    assert expected_result == list(
        fileinfo_groups_check.run_check(
            'banana',
            {
                'group_patterns': [('/var/log/*', '')],
                'additional_rules': [
                    ('/var/log/sys*', {
                        'minage_oldest': (1.0, 2.0)
                    }),
                ],
            },
            fileinfo_single_check.run_parse(info),
        ))
Exemplo n.º 22
0
def test_status_wato_override():
    lines = """\
QMNAME(THE.ENDED.ONE)                                     STATUS(ENDED PRE-EMPTIVELY) DEFAULT(NO) STANDBY(NOT APPLICABLE) INSTNAME(Installation1) INSTPATH(/opt/mqm) INSTVER(7.5.0.2)
"""
    section = parse_info(lines, chr(10))
    check = Check(CHECK_NAME)
    parsed = check.run_parse(section)

    # Factory defaults
    params: Dict[str, Any] = {}
    actual = list(check.run_check('THE.ENDED.ONE', params, parsed))
    expected = [
        (1, u'Status: ENDED PRE-EMPTIVELY'),
        (0, u'Version: 7.5.0.2'),
        (0, u'Installation: /opt/mqm (Installation1), Default: NO'),
    ]
    assert expected == actual

    # Override factory defaults
    params = {'mapped_states': [('ended_pre_emptively', 2)]}
    actual = list(check.run_check('THE.ENDED.ONE', params, parsed))
    expected = [
        (2, u'Status: ENDED PRE-EMPTIVELY'),
        (0, u'Version: 7.5.0.2'),
        (0, u'Installation: /opt/mqm (Installation1), Default: NO'),
    ]
    assert expected == actual

    # Override-does-not-match configuration
    params = {
        'mapped_states': [('running_as_standby', 2)],
        'mapped_states_default': 3,
    }
    actual = list(check.run_check('THE.ENDED.ONE', params, parsed))
    expected = [
        (3, u'Status: ENDED PRE-EMPTIVELY'),
        (0, u'Version: 7.5.0.2'),
        (0, u'Installation: /opt/mqm (Installation1), Default: NO'),
    ]
    assert expected == actual
def test_nfsmounts(info, discovery_expected, check_expected):
    check_nfs = Check("nfsmounts")
    check_cifs = Check("cifsmounts")

    # assure that the code of both checks is identical
    assert (check_nfs.info['parse_function'].__code__.co_code ==
            check_cifs.info['parse_function'].__code__.co_code)
    assert (check_nfs.info['inventory_function'].__code__.co_code ==
            check_cifs.info['inventory_function'].__code__.co_code)
    assert (check_nfs.info['check_function'].__code__.co_code ==
            check_cifs.info['check_function'].__code__.co_code)

    parsed = check_nfs.run_parse(info)

    assertDiscoveryResultsEqual(
        check_nfs,
        DiscoveryResult(check_nfs.run_discovery(parsed)),  #
        DiscoveryResult(discovery_expected))

    for item, params, result_expected in check_expected:
        result = CheckResult(check_nfs.run_check(item, params, parsed))
        assertCheckResultsEqual(result, CheckResult([result_expected]))
Exemplo n.º 24
0
def test_check_single_instance_running():
    lines = """\
QMNAME(THE.LOCAL.ONE)                                     STATUS(RUNNING) DEFAULT(NO) STANDBY(NOT PERMITTED) INSTNAME(Installation1) INSTPATH(/opt/mqm) INSTVER(8.0.0.6)
   INSTANCE(sb112233) MODE(ACTIVE)
"""
    section = parse_info(lines, chr(10))
    check = Check(CHECK_NAME)
    parsed = check.run_parse(section)

    attrs = parsed["THE.LOCAL.ONE"]
    assert attrs['QMNAME'] == 'THE.LOCAL.ONE'
    assert attrs['STATUS'] == 'RUNNING'

    params: Dict[str, Any] = {}
    actual = list(check.run_check('THE.LOCAL.ONE', params, parsed))
    expected = [
        (0, u'Status: RUNNING'),
        (0, u'Version: 8.0.0.6'),
        (0, u'Installation: /opt/mqm (Installation1), Default: NO'),
        (0, u'Single-Instance: sb112233=ACTIVE'),
    ]
    assert expected == actual
Exemplo n.º 25
0
def run_test_on_parse(dataset, immu):
    """Test parse function

    If dataset has .info attribute and the check has parse function defined,
    test it, and return the result. Otherwise return None.
    If the .parsed attribute is present, it is compared to the result.
    """
    print("parse: %r" % (dataset.checkname, ))
    info = getattr(dataset, 'info', None)
    parsed_expected = getattr(dataset, 'parsed', None)

    if info is None:
        return None

    immu.register(dataset.info, 'info')
    try:
        main_check = Check(dataset.checkname)
        parse_function = main_check.info.get("parse_function")
    except MissingCheckInfoError:
        # this could be ok -
        # it just implies we don't have a parse function
        parse_function = None

    if parsed_expected is not None:
        # we *must* have a parse function in this case!
        assert parse_function, "%s has no parse function!" % (
            dataset.checkname, )
    elif not parse_function:  # we may not have one:
        return None

    parsed = main_check.run_parse(info)
    if parsed_expected is not None:
        assertEqual(parsed, parsed_expected, ' parsed result ')

    immu.test(' after parse function ')
    immu.register(parsed, 'parsed')

    return parsed
Exemplo n.º 26
0
def test_rdqm():
    lines = """\
QMNAME(THE.RDQM.ONE)                                      STATUS(RUNNING) DEFAULT(NO) STANDBY(NOT PERMITTED) INSTNAME(Installation1) INSTPATH(/opt/mqm) INSTVER(9.1.0.4) HA(REPLICATED) DRROLE()
    INSTANCE(sb008877) MODE(ACTIVE)
QMNAME(THE.STANDBY.RDQM)                                  STATUS(RUNNING ELSEWHERE) DEFAULT(NO) STANDBY(NOT APPLICABLE) INSTNAME(Installation1) INSTPATH(/opt/mqm) INSTVER(9.2.0.0) HA(REPLICATED) DRROLE()
"""
    section = parse_info(lines, chr(10))
    check = Check(CHECK_NAME)
    parsed = check.run_parse(section)

    attrs = parsed["THE.RDQM.ONE"]
    assert attrs['QMNAME'] == 'THE.RDQM.ONE'
    assert attrs['STATUS'] == 'RUNNING'

    params: Dict[str, Any] = {}
    actual = list(check.run_check('THE.RDQM.ONE', params, parsed))
    expected = [
        (0, u'Status: RUNNING'),
        (0, u'Version: 9.1.0.4'),
        (0, u'Installation: /opt/mqm (Installation1), Default: NO'),
        (0, u'Single-Instance: sb008877=ACTIVE'),
    ]
    assert expected == actual
Exemplo n.º 27
0
def test_fileinfo_min_max_age_levels():
    check = Check("prism_containers")

    item = u"prism-item"
    parsed = check.run_parse([
        [u'name', u'usage', u'capacity'],
        [u'prism-item', u'5', u'10'],
    ])

    output_expected = [
        BasicCheckResult(
            0,
            "Total: 10.00 B",
        ),
        BasicCheckResult(
            1,
            "Used: 5.00 B (warn/crit at 4.00 B/6.00 B)",
            [
                PerfValue('fs_used', 5, 4, 6, None, None),
            ],
        ),
    ]

    # percent levels
    output_perc_levels = check.run_check(item, {"levels": (40.0, 60.0)},
                                         parsed)
    assertCheckResultsEqual(
        CheckResult(output_perc_levels),
        CheckResult(output_expected),
    )

    # absolute levels
    output_abs_levels = check.run_check(item, {"levels": (4, 6)}, parsed)
    assertCheckResultsEqual(
        CheckResult(output_abs_levels),
        CheckResult(output_expected),
    )
def test_docker_container_diskstat_discovery(info, discovery_expected):
    check = Check('docker_container_diskstat')
    parsed = check.run_parse(info)
    discovery_actual = DiscoveryResult(check.run_discovery(parsed))
    assertDiscoveryResultsEqual(check, discovery_actual, discovery_expected)
Exemplo n.º 29
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
Exemplo n.º 30
0
def test_multipath_parse_groups(group, result):
    check = Check("multipath")
    assert result in check.run_parse([group])