feat: CrowdSec journald-Acquisition + Alarm-Quittieren/Löschen — v1.3.5
- fix(crowdsec/packaging): postinst setzt die HAProxy-Acquisition deterministisch auf die journald-Unit (haproxy.service) statt der cscli-setup-Datei-Default (/var/log/haproxy.log existiert nicht → CrowdSec las nichts → HTTP/CVE-Szenarien liefen leer). Self-healing auf jedem configure; admin-Custom bleibt unangetastet. - feat(alerts): Alarme (alert_events) bulk quittieren + löschen. Migration 0045 (acknowledged_at + Teil-Index). Dashboard-Karte zählt nur noch OFFENE (open=true) → Quittieren lässt die "Aktuelle Alerts"-Meldung verschwinden, History bleibt. Events-Tab: Row-Selection, Quittieren/Löschen (Auswahl) + "Alle quittieren", Status-Spalte (offen/quittiert). Audit-geloggt. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -62,13 +62,14 @@ type EmailSettings struct {
|
||||
|
||||
// Event ist eine Row in alert_events.
|
||||
type Event struct {
|
||||
ID int64 `json:"id"`
|
||||
Kind string `json:"kind"`
|
||||
Severity Severity `json:"severity"`
|
||||
Subject string `json:"subject"`
|
||||
Message string `json:"message"`
|
||||
SentTo json.RawMessage `json:"sent_to"`
|
||||
FiredAt time.Time `json:"fired_at"`
|
||||
ID int64 `json:"id"`
|
||||
Kind string `json:"kind"`
|
||||
Severity Severity `json:"severity"`
|
||||
Subject string `json:"subject"`
|
||||
Message string `json:"message"`
|
||||
SentTo json.RawMessage `json:"sent_to"`
|
||||
FiredAt time.Time `json:"fired_at"`
|
||||
AcknowledgedAt *time.Time `json:"acknowledged_at,omitempty"`
|
||||
}
|
||||
|
||||
// SendResult pro Channel — landet als JSON-Array in sent_to.
|
||||
@@ -170,14 +171,19 @@ func (s *Service) DeleteChannel(ctx context.Context, id int64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ListEvents liefert die letzten N Events newest-first.
|
||||
func (s *Service) ListEvents(ctx context.Context, limit int) ([]Event, error) {
|
||||
// ListEvents liefert die letzten N Events newest-first. Wenn openOnly
|
||||
// gesetzt ist, werden nur noch offene (nicht quittierte) Events geliefert —
|
||||
// das nutzt die Dashboard-Karte, damit Quittieren die Meldung verschwinden
|
||||
// lässt.
|
||||
func (s *Service) ListEvents(ctx context.Context, limit int, openOnly bool) ([]Event, error) {
|
||||
if limit <= 0 || limit > 500 {
|
||||
limit = 100
|
||||
}
|
||||
rows, err := s.Pool.Query(ctx, `
|
||||
SELECT id, kind, severity, subject, message, sent_to, fired_at
|
||||
FROM alert_events ORDER BY fired_at DESC, id DESC LIMIT $1`, limit)
|
||||
SELECT id, kind, severity, subject, message, sent_to, fired_at, acknowledged_at
|
||||
FROM alert_events
|
||||
WHERE ($2::bool = false OR acknowledged_at IS NULL)
|
||||
ORDER BY fired_at DESC, id DESC LIMIT $1`, limit, openOnly)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -186,7 +192,7 @@ FROM alert_events ORDER BY fired_at DESC, id DESC LIMIT $1`, limit)
|
||||
for rows.Next() {
|
||||
var e Event
|
||||
if err := rows.Scan(&e.ID, &e.Kind, &e.Severity, &e.Subject,
|
||||
&e.Message, &e.SentTo, &e.FiredAt); err != nil {
|
||||
&e.Message, &e.SentTo, &e.FiredAt, &e.AcknowledgedAt); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out = append(out, e)
|
||||
@@ -194,6 +200,46 @@ FROM alert_events ORDER BY fired_at DESC, id DESC LIMIT $1`, limit)
|
||||
return out, rows.Err()
|
||||
}
|
||||
|
||||
// Acknowledge quittiert die angegebenen Events (setzt acknowledged_at=NOW()
|
||||
// bei noch offenen). Liefert die Anzahl geänderter Rows.
|
||||
func (s *Service) Acknowledge(ctx context.Context, ids []int64) (int64, error) {
|
||||
if len(ids) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
tag, err := s.Pool.Exec(ctx,
|
||||
`UPDATE alert_events SET acknowledged_at = NOW()
|
||||
WHERE id = ANY($1) AND acknowledged_at IS NULL`, ids)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return tag.RowsAffected(), nil
|
||||
}
|
||||
|
||||
// AcknowledgeAll quittiert alle offenen Events — Backing für den
|
||||
// "Alle quittieren"-Button.
|
||||
func (s *Service) AcknowledgeAll(ctx context.Context) (int64, error) {
|
||||
tag, err := s.Pool.Exec(ctx,
|
||||
`UPDATE alert_events SET acknowledged_at = NOW() WHERE acknowledged_at IS NULL`)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return tag.RowsAffected(), nil
|
||||
}
|
||||
|
||||
// DeleteEvents löscht die angegebenen Events endgültig. Liefert die Anzahl
|
||||
// gelöschter Rows.
|
||||
func (s *Service) DeleteEvents(ctx context.Context, ids []int64) (int64, error) {
|
||||
if len(ids) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
tag, err := s.Pool.Exec(ctx,
|
||||
`DELETE FROM alert_events WHERE id = ANY($1)`, ids)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return tag.RowsAffected(), nil
|
||||
}
|
||||
|
||||
// Cleanup löscht alert_events älter als keepDays und liefert die Anzahl
|
||||
// gelöschter Rows. make_interval(days => $1) nimmt $1 sauber als int —
|
||||
// der frühere ($1 || ' days')::interval-Ansatz erzwang text und scheiterte
|
||||
|
||||
Reference in New Issue
Block a user