function system_status
Flask API endpoint that returns comprehensive system status information including database connectivity, authentication state, and feature availability.
/tf/active/vicechatdev/vice_ai/new_app.py
2519 - 2539
simple
Purpose
This endpoint provides a health check and status overview for the application. It verifies database connectivity, reports on available features (RAG, Azure SSO), checks user authentication status, and returns user information if authenticated. Used for monitoring, debugging, and displaying system state in the UI.
Source Code
def system_status():
"""Get system status information"""
status = {
'database_connected': True,
'rag_available': RAG_AVAILABLE,
'azure_sso_available': AZURE_SSO_AVAILABLE,
'authenticated': is_authenticated(),
'user_email': get_current_user() if is_authenticated() else None,
'user_name': get_user_name() if is_authenticated() else None,
'database_path': DATABASE_PATH
}
try:
# Test database connection
db_manager.verify_tables()
status['database_status'] = 'connected'
except Exception as e:
status['database_connected'] = False
status['database_status'] = f'error: {e}'
return jsonify(status)
Return Value
Returns a Flask JSON response containing a dictionary with keys: 'database_connected' (bool), 'rag_available' (bool), 'azure_sso_available' (bool), 'authenticated' (bool), 'user_email' (str or None), 'user_name' (str or None), 'database_path' (str), and 'database_status' (str - either 'connected' or 'error: <message>').
Dependencies
flask
Required Imports
from flask import jsonify
Usage Example
# In Flask application context
# Assuming all required globals and functions are defined:
# RAG_AVAILABLE = True
# AZURE_SSO_AVAILABLE = False
# DATABASE_PATH = '/path/to/database.db'
# db_manager = DatabaseManager()
# Make GET request to endpoint:
# curl http://localhost:5000/api/system/status
# Response example:
# {
# "database_connected": true,
# "rag_available": true,
# "azure_sso_available": false,
# "authenticated": true,
# "user_email": "user@example.com",
# "user_name": "John Doe",
# "database_path": "/path/to/database.db",
# "database_status": "connected"
# }
Best Practices
- This endpoint should be accessible without authentication to allow health checks
- The database verification is wrapped in try-except to prevent endpoint failure if database is down
- Returns both boolean flags and detailed status messages for better debugging
- Should be called periodically by monitoring systems to verify application health
- Consider adding response caching if called frequently to reduce database load
- Sensitive information like database_path might need to be restricted in production environments
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function health_v1 74.3% similar
-
function health 73.4% similar
-
function health_check 72.0% similar
-
function admin_status 68.0% similar
-
function api_task_status_v1 65.5% similar