diff --git a/openldap/datadog_checks/openldap/openldap.py b/openldap/datadog_checks/openldap/openldap.py index fb312e8b0453e..5a7c81814e8b6 100644 --- a/openldap/datadog_checks/openldap/openldap.py +++ b/openldap/datadog_checks/openldap/openldap.py @@ -38,8 +38,8 @@ def check(self, instance): res = conn.bind() if not res: raise ldap3.core.exceptions.LDAPBindError("Error binding to server: {}".format(conn.result)) - except ldap3.core.exceptions.LDAPBindError: - self.log.exception("Could not connect to server at %s: %s", url, conn.result) + except ldap3.core.exceptions.LDAPExceptionError as e: + self.log.exception("Could not connect to server at %s: %s", url, e) self.service_check("{}.can_connect".format(METRIC_PREFIX), self.CRITICAL, tags=tags) raise diff --git a/openldap/tests/test_check.py b/openldap/tests/test_check.py index 2800a5e7db397..1c9be4c94a0da 100644 --- a/openldap/tests/test_check.py +++ b/openldap/tests/test_check.py @@ -84,14 +84,24 @@ def test_check(aggregator, check, openldap_server, instance): def test_check_ssl(aggregator, check, openldap_server, instance_ssl): tags = ["url:{}".format(instance_ssl["url"]), "test:integration"] # Should fail certificate verification - with pytest.raises(ldap3.core.exceptions.LDAPSocketOpenError): + with pytest.raises(ldap3.core.exceptions.LDAPExceptionError): check.check(instance_ssl) + aggregator.assert_service_check("openldap.can_connect", check.CRITICAL, tags=tags) instance_ssl["ssl_verify"] = False # Should work now check.check(instance_ssl) aggregator.assert_service_check("openldap.can_connect", check.OK, tags=tags) +def test_check_connection_failure(aggregator, check, openldap_server, instance): + instance["url"] = "bad_url" + tags = ["url:{}".format(instance["url"]), "test:integration"] + # Should fail certificate verification + with pytest.raises(ldap3.core.exceptions.LDAPExceptionError): + check.check(instance) + aggregator.assert_service_check("openldap.can_connect", check.CRITICAL, tags=tags) + + @pytest.mark.skipif(not Platform.is_linux(), reason='Windows sockets are not file handles') def test_check_socket(aggregator, check, openldap_server, instance): instance["url"] = "ldapi://{}".format(openldap_server)