Files
ProxMenux/AppImage/scripts/flask_health_routes.py

75 lines
2.5 KiB
Python
Raw Permalink Normal View History

2025-11-04 22:28:42 +01:00
"""
2025-11-09 17:28:20 +01:00
Flask routes for health monitoring with persistence support
2025-11-04 22:28:42 +01:00
"""
2025-11-09 17:28:20 +01:00
from flask import Blueprint, jsonify, request
2025-11-04 22:28:42 +01:00
from health_monitor import health_monitor
2025-11-09 17:28:20 +01:00
from health_persistence import health_persistence
2025-11-04 22:28:42 +01:00
health_bp = Blueprint('health', __name__)
@health_bp.route('/api/health/status', methods=['GET'])
def get_health_status():
"""Get overall health status summary"""
try:
status = health_monitor.get_overall_status()
return jsonify(status)
except Exception as e:
return jsonify({'error': str(e)}), 500
@health_bp.route('/api/health/details', methods=['GET'])
def get_health_details():
"""Get detailed health status with all checks"""
try:
details = health_monitor.get_detailed_status()
return jsonify(details)
except Exception as e:
return jsonify({'error': str(e)}), 500
2025-11-07 18:49:37 +01:00
@health_bp.route('/api/system-info', methods=['GET'])
def get_system_info():
"""
Get lightweight system info for header display.
2025-11-09 16:30:29 +01:00
Returns: hostname, uptime, and health status with proper structure.
2025-11-07 18:49:37 +01:00
"""
try:
info = health_monitor.get_system_info()
2025-11-09 16:43:45 +01:00
2025-11-09 16:30:29 +01:00
if 'health' in info:
status_map = {
'OK': 'healthy',
'WARNING': 'warning',
'CRITICAL': 'critical',
'UNKNOWN': 'warning'
}
current_status = info['health'].get('status', 'OK').upper()
info['health']['status'] = status_map.get(current_status, 'healthy')
2025-11-07 18:49:37 +01:00
return jsonify(info)
except Exception as e:
return jsonify({'error': str(e)}), 500
2025-11-09 17:28:20 +01:00
2025-11-09 18:05:35 +01:00
@health_bp.route('/api/health/acknowledge', methods=['POST'])
def acknowledge_error():
2025-11-09 17:28:20 +01:00
"""Acknowledge an error manually (user dismissed it)"""
try:
2025-11-09 18:05:35 +01:00
data = request.get_json()
if not data or 'error_key' not in data:
return jsonify({'error': 'error_key is required'}), 400
error_key = data['error_key']
2025-11-09 17:28:20 +01:00
health_persistence.acknowledge_error(error_key)
return jsonify({'success': True, 'message': 'Error acknowledged'})
except Exception as e:
return jsonify({'error': str(e)}), 500
@health_bp.route('/api/health/active-errors', methods=['GET'])
def get_active_errors():
"""Get all active persistent errors"""
try:
category = request.args.get('category')
errors = health_persistence.get_active_errors(category)
return jsonify({'errors': errors})
except Exception as e:
return jsonify({'error': str(e)}), 500