mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-04-29 20:10:21 +00:00
This commit adds enterprise-grade reporting and audit capabilities: Reporting: - Refactored metrics store from internal/ to pkg/ for enterprise access - Added pkg/reporting with shared interfaces for report generation - Created API endpoint: GET /api/admin/reports/generate - New ReportingPanel.tsx for PDF/CSV report configuration Audit Webhooks: - Extended pkg/audit with webhook URL management interface - Added API endpoint: GET/POST /api/admin/webhooks/audit - New AuditWebhookPanel.tsx for webhook configuration - Updated Settings.tsx with Reporting and Webhooks tabs Server Hardening: - Enterprise hooks now execute outside mutex with panic recovery - Removed dbPath from metrics Stats API to prevent path disclosure - Added storage metrics persistence to polling loop Documentation: - Updated README.md feature table - Updated docs/API.md with new endpoints - Updated docs/PULSE_PRO.md with feature descriptions - Updated docs/WEBHOOKS.md with audit webhooks section
71 lines
1.6 KiB
Go
71 lines
1.6 KiB
Go
package metrics
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/rcourtman/pulse-go-rewrite/internal/alerts"
|
|
)
|
|
|
|
func TestRecordAlertFired(t *testing.T) {
|
|
alert := &alerts.Alert{
|
|
ID: "test-alert-1",
|
|
Level: alerts.AlertLevelWarning,
|
|
Type: "container_cpu",
|
|
StartTime: time.Now(),
|
|
}
|
|
|
|
// Should not panic
|
|
RecordAlertFired(alert)
|
|
}
|
|
|
|
func TestRecordAlertResolved(t *testing.T) {
|
|
now := time.Now()
|
|
alert := &alerts.Alert{
|
|
ID: "test-alert-2",
|
|
Level: alerts.AlertLevelWarning,
|
|
Type: "container_memory",
|
|
StartTime: now.Add(-5 * time.Minute),
|
|
LastSeen: now,
|
|
}
|
|
|
|
// Should not panic
|
|
RecordAlertResolved(alert)
|
|
}
|
|
|
|
func TestRecordAlertAcknowledged(t *testing.T) {
|
|
// Should not panic
|
|
RecordAlertAcknowledged()
|
|
}
|
|
|
|
func TestRecordAlertSuppressed(t *testing.T) {
|
|
// Should not panic with various reasons
|
|
RecordAlertSuppressed("quiet_hours")
|
|
RecordAlertSuppressed("rate_limit")
|
|
RecordAlertSuppressed("duplicate")
|
|
}
|
|
|
|
func TestMetricVectors_NotNil(t *testing.T) {
|
|
// Verify that metric vectors are properly initialized
|
|
if AlertsActive == nil {
|
|
t.Error("AlertsActive should not be nil")
|
|
}
|
|
if AlertsFiredTotal == nil {
|
|
t.Error("AlertsFiredTotal should not be nil")
|
|
}
|
|
if AlertsResolvedTotal == nil {
|
|
t.Error("AlertsResolvedTotal should not be nil")
|
|
}
|
|
if AlertsAcknowledgedTotal == nil {
|
|
t.Error("AlertsAcknowledgedTotal should not be nil")
|
|
}
|
|
if AlertDurationSeconds == nil {
|
|
t.Error("AlertDurationSeconds should not be nil")
|
|
}
|
|
if AlertsSuppressedTotal == nil {
|
|
t.Error("AlertsSuppressedTotal should not be nil")
|
|
}
|
|
if AlertsRateLimitedTotal == nil {
|
|
t.Error("AlertsRateLimitedTotal should not be nil")
|
|
}
|
|
}
|