def check_status(self): try: cache.set('djangohealtcheck_test', 'itworks', 1) if not cache.get("djangohealtcheck_test") == "itworks": raise ServiceUnavailable("Cache key does not match") except CacheKeyWarning as e: self.add_error(ServiceReturnedUnexpectedResult("Cache key warning"), e) except ValueError as e: self.add_error(ServiceReturnedUnexpectedResult("ValueError"), e)
def check_status(self): try: response = es_get('_cluster/health', timeout=2) status = get(response.json(), 'status') is_ok = status == 'green' if not is_ok: raise ServiceReturnedUnexpectedResult( "Status {}".format(status)) except Exception as ex: raise ServiceReturnedUnexpectedResult(ex.args)
def check_status(self): try: cache.set('djangohealtcheck_test', 'itworks', 5) cache_get_value = cache.get("djangohealtcheck_test") if not cache_get_value == "itworks": logger.warning( "Cache is unavailable, because cache value \"%r\" != \"itworks\".", cache_get_value) raise ServiceUnavailable("Cache key does not match") except CacheKeyWarning as e: self.add_error(ServiceReturnedUnexpectedResult("Cache key warning"), e) except ValueError as e: self.add_error(ServiceReturnedUnexpectedResult("ValueError"), e)
def check_status(self): timeout = getattr(settings, 'HEALTHCHECK_CELERY_TIMEOUT', 3) result_timeout = getattr(settings, 'HEALTHCHECK_CELERY_RESULT_TIMEOUT', timeout) queue_timeout = getattr(settings, 'HEALTHCHECK_CELERY_QUEUE_TIMEOUT', timeout) try: result = add.apply_async( args=[4, 4], expires=queue_timeout, queue=self.queue ) result.get(timeout=result_timeout) if result.result != 8: self.add_error(ServiceReturnedUnexpectedResult("Celery returned wrong result")) except IOError as e: self.add_error(ServiceUnavailable("IOError"), e) except NotImplementedError as e: self.add_error(ServiceUnavailable("NotImplementedError: Make sure CELERY_RESULT_BACKEND is set"), e) except TaskRevokedError as e: self.add_error(ServiceUnavailable("TaskRevokedError: The task was revoked, likely because it spent " "too long in the queue"), e) except TimeoutError as e: self.add_error(ServiceUnavailable("TimeoutError: The task took too long to return a result"), e) except BaseException as e: self.add_error(ServiceUnavailable("Unknown error"), e)
def check_status(self): try: res = requests.get('https://www.rest.co.il/restaurants/israel/?kw=zozobra') if res.status_code != 200: self.add_error(ServiceReturnedUnexpectedResult( "Logo finder service return status code: %s" % res.status_code)) except requests.exceptions.RequestException as e: self.add_error(ServiceUnavailable("Unknown error"), e)
def check_status(self): try: res = requests.get(settings.ELASTIC_SEARCH_HOST) if res.status_code != 200: self.add_error(ServiceReturnedUnexpectedResult( "ElasticSearch service return status code: %s" % res.status_code)) except requests.exceptions.RequestException as e: self.add_error(ServiceUnavailable("Unknown error"), e)
def check_status(self): try: res = requests.get('http://www.purgomalum.com/service/containsprofanity?text=kickass') if res.status_code != 200: self.add_error(ServiceReturnedUnexpectedResult( "Profanity service return status code: %s" % res.status_code)) except requests.exceptions.RequestException as e: self.add_error(ServiceUnavailable("Unknown error"), e)
def check_status(self): try: du = psutil.disk_usage('/') if DISK_USAGE_MAX and du.percent >= DISK_USAGE_MAX: raise ServiceWarning( f"{host} {du.percent}% disk usage exceeds {DISK_USAGE_MAX}%" ) except ValueError as e: self.add_error(ServiceReturnedUnexpectedResult("ValueError"), e)
def check_status(self): try: res = requests.get('https://maps.googleapis.com/maps/api/distancematrix/json?origins=jerusalem&' 'destinations=Tel-Aviv&mode=driving&key=AIzaSyBuVvbfu_0nMgFmagXaWdIsVyXrL41OV-U') if res.status_code != 200: self.add_error(ServiceReturnedUnexpectedResult( "Google distance api service return status code: %s" % res.status_code)) except requests.exceptions.RequestException as e: self.add_error(ServiceUnavailable("Unknown error"), e)
def check_status(self): try: obj = TestModel.objects.create(title="test") obj.title = "newtest" obj.save() obj.delete() except IntegrityError: raise ServiceReturnedUnexpectedResult("Integrity Error") except DatabaseError: raise ServiceUnavailable("Database error")
def check_status(self): try: response = sso_api_client.ping() except Exception as error: raise ServiceUnavailable('(SSO proxy) ' + str(error)) else: if response.status_code != 200: raise ServiceReturnedUnexpectedResult( self.message_bad_status.format(response)) return True
def check_status(self): from core.tasks import add timeout = getattr(settings, 'HEALTHCHECK_CELERY_TIMEOUT', 3) try: result = add.delay(4, 4) result.get(timeout=timeout) if result.result != 8: self.add_error(ServiceReturnedUnexpectedResult("Celery returned wrong result")) except IOError as e: self.add_error(ServiceUnavailable("IOError"), e) except BaseException as e: self.add_error(ServiceUnavailable("Unknown error"), e)
def check_status(self): from directory_api_client.client import api_client try: response = api_client.ping() except Exception as error: raise ServiceUnavailable('(API) ' + str(error)) else: if response.status_code != 200: raise ServiceReturnedUnexpectedResult( f'API returned {response.status_code} status code' ) return True
def check_status(self): try: memory = psutil.virtual_memory() if MEMORY_MIN and memory.available < (MEMORY_MIN * 1024 * 1024): locale.setlocale(locale.LC_ALL, '') avail = '{:n}'.format(int(memory.available / 1024 / 1024)) threshold = '{:n}'.format(MEMORY_MIN) raise ServiceWarning( "{host} {avail} MB available RAM below {threshold} MB". format(host=host, avail=avail, threshold=threshold)) except ValueError as e: self.add_error(ServiceReturnedUnexpectedResult("ValueError"), e)
def check_status(self): timeout = getattr(settings, 'HEALTHCHECK_CELERY_TIMEOUT', 3) try: result = add.apply_async( args=[4, 4], expires=timeout ) result.get(timeout=timeout) if result.result != 8: self.add_error(ServiceReturnedUnexpectedResult("Celery returned wrong result")) except IOError as e: self.add_error(ServiceUnavailable("IOError"), e) except BaseException as e: self.add_error(ServiceUnavailable("Unknown error"), e)
def check_status(self): """Check the database connection is available.""" try: if settings.MAINTENANCE_MODE: # Check DB for read access only connection.ensure_connection() else: # Check DB for read/write access obj = HealthCheckTestModel.objects.create(title="test") obj.title = "newtest" obj.save() obj.delete() except IntegrityError: raise ServiceReturnedUnexpectedResult("Integrity Error") except DatabaseError: raise ServiceUnavailable("Database error")
def check_status(self): timeout = time.time() + getattr(settings, 'HEALTHCHECK_RQWORKER_TIMEOUT', 4) try: job = enqueue(add, 5, 6) while True: if job.result or time.time() > timeout: break if not job.result: self.add_error( ServiceUnavailable("No result, are workers running?")) elif job.result == '11': self.add_error( ServiceReturnedUnexpectedResult("Invalid result")) except BaseException as e: self.add_error(ServiceUnavailable("Unknown error"), e)
def check_status(self): if not (settings.HEROKU_AUTH_TOKEN and settings.HEROKU_CONNECT_APP_NAME): raise ServiceUnavailable( 'Both App Name and Auth Token are required') try: connections = utils.get_connections( settings.HEROKU_CONNECT_APP_NAME) except requests.HTTPError as e: raise ServiceReturnedUnexpectedResult( "Unable to retrieve connection state") from e for connection in connections: if connection['state'] not in utils.ConnectionStates.OK_STATES: self.add_error( ServiceUnavailable( "Connection state for '%s' is '%s'" % (connection['name'], connection['state'])))
def check_status(self): client = TestClient() response = client.get(reverse_lazy('search'), data={'q': 'qwerty123'}, follow=True) ordering_success = False if response.status_code == 200: results = response.context_data['results'] if (len(results) == 4) and \ (results[0]["type"] == "Service") and \ (results[-1]["type"] == "Export opportunity"): ordering_success = True if not ordering_success: raise ServiceReturnedUnexpectedResult( 'Search sort ordering via Activity Stream failed') return True
def check_status(self): timeout = getattr(settings, 'HEALTHCHECK_CELERY_TIMEOUT', 3) try: result = add.apply_async(args=[4, 4], expires=timeout, queue=self.queue) result.get(timeout=timeout) if result.result != 8: self.add_error( ServiceReturnedUnexpectedResult( "Celery returned wrong result")) add.forget() except IOError as e: self.add_error(ServiceUnavailable("IOError"), e) except NotImplementedError as e: self.add_error( ServiceUnavailable( "NotImplementedError: Make sure CELERY_RESULT_BACKEND is set" ), e) except BaseException as e: self.add_error(ServiceUnavailable("Unknown error"), e)
def check_status(self): try: response = requests.request( self.get_method(), self.get_url(), data=self.get_payload(), timeout=self.requests_timeout, ) except requests.RequestException as e: logger.exception(e) self.add_error( ServiceUnavailable("{url} - {error}".format( url=self.url, error=e.__class__.__name__, ))) else: if response.status_code != self.expected_status_code: self.add_error( ServiceReturnedUnexpectedResult( "Expected {expected}, got {actual}".format( expected=self.expected_status_code, actual=response.status_code, )))