From 66617b769885a696c847c49fc228b0fe76306f2b Mon Sep 17 00:00:00 2001 From: Per-Arne Andersen Date: Sun, 19 Jul 2020 22:12:27 +0200 Subject: [PATCH] * Removed warning on missing devices as this is a is_running check. No device appears when device is NOT running. * Check if interface runs before checking stats. --- wg_dashboard_backend/routers/v1/server.py | 6 +++++- wg_dashboard_backend/script/wireguard.py | 5 +---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/wg_dashboard_backend/routers/v1/server.py b/wg_dashboard_backend/routers/v1/server.py index 185c501..1a44ee3 100644 --- a/wg_dashboard_backend/routers/v1/server.py +++ b/wg_dashboard_backend/routers/v1/server.py @@ -122,7 +122,11 @@ def delete_server( @router.post("/stats", dependencies=[Depends(middleware.auth)]) def stats_server(server: schemas.WGServer): - stats = script.wireguard.get_stats(server) + if script.wireguard.is_running(server): + stats = script.wireguard.get_stats(server) + else: + stats = [] + return JSONResponse(content=stats) diff --git a/wg_dashboard_backend/script/wireguard.py b/wg_dashboard_backend/script/wireguard.py index 668d8f7..7459217 100644 --- a/wg_dashboard_backend/script/wireguard.py +++ b/wg_dashboard_backend/script/wireguard.py @@ -108,10 +108,7 @@ def restart_interface(server: schemas.WGServer): def is_running(server: schemas.WGServer): try: output = _run_wg(server, ["show", server.interface]) - if output is None or b'Unable to access interface: No such device' in output: - _LOGGER.warning("Unable to access interface: No such device. (%s)" - "This may indicate that there is a bug somewhere, " - "or that you have manually deleted parts of the database", server.interface) + if output is None: return False except Exception as e: if b'No such device' in e.output: