From fd40051b9df44574b343022d7aab4512676954be Mon Sep 17 00:00:00 2001 From: Lukas Juhrich Date: Fri, 17 Nov 2023 14:49:26 +0100 Subject: [PATCH] Add hades health endpoint --- web/app.py | 3 ++- web/blueprints/health/__init__.py | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 web/blueprints/health/__init__.py diff --git a/web/app.py b/web/app.py index fdd333eb1..aac3fb389 100644 --- a/web/app.py +++ b/web/app.py @@ -31,7 +31,7 @@ from web.blueprints import task from . import template_filters, template_tests from .blueprints import ( - facilities, finance, infrastructure, login, properties, user, host + facilities, finance, infrastructure, login, properties, user, host, health ) from .blueprints.login import login_manager @@ -99,6 +99,7 @@ def make_app(debug: bool = False, hades_logs: bool = True) -> PycroftFlask: app.register_blueprint(task.bp, url_prefix="/task") app.register_blueprint(login.bp) app.register_blueprint(api.bp, url_prefix="/api/v0") + app.register_blueprint(health.bp, url_prefix="/health") template_filters.register_filters(app) template_tests.register_checks(app) diff --git a/web/blueprints/health/__init__.py b/web/blueprints/health/__init__.py new file mode 100644 index 000000000..4ca31288c --- /dev/null +++ b/web/blueprints/health/__init__.py @@ -0,0 +1,17 @@ +from flask import Blueprint +from flask.typing import ResponseReturnValue + +from hades_logs import hades_logs +from hades_logs.exc import HadesError + +bp = Blueprint("health", __name__) + + +@bp.route("hades-logs") +def hades() -> ResponseReturnValue: + try: + hades_logs.fetch_logs(nasipaddress="10.160.0.75", nasportid="2/1/39") + except HadesError as e: + return f"CRIT {e}" + else: + return "OK"