def test_namespace(self, aggregator):
        check = AgentCheck()
        check.__NAMESPACE__ = 'test'

        check.service_check('service_check', AgentCheck.OK)
        aggregator.assert_service_check('test.service_check',
                                        status=AgentCheck.OK)
Esempio n. 2
0
    def test_sanitize_service_check_message(self, aggregator, caplog):
        # type: (Any, Any) -> None
        secret = 'p@$$w0rd'
        check = AgentCheck()
        check.register_secret(secret)
        sanitized = check.sanitize(secret)

        check.service_check('test.can_check', status=AgentCheck.CRITICAL, message=secret)

        aggregator.assert_service_check('test.can_check', status=AgentCheck.CRITICAL, message=sanitized)
def test_assert_no_duplicate_service_checks_cases(aggregator, case_name, service_checks, expect_assertion_error):
    check = AgentCheck()

    for metric_params in service_checks:
        check.service_check(**metric_params)

    try:
        aggregator.assert_no_duplicate_service_checks()
        assertion_error_raised = False
    except AssertionError:
        assertion_error_raised = True

    assert assertion_error_raised == expect_assertion_error
    def test__build_similar_elements__service_check_hostname(self, aggregator):
        check = AgentCheck()

        check.service_check('test.similar1', AgentCheck.OK, hostname="aa")
        check.service_check('test.similar2', AgentCheck.OK, hostname="bb")
        check.service_check('test.similar3', AgentCheck.OK, hostname="cc")
        check.service_check('test.similar4', AgentCheck.OK, hostname="dd")

        expected_service_check = ServiceCheckStub(
            None, "test.similar", status=AgentCheck.OK, tags=None, hostname="cc", message=None
        )
        similar_service_checks = similar._build_similar_elements(expected_service_check, aggregator._service_checks)

        # expect similar metrics in a similarity order
        assert similar_service_checks[0][1].name == 'test.similar3'
Esempio n. 5
0
    def test_metrics_filters(self, exclude_metrics_filters, include_metrics_filters, expected_metrics, aggregator):
        instance = {
            'metric_patterns': {
                'exclude': exclude_metrics_filters,
                'include': include_metrics_filters,
            }
        }
        check = AgentCheck('myintegration', {}, [instance])
        check.__NAMESPACE__ = 'ns'
        check.gauge('my_metric', 0)
        check.count('my_metric_count', 0)
        check.count('test.my_metric1', 1)
        check.monotonic_count('hello', 0)
        check.service_check('test.can_check', status=AgentCheck.OK)

        for metric_name in expected_metrics:
            aggregator.assert_metric('ns.{}'.format(metric_name), count=1)

        aggregator.assert_service_check('ns.test.can_check', status=AgentCheck.OK)
        aggregator.assert_all_metrics_covered()
    def test_valid_sc(self, aggregator):
        check = AgentCheck()

        check.service_check("testservicecheck",
                            AgentCheck.OK,
                            tags=None,
                            message="")
        aggregator.assert_service_check("testservicecheck",
                                        status=AgentCheck.OK)

        check.service_check(
            "testservicecheckwithhostname",
            AgentCheck.OK,
            tags=["foo", "bar"],
            hostname="testhostname",
            message="a message",
        )
        aggregator.assert_service_check(
            "testservicecheckwithhostname",
            status=AgentCheck.OK,
            tags=["foo", "bar"],
            hostname="testhostname",
            message="a message",
        )

        check.service_check("testservicecheckwithnonemessage",
                            AgentCheck.OK,
                            message=None)
        aggregator.assert_service_check("testservicecheckwithnonemessage",
                                        status=AgentCheck.OK)
Esempio n. 7
0
    def test__build_similar_elements__service_check_tags(self, aggregator):
        check = AgentCheck()

        check.service_check('test.similar2',
                            AgentCheck.OK,
                            tags=['name:less_similar_tag'])
        check.service_check('test.similar1',
                            AgentCheck.OK,
                            tags=['name:similar_tag'])
        check.service_check('test.similar3',
                            AgentCheck.OK,
                            tags=['something:different'])

        expected_service_check = ServiceCheckStub(None,
                                                  "test.similar",
                                                  status=AgentCheck.OK,
                                                  tags=['name:similar_tag'],
                                                  hostname=None,
                                                  message=None)
        similar_service_checks = similar._build_similar_elements(
            expected_service_check, aggregator._service_checks)

        # expect similar metrics in a similarity order
        assert similar_service_checks[0][1].name == 'test.similar1'
        assert similar_service_checks[1][1].name == 'test.similar2'
        assert similar_service_checks[2][1].name == 'test.similar3'
Esempio n. 8
0
    def test__build_similar_elements__service_check_name(self, aggregator):
        check = AgentCheck()

        check.service_check('test.second_similar_service_check', AgentCheck.OK)
        check.service_check('test.very_different_service_check', AgentCheck.OK)
        check.service_check('test.most_similar_service_check', AgentCheck.OK)
        check.service_check('test.very_very_different', AgentCheck.OK)

        expected_service_check = ServiceCheckStub(None,
                                                  "test.similar_service_check",
                                                  status=AgentCheck.OK,
                                                  tags=None,
                                                  hostname=None,
                                                  message=None)
        similar_service_checks = similar._build_similar_elements(
            expected_service_check, aggregator._service_checks)

        # expect similar metrics in a similarity order
        assert similar_service_checks[0][
            1].name == 'test.most_similar_service_check'
        assert similar_service_checks[1][
            1].name == 'test.second_similar_service_check'
        assert similar_service_checks[2][
            1].name == 'test.very_different_service_check'
        assert similar_service_checks[3][1].name == 'test.very_very_different'
    def test__build_similar_elements__service_check_status(self, aggregator):
        check = AgentCheck()

        check.service_check('test.similar1', AgentCheck.OK)
        check.service_check('test.similar2', AgentCheck.CRITICAL)
        check.service_check('test.similar3', AgentCheck.WARNING)

        expected_service_check = ServiceCheckStub(
            None, "test.similar", status=AgentCheck.CRITICAL, tags=None, hostname=None, message=None
        )
        similar_service_checks = similar._build_similar_elements(expected_service_check, aggregator._service_checks)

        # expect similar metrics in a similarity order
        assert similar_service_checks[0][1].name == 'test.similar2'
Esempio n. 10
0
 def test_sc_no_ok_message(self, aggregator):
     check = AgentCheck()
     with pytest.raises(Exception):
         check.service_check("testservicecheck", AgentCheck.OK, tags=None, message="No message allowed")