diff --git a/powerdnsadmin/routes/api.py b/powerdnsadmin/routes/api.py index 68d2352..e37b2ae 100644 --- a/powerdnsadmin/routes/api.py +++ b/powerdnsadmin/routes/api.py @@ -23,7 +23,7 @@ from ..lib.errors import ( AccountCreateFail, AccountUpdateFail, AccountDeleteFail, AccountCreateDuplicate, AccountNotExists, UserCreateFail, UserCreateDuplicate, UserUpdateFail, UserDeleteFail, - UserUpdateFailEmail, + UserUpdateFailEmail ) from ..decorators import ( api_basic_auth, api_can_create_domain, is_json, apikey_auth, @@ -1195,3 +1195,21 @@ def sync_domains(): domain = Domain() domain.update() return 'Finished synchronization in background', 200 + +@api_bp.route('/health', methods=['GET']) +@apikey_auth +def health(): + domain = Domain() + domain_to_query = domain.query.first() + + if not domain_to_query: + current_app.logger.error("No domain found to query a health check") + return make_response("Unknown", 503) + + try: + domain.get_domain_info(domain_to_query.name) + except Exception as e: + current_app.logger.error("Health Check - Failed to query authoritative server for domain {}".format(domain_to_query.name)) + return make_response("Down", 503) + + return make_response("Up", 200) diff --git a/powerdnsadmin/swagger-spec.yaml b/powerdnsadmin/swagger-spec.yaml index dbf484e..75b1d9f 100644 --- a/powerdnsadmin/swagger-spec.yaml +++ b/powerdnsadmin/swagger-spec.yaml @@ -782,6 +782,32 @@ paths: '422': description: 'Returned when something is wrong with the content of the request. Contains an error message' + '/servers/{server_id}/health': + get: + security: + - APIKeyHeader: [] + summary: Perfoms health check + operationId: health_check + tags: + - Monitoring + parameters: + - name: server_id + in: path + required: true + description: The id of the server to retrieve + type: string + responses: + '200': + description: Healthcheck succeeded + schema: + type: string + example: "up" + '503': + description: Healthcheck failed + schema: + type: string + example: Down/Unknown + '/pdnsadmin/zones': get: security: