diff --git a/app/web/api/alerts.py b/app/web/api/alerts.py index 8315dae..18446d2 100644 --- a/app/web/api/alerts.py +++ b/app/web/api/alerts.py @@ -146,6 +146,47 @@ def acknowledge_alert(alert_id): }), 400 +@bp.route('/acknowledge-all', methods=['POST']) +@api_auth_required +def acknowledge_all_alerts(): + """ + Acknowledge all unacknowledged alerts. + + Returns: + JSON response with count of acknowledged alerts + """ + acknowledged_by = request.json.get('acknowledged_by', 'api') if request.json else 'api' + + try: + # Get all unacknowledged alerts + unacked_alerts = current_app.db_session.query(Alert).filter( + Alert.acknowledged == False + ).all() + + count = 0 + for alert in unacked_alerts: + alert.acknowledged = True + alert.acknowledged_at = datetime.now(timezone.utc) + alert.acknowledged_by = acknowledged_by + count += 1 + + current_app.db_session.commit() + + return jsonify({ + 'status': 'success', + 'message': f'Acknowledged {count} alerts', + 'count': count, + 'acknowledged_by': acknowledged_by + }) + + except Exception as e: + current_app.db_session.rollback() + return jsonify({ + 'status': 'error', + 'message': f'Failed to acknowledge alerts: {str(e)}' + }), 500 + + @bp.route('/rules', methods=['GET']) @api_auth_required def list_alert_rules(): diff --git a/app/web/templates/alerts.html b/app/web/templates/alerts.html index 4d71640..b6fe6ab 100644 --- a/app/web/templates/alerts.html +++ b/app/web/templates/alerts.html @@ -6,9 +6,14 @@

Alert History

- - Manage Alert Rules - +
+ + + Manage Alert Rules + +
@@ -265,5 +270,34 @@ function acknowledgeAlert(alertId) { alert('Failed to acknowledge alert'); }); } + +function acknowledgeAllAlerts() { + if (!confirm('Acknowledge all unacknowledged alerts?')) { + return; + } + + fetch('/api/alerts/acknowledge-all', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'X-API-Key': localStorage.getItem('api_key') || '' + }, + body: JSON.stringify({ + acknowledged_by: 'web_user' + }) + }) + .then(response => response.json()) + .then(data => { + if (data.status === 'success') { + location.reload(); + } else { + alert('Failed to acknowledge alerts: ' + (data.message || 'Unknown error')); + } + }) + .catch(error => { + console.error('Error:', error); + alert('Failed to acknowledge alerts'); + }); +} {% endblock %} \ No newline at end of file