コード例 #1
0
def test_check_ok(aggregator, spin_up_squid, instance):
    squid_check = SquidCheck(common.CHECK_NAME, {}, {})
    squid_check.check(instance)

    expected_tags = ["name:ok_instance", "custom_tag"]
    aggregator.assert_service_check(common.SERVICE_CHECK, tags=expected_tags, status=squid_check.OK)

    for metric in common.EXPECTED_METRICS:
        aggregator.assert_metric("squid.cachemgr." + metric, tags=expected_tags)
コード例 #2
0
def test_parse_counter(aggregator):
    squid_check = SquidCheck(common.CHECK_NAME, {}, {})

    # Good format
    line = "counter = 0\n"
    counter, value = squid_check.parse_counter(line)
    assert counter == "counter"
    assert value == "0"

    # Bad format
    line = "counter: value\n"
    counter, value = squid_check.parse_counter(line)
    assert counter is None
    assert value is None
コード例 #3
0
def test_legacy_username_password(instance, auth_config):
    instance = deepcopy(instance)
    instance.update(auth_config)
    check = SquidCheck(common.CHECK_NAME, {}, {}, [instance])

    with mock.patch('datadog_checks.base.utils.http.requests.get') as g:
        check.get_counters('host', 'port', [])

        g.assert_called_with(
            'http://host:port/squid-internal-mgr/counters',
            auth=('datadog_user', 'datadog_pass'),
            cert=mock.ANY,
            headers=mock.ANY,
            proxies=mock.ANY,
            timeout=mock.ANY,
            verify=mock.ANY,
        )
コード例 #4
0
def test_parse_instance(aggregator):
    squid_check = SquidCheck(common.CHECK_NAME, {}, {})

    # instance with defaults
    instance = {"name": "ok_instance"}
    name, host, port, cachemgr_user, \
        cachemgr_passwd, custom_tags = squid_check.parse_instance(instance)
    assert name == "ok_instance"
    assert host == "localhost"
    assert port == 3128
    assert cachemgr_user == ""
    assert cachemgr_passwd == ""
    assert custom_tags == []

    # instance with no defaults
    instance = {
        "name": "ok_instance",
        "host": "host",
        "port": 1234,
        "cachemgr_username": "******",
        "cachemgr_password": "******",
        "tags": ["foo:bar"],
    }
    name, host, port, cachemgr_user,\
        cachemgr_passwd, custom_tags = squid_check.parse_instance(instance)
    assert name == "ok_instance"
    assert host == "host"
    assert port == 1234
    assert cachemgr_user == "datadog"
    assert cachemgr_passwd == "pass"
    assert custom_tags == ["foo:bar"]

    # instance with no name
    instance = {"host": "host"}
    with pytest.raises(Exception):
        squid_check.parse_instance(instance)
コード例 #5
0
def test_check_fail(aggregator, spin_up_squid, instance):
    squid_check = SquidCheck(common.CHECK_NAME, {}, {})
    instance["host"] = "bad_host"
    with pytest.raises(Exception):
        squid_check.check(instance)
コード例 #6
0
def check():
    return SquidCheck(common.CHECK_NAME, {}, {})