def test_single_instance_counter(Aggregator, pdh_mocks_fixture):
    initialize_pdh_tests()
    instance = DEFAULT_INSTANCE
    c = PDHBaseCheck("testcheck", {}, {}, [instance], SINGLE_INSTANCE_COUNTER)
    c.check(instance)

    Aggregator.assert_metric("test.system.mem.available", tags=None, count=1)
Beispiel #2
0
def test_winpdhcounter_throws_on_bad_input(pdh_mocks_fixture):  # noqa F811
    initialize_pdh_tests()
    with pytest.raises(AttributeError):
        WinPDHCounter('Ssystem', 'Processor Queue Length', logger)

    with pytest.raises(AttributeError):
        WinPDHCounter('System', 'PProcessor Queue Length', logger)
Beispiel #3
0
def test_winpdhcounter_bad_strings_english(
        pdh_mocks_fixture_bad_perf_strings):  # noqa F811
    initialize_pdh_tests()
    counter = WinPDHCounter('System', 'Processor Queue Length', logger)

    vals = counter.get_all_values()
    assert len(vals) == 1  # single instance key, should only have one value
    assert SINGLE_INSTANCE_KEY in vals
Beispiel #4
0
def test_default_admin_share():
    initialize_pdh_tests()
    c = PDHBaseCheck("testcheck", {}, [DEFAULT_INSTANCE],
                     SINGLE_INSTANCE_COUNTER)
    nr = c._get_netresource('1.1.1.1')
    assert nr.lpRemoteName == '\\\\1.1.1.1\\c$'
    assert nr.dwType == 0
    assert nr.lpLocalName is None
Beispiel #5
0
def test_winpdhcounter_non_english(pdh_mocks_fixture):  # noqa F811
    WinPDHCounter._use_en_counter_names = False
    WinPDHCounter.pdh_counter_dict = defaultdict(list)
    initialize_pdh_tests(lang="se-sv")
    counter = WinPDHCounter('System', 'Processor Queue Length', logger)

    vals = counter.get_all_values()
    assert len(vals) == 1  # single instance key, should only have one value
    assert SINGLE_INSTANCE_KEY in vals
Beispiel #6
0
def test_service_check_with_invalid_host(Aggregator, pdh_mocks_fixture):
    initialize_pdh_tests()
    instance = INVALID_HOST_INSTANCE
    c = IIS(CHECK_NAME, {}, {}, [instance])
    c.check(instance)

    Aggregator.assert_service_check('iis.site_up',
                                    IIS.CRITICAL,
                                    tags=["site:{0}".format('Total')])
Beispiel #7
0
def test_additional_metrics(aggregator, pdh_mocks_fixture):  # noqa F811
    initialize_pdh_tests()
    instance = copy.deepcopy(DEFAULT_INSTANCE)
    instance['additional_metrics'] = SINGLE_INSTANCE_COUNTER

    c = PDHBaseCheck("testcheck", {}, [instance], counter_list=[])
    c.check(instance)

    aggregator.assert_metric("test.system.mem.available", tags=None, count=1)
def test_multi_instance_counter(aggregator, pdh_mocks_fixture):  # noqa F811
    initialize_pdh_tests()
    instance = DEFAULT_INSTANCE
    c = PDHBaseCheck("testcheck", {}, {}, [instance], MULTI_INSTANCE_COUNTER)
    c.check(instance)
    for t in ['instance:0', 'instance:1', 'instance:_Total']:
        aggregator.assert_metric("test.processor_time",
                                 tags=['%s' % t],
                                 count=1)
    assert aggregator.metrics_asserted_pct == 100.0
def test_multi_instance_counter_specific_instances(
        aggregator, pdh_mocks_fixture):  # noqa F811
    initialize_pdh_tests()
    instance = DEFAULT_INSTANCE
    c = PDHBaseCheck("testcheck", {}, {}, [instance],
                     MULTI_INSTANCE_COUNTER_WITH_INSTANCES)
    c.check(instance)
    for t in ['test.processor_time_0', 'test.processor_time_1']:
        aggregator.assert_metric(t, tags=None, count=1)
    assert aggregator.metrics_asserted_pct == 100.0
Beispiel #10
0
def test_basic_check(aggregator):
    initialize_pdh_tests()
    instance = MINIMAL_INSTANCE
    c = ActiveDirectoryCheck(CHECK_NAME, {}, {}, [instance])
    c.check(instance)

    for metric_def in DEFAULT_COUNTERS:
        metric = metric_def[3]
        aggregator.assert_metric(metric, tags=None, count=1)

    assert aggregator.metrics_asserted_pct == 100.0
def test_basic_check(aggregator):
    initialize_pdh_tests()
    instance = MINIMAL_INSTANCE
    c = DotnetclrCheck(CHECK_NAME, {}, {}, [instance])
    c.check(instance)

    for metric_def in DEFAULT_COUNTERS:
        metric = metric_def[3]
        for inst in INSTANCES:
            aggregator.assert_metric(metric, tags=["instance:%s" % inst], count=1)

    assert aggregator.metrics_asserted_pct == 100.0
def test_winpdhcounter_bad_strings_not_english(pdh_mocks_fixture_bad_perf_strings):  # noqa F811
    WinPDHCounter._use_en_counter_names = False
    WinPDHCounter.pdh_counter_dict = defaultdict(list)

    initialize_pdh_tests(lang="se-sv")
    '''
    expectation is that the initialization will fail.  We attempt to fall
    back to english counters if the strings database isn't present; however,
    on non-english windows the english counters won't work
    '''
    with pytest.raises(AttributeError):
        WinPDHCounter('System', 'Processor Queue Length', logger)
Beispiel #13
0
def test_basic_check(aggregator):
    # type: (AggregatorStub) -> None
    initialize_pdh_tests()
    instance = MINIMAL_INSTANCE
    c = ActiveDirectoryCheck(CHECK_NAME, {}, [instance])
    c.check(instance)

    for metric_def in DEFAULT_COUNTERS:
        metric = metric_def[3]
        aggregator.assert_metric(metric, tags=None, count=1)

    aggregator.assert_all_metrics_covered()
    aggregator.assert_metrics_using_metadata(get_metadata_metrics())
def test_basic_check(Aggregator, pdh_mocks_fixture):
    initialize_pdh_tests()
    instance = MINIMAL_INSTANCE
    c = AspdotnetCheck(CHECK_NAME, {}, {}, [instance])
    c.check(instance)

    for metric in ASP_METRICS:
        Aggregator.assert_metric(metric, tags=None, count=1)

    for metric in ASP_APP_METRICS:
        for i in ASP_APP_INSTANCES:
            Aggregator.assert_metric(metric, tags=["instance:%s" % i], count=1)

    assert Aggregator.metrics_asserted_pct == 100.0
Beispiel #15
0
def test_with_tags(Aggregator, pdh_mocks_fixture):  # noqa: F811
    initialize_pdh_tests()
    instance = INSTANCE_WITH_TAGS
    c = AspdotnetCheck(CHECK_NAME, {}, {}, [instance])
    c.check(instance)

    for metric in ASP_METRICS:
        Aggregator.assert_metric(metric, tags=['tag1', 'another:tag'], count=1)

    for metric in ASP_APP_METRICS:
        for i in ASP_APP_INSTANCES:
            Aggregator.assert_metric(metric, tags=['tag1', 'another:tag', "instance:%s" % i], count=1)

    assert aggregator.metrics_asserted_pct == 100.0
def test_basic_check(aggregator):
    """
    Returns the right metrics and service checks
    """
    # Set up & run the check
    config = {'instances': [INSTANCE]}
    initialize_pdh_tests()
    c = PDHCheck(CHECK_NAME, {}, config['instances'])
    c.check(config['instances'][0])

    for metric in INSTANCE_METRICS:
        aggregator.assert_metric(metric, tags=None, count=1)

    aggregator.assert_all_metrics_covered()
def test_basic_check(Aggregator, pdh_mocks_fixture):
    initialize_pdh_tests()
    instance = MINIMAL_INSTANCE
    c = ExchangeCheck(CHECK_NAME, {}, {}, [instance])
    c.check(instance)

    for metric_def in DEFAULT_COUNTERS:
        metric = metric_def[3]
        instances = METRIC_INSTANCES.get(metric)
        if instances is not None:
            for inst in instances:
                Aggregator.assert_metric(metric, tags=["instance:%s" % inst], count=1)
        else:
            Aggregator.assert_metric(metric, tags=None, count=1)

    assert Aggregator.metrics_asserted_pct == 100.0
def test_returns_partial_metrics(Aggregator, pdh_mocks_fixture):
    COUNTER_LIST = [
        [
            "NTDS", None, "LDAP Client Sessions",
            "active_directory.ldap.client_sessions", "gauge"
        ],
        [
            "NTDS", None, "LDAP Bind Time", "active_directory.ldap.bind_time",
            "gauge"
        ],
        [
            "NTDS", None, "LDAP Successful Binds/sec",
            "active_directory.ldap.successful_binds_persec", "gauge"
        ],
        [
            "NTDS", None, "LDAP Searches/sec",
            "active_directory.ldap.searches_persec", "gauge"
        ],

        ## these two don't exist
        [
            "NTDS", None, "Kerberos Authentications/sec",
            "active_directory.kerberos.auths_persec", "gauge"
        ],
        [
            "NTDS", None, "NTLM Authentications/sec",
            "active_directory.ntlm.auths_persec", "gauge"
        ],
    ]
    initialize_pdh_tests()
    instance = DEFAULT_INSTANCE
    c = PDHBaseCheck("testcheck", {}, {}, [instance], COUNTER_LIST)
    c.check(instance)

    Aggregator.assert_metric("active_directory.ldap.client_sessions",
                             tags=None,
                             count=1)
    Aggregator.assert_metric("active_directory.ldap.bind_time",
                             tags=None,
                             count=1)
    Aggregator.assert_metric("active_directory.ldap.successful_binds_persec",
                             tags=None,
                             count=1)
    Aggregator.assert_metric("active_directory.ldap.searches_persec",
                             tags=None,
                             count=1)
    assert Aggregator.metrics_asserted_pct == 100.0
Beispiel #19
0
def test_check(Aggregator, pdh_mocks_fixture):
    """
    Returns the right metrics and service checks
    """
    # Set up & run the check
    config = {'instances': [WIN_SERVICES_CONFIG]}
    initialize_pdh_tests()
    instance = WIN_SERVICES_CONFIG
    c = IIS(CHECK_NAME, {}, {}, [instance])
    c.check(instance)

    # Test metrics
    # ... normalize site-names
    default_site_name = re.sub(r"[,\+\*\-/()\[\]{}\s]", "_",
                               config['instances'][0]['sites'][0])
    ok_site_name = re.sub(r"[,\+\*\-/()\[\]{}\s]", "_",
                          config['instances'][0]['sites'][1])
    fail_site_name = re.sub(r"[,\+\*\-/()\[\]{}\s]", "_",
                            config['instances'][0]['sites'][2])

    for site_name in [default_site_name, ok_site_name, 'Total']:
        for metric_def in DEFAULT_COUNTERS:
            mname = metric_def[3]
            Aggregator.assert_metric(
                mname,
                tags=["mytag1", "mytag2", "site:{0}".format(site_name)],
                count=1)

        Aggregator.assert_service_check(
            'iis.site_up',
            status=IIS.OK,
            tags=["mytag1", "mytag2", "site:{0}".format(site_name)],
            count=1)

    Aggregator.assert_service_check(
        'iis.site_up',
        status=IIS.CRITICAL,
        tags=["mytag1", "mytag2", "site:{0}".format(fail_site_name)],
        count=1)

    # Check completed with no warnings
    # self.assertFalse(logger.warning.called)

    Aggregator.assert_all_metrics_covered()
Beispiel #20
0
def test_returns_partial_metrics(aggregator, pdh_mocks_fixture):  # noqa F811
    initialize_pdh_tests()
    instance = DEFAULT_INSTANCE
    c = PDHBaseCheck("testcheck", {}, [instance], PARTIAL_COUNTER_LIST)
    c.check(instance)

    aggregator.assert_metric("active_directory.ldap.client_sessions",
                             tags=None,
                             count=1)
    aggregator.assert_metric("active_directory.ldap.bind_time",
                             tags=None,
                             count=1)
    aggregator.assert_metric("active_directory.ldap.successful_binds_persec",
                             tags=None,
                             count=1)
    aggregator.assert_metric("active_directory.ldap.searches_persec",
                             tags=None,
                             count=1)
    assert aggregator.metrics_asserted_pct == 100.0
Beispiel #21
0
def test_basic_check(Aggregator, pdh_mocks_fixture):
    initialize_pdh_tests()
    instance = MINIMAL_INSTANCE
    c = IIS(CHECK_NAME, {}, {}, [instance])
    c.check(instance)

    site_tags = ['Default_Web_Site', 'Exchange_Back_End', 'Total']
    for metric_def in DEFAULT_COUNTERS:
        metric = metric_def[3]
        for site_tag in site_tags:
            Aggregator.assert_metric(metric,
                                     tags=["site:{0}".format(site_tag)],
                                     count=1)

    for site_tag in site_tags:
        Aggregator.assert_service_check('iis.site_up',
                                        IIS.OK,
                                        tags=["site:{0}".format(site_tag)],
                                        count=1)

    Aggregator.assert_all_metrics_covered()
Beispiel #22
0
def setup_check():
    initialize_pdh_tests()
def test_single_instance_counter_with_instance(Aggregator, pdh_mocks_fixture):
    initialize_pdh_tests()
    instance = DEFAULT_INSTANCE
    with pytest.raises(AttributeError):
        PDHBaseCheck("testcheck", {}, {}, [instance],
                     INSTANCE_OF_SINGLE_INSTANCE_COUNTER)