Add source status API and enhance dashboard with data source checks
- Introduced a new API endpoint `/api/source-status/` to return the status of Prometheus and OpenStack data sources. - Implemented lightweight health check functions for both Prometheus and OpenStack. - Updated the dashboard template to display the status of data sources dynamically. - Added tests for the new API endpoint to ensure correct functionality and response handling. - Configured a cache timeout for source status checks to improve performance.
This commit is contained in:
@@ -3,6 +3,21 @@ from openstack.connection import Connection
|
||||
|
||||
from watcher_visio.settings import OPENSTACK_CLOUD, OPENSTACK_REGION_NAME
|
||||
|
||||
|
||||
def check_openstack() -> dict:
|
||||
"""
|
||||
Lightweight check that OpenStack is reachable (connection only).
|
||||
Returns {"status": "ok"} or {"status": "error", "message": "..."}.
|
||||
"""
|
||||
try:
|
||||
conn = openstack.connect(cloud=OPENSTACK_CLOUD, region_name=OPENSTACK_REGION_NAME)
|
||||
if conn is None:
|
||||
return {"status": "error", "message": "No connection"}
|
||||
return {"status": "ok"}
|
||||
except Exception as e:
|
||||
return {"status": "error", "message": str(e) or "Connection failed"}
|
||||
|
||||
|
||||
def get_connection() -> Connection:
|
||||
connection = openstack.connect(cloud=OPENSTACK_CLOUD, region_name=OPENSTACK_REGION_NAME)
|
||||
return connection
|
||||
|
||||
Reference in New Issue
Block a user