Exemple #1
0
def test_discovery_qmgr_not_included():
    check = Check(CHECK_NAME)
    parsed = {
        'QM1': {
            'STATUS': 'RUNNING'
        },
        'QM2': {
            'STATUS': 'RUNNING'
        },
        'QM1:QUEUE1': {
            'CURDEPTH': '0'
        },
        'QM1:QUEUE2': {
            'CURDEPTH': '1400'
        },
        'QM2:QUEUE3': {
            'CURDEPTH': '530'
        },
        'QM2:QUEUE4': {
            'CURDEPTH': '10'
        },
    }
    discovery = list(check.run_discovery(parsed))
    assert len(discovery) == 4
    assert ('QM1:QUEUE2', {}) in discovery
    assert ('QM2:QUEUE3', {}) in discovery
Exemple #2
0
def test_df_discovery_groups_with_parse(inventory_df_rules, filesystem_groups,
                                        expected_result):
    check = Check('df')

    def mocked_host_extra_conf_merged(_hostname, ruleset):
        if ruleset is check.context.get("inventory_df_rules"):
            return inventory_df_rules
        raise AssertionError(
            "Unknown/unhandled ruleset 'inventory_df_rules' used in mock of host_extra_conf_merged"
        )

    def mocked_host_extra_conf(_hostname, ruleset):
        if ruleset is check.context.get("filesystem_groups"):
            return filesystem_groups
        raise AssertionError(
            "Unknown/unhandled ruleset 'filesystem_groups' used in mock of host_extra_conf"
        )

    with MockHostExtraConf(check, mocked_host_extra_conf_merged,
                           "host_extra_conf_merged"):
        with MockHostExtraConf(check, mocked_host_extra_conf,
                               "host_extra_conf"):
            raw_discovery_result = check.run_discovery(
                parse_df(info_df_groups))
            discovery_result = DiscoveryResult(raw_discovery_result)

    expected_result = DiscoveryResult(expected_result)
    assertDiscoveryResultsEqual(check, discovery_result, expected_result)
def test_inventory_function(info, item_expected, data_expected):
    """
    Verifies if the item is detected corresponding to info content.
    """
    check = Check("alcatel_temp")
    result = list(check.run_discovery(info))
    assert result[0][0] == item_expected
    assert result[0][1] == data_expected
Exemple #4
0
def test_f5_bigip_mem_tmm_discovery(info, result):
    parsed = Check("f5_bigip_mem").run_parse(info)
    check = Check("f5_bigip_mem.tmm")

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

    if result:
        assert parsed["TMM"] == (1024.0, 0.0)
Exemple #5
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)
Exemple #6
0
def test_jolokia_generic_discovery(check, lines, expected_result):
    parsed = Check('jolokia_generic').run_parse(lines)

    check = Check(check)
    discovered = check.run_discovery(parsed)
    assertDiscoveryResultsEqual(
        check,
        DiscoveryResult(discovered),
        DiscoveryResult(expected_result),
    )
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,
        ))
Exemple #8
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),
    )
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]))
Exemple #10
0
def test_discovery_qmgr_not_included():
    check = Check(CHECK_NAME)
    parsed = {
        'QM1': {
            'STATUS': 'RUNNING'
        },
        'QM1:CHAN1': {
            'CHLTYPE': 'SDR',
            'STATUS': 'RETRYING',
            'XMITQ': 'MY.XMIT.Q'
        },
        'QM1:CHAN2': {
            'CHLTYPE': 'RCVR',
            'STATUS': 'STOPPED'
        },
        'QM1:CHAN3': {
            'CHLTYPE': 'SVRCONN'
        },
    }
    discovery = list(check.run_discovery(parsed))
    assert len(discovery) == 3
    assert ('QM1:CHAN2', {}) in discovery
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)
Exemple #12
0
def test_oracle_intance_uptime_discovery(info):
    main_check = Check('oracle_instance')
    check = Check('oracle_instance.uptime')
    assert list(check.run_discovery(main_check.run_parse(info))) == []
Exemple #13
0
def test_ceph_df_octopus_discovery(info, result):
    check = Check("ceph_df")
    parsed = check.run_parse(info)
    assert sorted(check.run_discovery(parsed)) == result
def test_df_discovery_yields_volume_name_as_item():
    parsed = {'Foo': {'durable-id': 'Bar'}}
    expected_yield: Tuple[str, Dict[Any, Any]] = ('Foo', {})
    check = Check("hp_msa_volume.df")
    for item in check.run_discovery(parsed):
        assert item == expected_yield
def test_health_discovery_forwards_info():
    info = [["volume", "1", "volume-name", "Foo"]]
    check = Check("hp_msa_volume")
    discovery_result = check.run_discovery(info)
    assert discovery_result == [(info[0], None)]
def test_io_discovery_yields_summary():
    parsed = {'Foo': {'durable-id': 'Bar'}}
    expected_yield = ('SUMMARY', 'diskstat_default_levels')
    check = Check("hp_msa_volume.io")
    for item in check.run_discovery(parsed):
        assert item == expected_yield
Exemple #17
0
def test_zfsget_discovery(info, expected_discovery_result):
    check_zfsget = Check("zfsget")
    discovery_result = DiscoveryResult(
        check_zfsget.run_discovery(check_zfsget.run_parse(info)))
    assertDiscoveryResultsEqual("zfsget", discovery_result,
                                DiscoveryResult(expected_discovery_result))
Exemple #18
0
def test_ra32e_switch_discovery(info, result):
    check = Check(RA32E_SWITCH)
    assert list(check.run_discovery(info)) == result
Exemple #19
0
def test_wmi_cpu_load_discovery(check_name, info, expected):
    check = Check(check_name)
    discovery_result = DiscoveryResult(
        check.run_discovery(check.run_parse(info)))
    discovery_expected = DiscoveryResult(expected)
    assertDiscoveryResultsEqual(check, discovery_result, discovery_expected)
Exemple #20
0
def test_inventory_function(info, result_expected):
    check = Check(CHECK_NAME)
    result = list(check.run_discovery(info))
    assert result == result_expected
def test_apc_netbotz_drycontact_inventory(parsed, expected):

    check = Check("apc_netbotz_drycontact")
    assert list(check.run_discovery(parsed)) == expected
Exemple #22
0
def test_ra32e_power_discovery(info, result):
    check = Check(RA32E_POWER)
    assert check.run_discovery(info) == result
Exemple #23
0
def test_parse_and_discovery_function(info, result):
    check = Check("lnx_thermal")
    parsed = check.run_parse(info)
    discovery = DiscoveryResult(check.run_discovery(parsed))
    assertDiscoveryResultsEqual(check, discovery, DiscoveryResult(result))
def test_discovery_mbg_lantime_ng_refclock_gps(info, expected):
    check = Check("mbg_lantime_ng_refclock.gps")
    discovery = DiscoveryResult(check.run_discovery(info))
    assertDiscoveryResultsEqual(check, discovery, expected)
Exemple #25
0
def test_oracle_jobs_discovery_error(info):
    check = Check('oracle_jobs')
    assert list(check.run_discovery(info)) == []