예제 #1
0
def test_tags(aggregator, spin_up_powerdns):
    version = _get_pdns_version()

    pdns_check = PowerDNSRecursorCheck(CHECK_NAME, {}, {})
    tags = ['foo:bar']
    if version == 3:
        config = common.CONFIG.copy()
        config['tags'] = ['foo:bar']
        pdns_check.check(config)

        # Assert metrics v3
        for metric in metrics.GAUGE_METRICS:
            aggregator.assert_metric(metrics.METRIC_FORMAT.format(metric), tags=tags, count=1)

        for metric in metrics.RATE_METRICS:
            aggregator.assert_metric(metrics.METRIC_FORMAT.format(metric), tags=tags, count=1)

    elif version == 4:
        config = common.CONFIG_V4.copy()
        config['tags'] = ['foo:bar']
        pdns_check.check(config)

        # Assert metrics v3
        for metric in metrics.GAUGE_METRICS + metrics.GAUGE_METRICS_V4:
            aggregator.assert_metric(metrics.METRIC_FORMAT.format(metric), tags=tags, count=1)

        for metric in metrics.RATE_METRICS + metrics.RATE_METRICS_V4:
            aggregator.assert_metric(metrics.METRIC_FORMAT.format(metric), tags=tags, count=1)

    service_check_tags = common._config_sc_tags(common.CONFIG)
    aggregator.assert_service_check('powerdns.recursor.can_connect',
                                    status=PowerDNSRecursorCheck.OK,
                                    tags=service_check_tags+tags)

    aggregator.assert_all_metrics_covered()
예제 #2
0
def test_very_bad_config(aggregator):
    pdns_check = PowerDNSRecursorCheck(CHECK_NAME, {}, {})
    for config in [{}, {"host": "localhost"}, {"port": 1000}, {"host": "localhost", "port": 1000}]:
        with pytest.raises(Exception):
            pdns_check.check(common.BAD_API_KEY_CONFIG)

    assert len(aggregator._metrics) == 0
예제 #3
0
def test_bad_api_key(aggregator, spin_up_powerdns):
    pdns_check = PowerDNSRecursorCheck(CHECK_NAME, {}, {})
    with pytest.raises(Exception):
        pdns_check.check(common.BAD_API_KEY_CONFIG)

    service_check_tags = common._config_sc_tags(common.BAD_API_KEY_CONFIG)
    aggregator.assert_service_check('powerdns.recursor.can_connect',
                                    status=PowerDNSRecursorCheck.CRITICAL,
                                    tags=service_check_tags)
    assert len(aggregator._metrics) == 0
예제 #4
0
def test_bad_config(aggregator):
    check = PowerDNSRecursorCheck("powerdns_recursor", {}, [common.BAD_CONFIG])
    with pytest.raises(Exception):
        check.check(common.BAD_CONFIG)

    service_check_tags = common._config_sc_tags(common.BAD_CONFIG)
    aggregator.assert_service_check('powerdns.recursor.can_connect',
                                    status=check.CRITICAL,
                                    tags=service_check_tags)
    assert len(aggregator._metrics) == 0
예제 #5
0
def test_very_bad_config(aggregator):
    for config in [{}, {
            "host": "localhost"
    }, {
            "port": 1000
    }, {
            "host": "localhost",
            "port": 1000
    }]:
        check = PowerDNSRecursorCheck("powerdns_recursor", {}, [config])
        with pytest.raises(Exception):
            check.check(config)

    assert len(aggregator._metrics) == 0
예제 #6
0
def test_check(aggregator, spin_up_powerdns):
    service_check_tags = common._config_sc_tags(common.CONFIG)

    # get version and test v3 first.
    version = _get_pdns_version()
    pdns_check = PowerDNSRecursorCheck(CHECK_NAME, {}, {})
    if version == 3:
        pdns_check.check(common.CONFIG)

        # Assert metrics
        for metric in metrics.GAUGE_METRICS:
            aggregator.assert_metric(metrics.METRIC_FORMAT.format(metric),
                                     tags=[],
                                     count=1)

        for metric in metrics.RATE_METRICS:
            aggregator.assert_metric(metrics.METRIC_FORMAT.format(metric),
                                     tags=[],
                                     count=1)

        aggregator.assert_service_check('powerdns.recursor.can_connect',
                                        status=PowerDNSRecursorCheck.OK,
                                        tags=service_check_tags)
        assert aggregator.metrics_asserted_pct == 100.0

    elif version == 4:
        pdns_check.check(common.CONFIG_V4)

        # Assert metrics
        for metric in metrics.GAUGE_METRICS + metrics.GAUGE_METRICS_V4:
            aggregator.assert_metric(metrics.METRIC_FORMAT.format(metric),
                                     tags=[],
                                     count=1)

        for metric in metrics.RATE_METRICS + metrics.RATE_METRICS_V4:
            aggregator.assert_metric(metrics.METRIC_FORMAT.format(metric),
                                     tags=[],
                                     count=1)

        aggregator.assert_service_check('powerdns.recursor.can_connect',
                                        status=PowerDNSRecursorCheck.OK,
                                        tags=service_check_tags)
        assert aggregator.metrics_asserted_pct == 100.0
    else:
        print("powerdns_recursor unknown version.")
        aggregator.assert_service_check('powerdns.recursor.can_connect',
                                        status=PowerDNSRecursorCheck.CRITICAL,
                                        tags=service_check_tags)
def test_check(aggregator):
    # get version and test v3 first.
    version = common._get_pdns_version()
    if version == 3:
        check = PowerDNSRecursorCheck("powerdns_recursor", {}, [common.CONFIG])
        service_check_tags = common._config_sc_tags(common.CONFIG)
        check.check(common.CONFIG)

        # Assert metrics
        for metric in metrics.GAUGE_METRICS:
            aggregator.assert_metric(metrics.METRIC_FORMAT.format(metric),
                                     tags=[],
                                     count=1)

        for metric in metrics.RATE_METRICS:
            aggregator.assert_metric(metrics.METRIC_FORMAT.format(metric),
                                     tags=[],
                                     count=1)

        aggregator.assert_service_check('powerdns.recursor.can_connect',
                                        status=check.OK,
                                        tags=service_check_tags)
        aggregator.assert_all_metrics_covered()

    elif version == 4:
        check = PowerDNSRecursorCheck("powerdns_recursor", {},
                                      [common.CONFIG_V4])
        service_check_tags = common._config_sc_tags(common.CONFIG_V4)
        check.check(common.CONFIG_V4)

        # Assert metrics
        for metric in metrics.GAUGE_METRICS + metrics.GAUGE_METRICS_V4:
            aggregator.assert_metric(metrics.METRIC_FORMAT.format(metric),
                                     tags=[],
                                     count=1)

        for metric in metrics.RATE_METRICS + metrics.RATE_METRICS_V4:
            aggregator.assert_metric(metrics.METRIC_FORMAT.format(metric),
                                     tags=[],
                                     count=1)

        aggregator.assert_service_check('powerdns.recursor.can_connect',
                                        status=check.OK,
                                        tags=service_check_tags)
        aggregator.assert_all_metrics_covered()
    else:
        raise Exception("Version not supported")
def test_tags(aggregator):
    version = common._get_pdns_version()

    tags = ['foo:bar']
    if version == 3:
        config = common.CONFIG.copy()
        config['tags'] = ['foo:bar']
        check = PowerDNSRecursorCheck("powerdns_recursor", {}, [config])
        check.check(config)

        # Assert metrics v3
        for metric in metrics.GAUGE_METRICS:
            aggregator.assert_metric(metrics.METRIC_FORMAT.format(metric),
                                     tags=tags,
                                     count=1)

        for metric in metrics.RATE_METRICS:
            aggregator.assert_metric(metrics.METRIC_FORMAT.format(metric),
                                     tags=tags,
                                     count=1)

    elif version == 4:
        config = common.CONFIG_V4.copy()
        config['tags'] = ['foo:bar']
        check = PowerDNSRecursorCheck("powerdns_recursor", {}, [config])
        check.check(config)

        # Assert metrics v3
        for metric in metrics.GAUGE_METRICS + metrics.GAUGE_METRICS_V4:
            aggregator.assert_metric(metrics.METRIC_FORMAT.format(metric),
                                     tags=tags,
                                     count=1)

        for metric in metrics.RATE_METRICS + metrics.RATE_METRICS_V4:
            aggregator.assert_metric(metrics.METRIC_FORMAT.format(metric),
                                     tags=tags,
                                     count=1)
    else:
        raise Exception("Version not supported")

    service_check_tags = common._config_sc_tags(common.CONFIG)
    aggregator.assert_service_check('powerdns.recursor.can_connect',
                                    status=check.OK,
                                    tags=service_check_tags + tags)

    aggregator.assert_all_metrics_covered()
예제 #9
0
def test_metadata_integration(aggregator, datadog_agent):
    version = common._get_pdns_version()
    if version == 3:
        check = PowerDNSRecursorCheck("powerdns_recursor", {}, [common.CONFIG])
        check.check_id = 'test:123'
        check.check(common.CONFIG)
    elif version == 4:
        check = PowerDNSRecursorCheck("powerdns_recursor", {}, [common.CONFIG_V4])
        check.check_id = 'test:123'
        check.check(common.CONFIG_V4)

    major, minor, patch = common.POWERDNS_RECURSOR_VERSION.split('.')
    version_metadata = {
        'version.scheme': 'semver',
        'version.major': major,
        'version.minor': minor,
        'version.patch': patch,
        'version.raw': common.POWERDNS_RECURSOR_VERSION,
    }

    datadog_agent.assert_metadata('test:123', version_metadata)
    datadog_agent.assert_metadata_count(len(version_metadata))