updated view and database
This commit is contained in:
+22
-18
@@ -2,7 +2,7 @@
|
||||
Main web routes for dashboard and device management
|
||||
"""
|
||||
from flask import Blueprint, render_template, request, redirect, url_for, flash, jsonify
|
||||
from app.models import Device, LogEntry, MessageTemplate, AnsibleExecution, WMTUpdateRequest, InventoryGroup, device_inventory_association
|
||||
from app.models import Device, LogEntry, MessageTemplate, AnsibleExecution, PlaybookExecution, WMTUpdateRequest, InventoryGroup, device_inventory_association
|
||||
from config.database_config import get_db
|
||||
from app.services.log_service import LogCompressionService
|
||||
from datetime import datetime, timedelta
|
||||
@@ -242,10 +242,12 @@ def stats():
|
||||
|
||||
# Get execution statistics
|
||||
exec_stats = {
|
||||
'total': session.query(AnsibleExecution).count(),
|
||||
'successful': session.query(AnsibleExecution).filter_by(status='completed').count(),
|
||||
'failed': session.query(AnsibleExecution).filter_by(status='failed').count(),
|
||||
'running': session.query(AnsibleExecution).filter_by(status='running').count()
|
||||
'total': session.query(PlaybookExecution).count(),
|
||||
'successful': session.query(PlaybookExecution).filter_by(status='completed').count(),
|
||||
'failed': session.query(PlaybookExecution).filter_by(status='failed').count(),
|
||||
'running': session.query(PlaybookExecution).filter(
|
||||
PlaybookExecution.status.in_(['queued', 'running'])
|
||||
).count()
|
||||
}
|
||||
|
||||
return render_template('stats.html',
|
||||
@@ -541,6 +543,21 @@ def admin():
|
||||
@main_bp.route('/admin/clear/logs', methods=['POST'])
|
||||
def admin_clear_logs():
|
||||
"""Delete all log entries from the database."""
|
||||
return _clear_all_log_entries()
|
||||
|
||||
|
||||
@main_bp.route('/admin/clear/device-logs', methods=['POST'])
|
||||
def admin_clear_device_logs():
|
||||
"""Delete all log entries from the database (devices stay intact).
|
||||
|
||||
Functionally identical to admin_clear_logs – both endpoints are kept because
|
||||
the admin UI exposes two separate buttons, but they share one implementation.
|
||||
"""
|
||||
return _clear_all_log_entries()
|
||||
|
||||
|
||||
def _clear_all_log_entries():
|
||||
"""Shared implementation: delete every LogEntry row."""
|
||||
try:
|
||||
with get_db().get_session() as session:
|
||||
count = session.query(LogEntry).delete()
|
||||
@@ -551,19 +568,6 @@ def admin_clear_logs():
|
||||
return jsonify({'success': False, 'error': str(e)}), 500
|
||||
|
||||
|
||||
@main_bp.route('/admin/clear/device-logs', methods=['POST'])
|
||||
def admin_clear_device_logs():
|
||||
"""Delete all log entries from the database (devices stay intact)."""
|
||||
try:
|
||||
with get_db().get_session() as session:
|
||||
count = session.query(LogEntry).delete()
|
||||
session.commit()
|
||||
return jsonify({'success': True, 'deleted': count})
|
||||
except Exception as e:
|
||||
logging.error(f'Admin clear device logs error: {e}')
|
||||
return jsonify({'success': False, 'error': str(e)}), 500
|
||||
|
||||
|
||||
@main_bp.route('/admin/delete/device/<int:device_id>', methods=['POST'])
|
||||
def admin_delete_device(device_id):
|
||||
"""Delete a single registered device and its log entries."""
|
||||
|
||||
Reference in New Issue
Block a user