🔍 Code Extractor

function system_status

Maturity: 42

Flask API endpoint that returns comprehensive system status information including database connectivity, authentication state, and feature availability.

File:
/tf/active/vicechatdev/vice_ai/new_app.py
Lines:
2519 - 2539
Complexity:
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

    Flask route handler that provides a health check endpoint returning the operational status of the application and its core components (RAG engine and document indexer).

    From: /tf/active/vicechatdev/docchat/app.py
  • function health 73.4% similar

    Flask route handler that provides a health check endpoint returning the application's operational status, chat engine availability, and current timestamp.

    From: /tf/active/vicechatdev/vice_ai/app.py
  • function health_check 72.0% similar

    A Flask route handler that provides a health check endpoint returning the application's status and current timestamp.

    From: /tf/active/vicechatdev/leexi/app.py
  • function admin_status 68.0% similar

    Flask route handler that retrieves comprehensive system status information including disk usage, session counts, analysis counts, and orphaned file detection for an admin dashboard.

    From: /tf/active/vicechatdev/full_smartstat/app.py
  • function api_task_status_v1 65.5% similar

    Flask API endpoint that retrieves and returns the status of a background task, with user authorization checks.

    From: /tf/active/vicechatdev/vice_ai/app.py
← Back to Browse