def test_version_init_config_default(aggregator, instance_remote_version_default_1_1): c = TLSCheck('tls', {'allowed_versions': ['1.1']}, [instance_remote_version_default_1_1]) c.check(None) aggregator.assert_service_check(SERVICE_CHECK_CAN_CONNECT, status=c.OK, tags=c._tags, count=1) aggregator.assert_service_check(SERVICE_CHECK_VERSION, status=c.OK, tags=c._tags, count=1) aggregator.assert_service_check(SERVICE_CHECK_VALIDATION, status=c.OK, tags=c._tags, count=1) aggregator.assert_service_check(SERVICE_CHECK_EXPIRATION, status=c.OK, tags=c._tags, count=1) aggregator.assert_metric('tls.days_left', count=1) aggregator.assert_metric('tls.seconds_left', count=1) aggregator.assert_all_metrics_covered()
def test_cert_warning_seconds(aggregator, instance_remote_cert_warning_seconds): c = TLSCheck('tls', {}, [instance_remote_cert_warning_seconds]) c.check(None) aggregator.assert_service_check(SERVICE_CHECK_CAN_CONNECT, status=c.OK, tags=c._tags, count=1) aggregator.assert_service_check(SERVICE_CHECK_VERSION, status=c.OK, tags=c._tags, count=1) aggregator.assert_service_check(SERVICE_CHECK_VALIDATION, status=c.OK, tags=c._tags, count=1) aggregator.assert_service_check(SERVICE_CHECK_EXPIRATION, status=c.WARNING, tags=c._tags, count=1) aggregator.assert_metric('tls.days_left', count=1) aggregator.assert_metric('tls.seconds_left', count=1) aggregator.assert_all_metrics_covered()
def test_cert_send_cert_duration(aggregator, instance_remote_send_cert_duration): c = TLSCheck('tls', {}, [instance_remote_send_cert_duration]) c.check(None) aggregator.assert_service_check(SERVICE_CHECK_CAN_CONNECT, status=c.OK, tags=c._tags, count=1) aggregator.assert_service_check(SERVICE_CHECK_VERSION, status=c.OK, tags=c._tags, count=1) aggregator.assert_service_check(SERVICE_CHECK_VALIDATION, status=c.OK, tags=c._tags, count=1) aggregator.assert_service_check(SERVICE_CHECK_EXPIRATION, status=c.OK, tags=c._tags, count=1) aggregator.assert_metric('tls.days_left', count=1) aggregator.assert_metric('tls.seconds_left', count=1) aggregator.assert_metric('tls.issued_days', count=1) aggregator.assert_metric('tls.issued_seconds', count=1) aggregator.assert_all_metrics_covered()
def test_no_connect_ipv6(aggregator, instance_remote_no_connect): c = TLSCheck('tls', {}, [instance_remote_no_connect]) with mock.patch('socket.getaddrinfo', return_value=()): c.check(None) aggregator.assert_service_check( SERVICE_CHECK_CAN_CONNECT, status=c.CRITICAL, tags=c._tags, message='No valid addresses found, try checking your IPv6 connectivity', count=1, ) aggregator.assert_service_check(SERVICE_CHECK_VERSION, count=0) aggregator.assert_service_check(SERVICE_CHECK_VALIDATION, count=0) aggregator.assert_service_check(SERVICE_CHECK_EXPIRATION, count=0) aggregator.assert_all_metrics_covered()
def test_no_connect(aggregator, instance_remote_no_connect): c = TLSCheck('tls', {}, [instance_remote_no_connect]) c.check(None) aggregator.assert_service_check(SERVICE_CHECK_CAN_CONNECT, status=c.CRITICAL, tags=c._tags, count=1) aggregator.assert_service_check(SERVICE_CHECK_VERSION, count=0) aggregator.assert_service_check(SERVICE_CHECK_VALIDATION, count=0) aggregator.assert_service_check(SERVICE_CHECK_EXPIRATION, count=0) message = 'Unable to resolve host, check your DNS' assert message not in aggregator.service_checks( SERVICE_CHECK_CAN_CONNECT)[0].message aggregator.assert_all_metrics_covered()
def test_cert_expired(aggregator, instance_remote_cert_expired): c = TLSCheck('tls', {}, [instance_remote_cert_expired]) c.check(None) aggregator.assert_service_check(SERVICE_CHECK_CAN_CONNECT, status=c.OK, tags=c._tags, count=1) aggregator.assert_service_check(SERVICE_CHECK_VALIDATION, status=c.CRITICAL, tags=c._tags, count=1) if PY2: aggregator.assert_service_check(SERVICE_CHECK_VERSION, count=0) aggregator.assert_service_check(SERVICE_CHECK_EXPIRATION, count=0) else: aggregator.assert_service_check(SERVICE_CHECK_VERSION, count=0) aggregator.assert_service_check(SERVICE_CHECK_EXPIRATION, status=c.CRITICAL, tags=c._tags, message='Certificate has expired', count=1) aggregator.assert_all_metrics_covered()
def test_hostname_mismatch(aggregator, instance_remote_hostname_mismatch): c = TLSCheck('tls', {}, [instance_remote_hostname_mismatch]) c.check(None) aggregator.assert_service_check(SERVICE_CHECK_CAN_CONNECT, status=c.OK, tags=c._tags, count=1) aggregator.assert_service_check(SERVICE_CHECK_VERSION, status=c.OK, tags=c._tags, count=1) aggregator.assert_service_check(SERVICE_CHECK_VALIDATION, status=c.CRITICAL, tags=c._tags, count=1) aggregator.assert_service_check(SERVICE_CHECK_EXPIRATION, status=c.OK, tags=c._tags, count=1) aggregator.assert_metric('tls.days_left', count=1) aggregator.assert_metric('tls.seconds_left', count=1) aggregator.assert_all_metrics_covered()
def test_no_server(instance_remote_no_server): c = TLSCheck('tls', {}, [instance_remote_no_server]) with pytest.raises(ConfigurationError): c.check(None)
def test_right_class_is_instantiated(instance_remote_no_server): c = TLSCheck('tls', {}, [instance_remote_no_server]) assert isinstance(c, TLSRemoteCheck)