Documentation
¶
Overview ¶
Package alerts handles alert management and delivery.
Index ¶
- func DeleteUserAlerts(e *core.RequestEvent) error
- func UpsertUserAlerts(e *core.RequestEvent) error
- type AlertManager
- func (am *AlertManager) CancelPendingContainerAlerts(systemID string)
- func (am *AlertManager) CancelPendingStatusAlerts(systemID string)
- func (am *AlertManager) HandleContainerAlerts(systemRecord *core.Record, data *system.CombinedData, ...) error
- func (am *AlertManager) HandleNetworkMonitorAlerts(systemRecord *core.Record, results map[string]monitor.Result) error
- func (am *AlertManager) HandleStatusAlerts(newStatus string, systemRecord *core.Record) error
- func (am *AlertManager) HandleSystemAlerts(systemRecord *core.Record, data *system.CombinedData) error
- func (am *AlertManager) HandleSystemdAlerts(systemRecord *core.Record) error
- func (am *AlertManager) IsNotificationSilenced(userID, systemID string) bool
- func (am *AlertManager) SendAlert(data AlertMessageData) error
- func (am *AlertManager) SendShoutrrrAlert(notificationUrl, title, message, link, linkText string) error
- func (am *AlertManager) SendTestNotification(e *core.RequestEvent) error
- func (am *AlertManager) Stop()
- type AlertMessageData
- type AlertsCache
- func (c *AlertsCache) Delete(record *core.Record)
- func (c *AlertsCache) GetAlert(systemID, alertID string) (CachedAlertData, bool)
- func (c *AlertsCache) GetAlertsByName(systemID, alertName string) []CachedAlertData
- func (c *AlertsCache) GetAlertsExcludingNames(systemID string, excludedNames ...string) []CachedAlertData
- func (c *AlertsCache) GetSystemAlerts(systemID string) []CachedAlertData
- func (c *AlertsCache) PopulateFromDB(force bool) error
- func (c *AlertsCache) Refresh(alert CachedAlertData) (CachedAlertData, bool)
- func (c *AlertsCache) Update(record *core.Record)
- type CachedAlertData
- type FetchContainerLogsFunc
- type SystemAlertData
- type SystemAlertFsStats
- type SystemAlertGPUData
- type SystemAlertStats
- type SystemAlertZfsPool
- type UserNotificationSettings
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeleteUserAlerts ¶
func DeleteUserAlerts(e *core.RequestEvent) error
DeleteUserAlerts handles API request to delete alerts for a user across multiple systems (DELETE /api/beszel/user-alerts)
func UpsertUserAlerts ¶
func UpsertUserAlerts(e *core.RequestEvent) error
UpsertUserAlerts handles API request to create or update alerts for a user across multiple systems (POST /api/beszel/user-alerts)
Types ¶
type AlertManager ¶
type AlertManager struct {
// contains filtered or unexported fields
}
func NewAlertManager ¶
func NewAlertManager(app hubLike) *AlertManager
NewAlertManager creates a new AlertManager instance.
func (*AlertManager) CancelPendingContainerAlerts ¶ added in v0.19.0
func (am *AlertManager) CancelPendingContainerAlerts(systemID string)
CancelPendingContainerAlerts clears pending container-health durations for a system. Called when monitoring pauses or the system goes down.
func (*AlertManager) CancelPendingStatusAlerts ¶ added in v0.18.7
func (am *AlertManager) CancelPendingStatusAlerts(systemID string)
CancelPendingStatusAlerts cancels all pending status alert timers for a given system. This is called when a system is paused to prevent delayed alerts from firing.
func (*AlertManager) HandleContainerAlerts ¶ added in v0.19.0
func (am *AlertManager) HandleContainerAlerts(systemRecord *core.Record, data *system.CombinedData, fetchLogs FetchContainerLogsFunc) error
HandleContainerAlerts checks configured "ContainerHealth" alerts for a system against the Docker container health data included in the latest agent update. It persists when containers first become unhealthy, fires from a fresh poll once the configured delay has elapsed, and resolves once containers recover. fetchLogs is used when an alert actually fires so the notification can include a log excerpt (prioritizing lines containing "error"/"fatal") for context.
func (*AlertManager) HandleNetworkMonitorAlerts ¶ added in v0.20.0
func (am *AlertManager) HandleNetworkMonitorAlerts(systemRecord *core.Record, results map[string]monitor.Result) error
HandleNetworkMonitorAlerts runs after the full monitoring transaction commits, using its exact payload (dashboard requests can replace the cached payload). Omitted results and disconnected systems never imply recovery.
func (*AlertManager) HandleStatusAlerts ¶
func (am *AlertManager) HandleStatusAlerts(newStatus string, systemRecord *core.Record) error
HandleStatusAlerts manages the logic when system status changes.
func (*AlertManager) HandleSystemAlerts ¶
func (am *AlertManager) HandleSystemAlerts(systemRecord *core.Record, data *system.CombinedData) error
func (*AlertManager) HandleSystemdAlerts ¶ added in v0.19.0
func (am *AlertManager) HandleSystemdAlerts(systemRecord *core.Record) error
HandleSystemdAlerts manages alerts for systemd services in the failed state.
This is a binary state alert and fires on the first observation of a failed service rather than using a delay. The agent only refreshes systemd state every 10 minutes, so a shorter delay could never observe new data before expiring, and that poll interval already hides services that fail and restart quickly.
func (*AlertManager) IsNotificationSilenced ¶ added in v0.17.0
func (am *AlertManager) IsNotificationSilenced(userID, systemID string) bool
IsNotificationSilenced checks if a notification should be silenced based on configured quiet hours
func (*AlertManager) SendAlert ¶
func (am *AlertManager) SendAlert(data AlertMessageData) error
SendAlert sends an alert to the user
func (*AlertManager) SendShoutrrrAlert ¶
func (am *AlertManager) SendShoutrrrAlert(notificationUrl, title, message, link, linkText string) error
SendShoutrrrAlert sends an alert via a Shoutrrr URL
func (*AlertManager) SendTestNotification ¶
func (am *AlertManager) SendTestNotification(e *core.RequestEvent) error
SendTestNotification handles API request to send a test notification to a specified Shoutrrr URL
func (*AlertManager) Stop ¶ added in v0.18.5
func (am *AlertManager) Stop()
Stop cancels all pending status alert timers.
type AlertMessageData ¶
type AlertsCache ¶ added in v0.18.5
type AlertsCache struct {
// contains filtered or unexported fields
}
AlertsCache provides an in-memory cache for system alerts.
func NewAlertsCache ¶ added in v0.18.5
func NewAlertsCache(app core.App) *AlertsCache
NewAlertsCache creates a new instance of SystemAlertsCache.
func (*AlertsCache) Delete ¶ added in v0.18.5
func (c *AlertsCache) Delete(record *core.Record)
Delete removes an alert record from the cache.
func (*AlertsCache) GetAlert ¶ added in v0.18.5
func (c *AlertsCache) GetAlert(systemID, alertID string) (CachedAlertData, bool)
GetAlert returns a specific alert by its ID from the cache.
func (*AlertsCache) GetAlertsByName ¶ added in v0.18.5
func (c *AlertsCache) GetAlertsByName(systemID, alertName string) []CachedAlertData
GetAlertsByName returns all alerts of a specific type for the specified system.
func (*AlertsCache) GetAlertsExcludingNames ¶ added in v0.18.5
func (c *AlertsCache) GetAlertsExcludingNames(systemID string, excludedNames ...string) []CachedAlertData
GetAlertsExcludingNames returns all alerts for the specified system excluding the given types.
func (*AlertsCache) GetSystemAlerts ¶ added in v0.18.5
func (c *AlertsCache) GetSystemAlerts(systemID string) []CachedAlertData
GetSystemAlerts returns all alerts for the specified system, lazy-loading if necessary.
func (*AlertsCache) PopulateFromDB ¶ added in v0.18.5
func (c *AlertsCache) PopulateFromDB(force bool) error
PopulateFromDB clears current entries and loads all alerts from the database into the cache.
func (*AlertsCache) Refresh ¶ added in v0.18.5
func (c *AlertsCache) Refresh(alert CachedAlertData) (CachedAlertData, bool)
Refresh returns the latest cached copy for an alert snapshot if it still exists.
func (*AlertsCache) Update ¶ added in v0.18.5
func (c *AlertsCache) Update(record *core.Record)
Update adds or updates an alert record in the cache.
type CachedAlertData ¶ added in v0.18.5
type CachedAlertData struct {
Id string
SystemID string
UserID string
Name string
Value float64
Triggered bool
Min uint8
PendingSince time.Time
// Immutable after publication; decoded only when the alert record changes.
MonitorStates map[string]string
MonitorStatesValid bool
}
CachedAlertData represents the relevant fields of an alert record for status checking and updates.
func (*CachedAlertData) PopulateFromRecord ¶ added in v0.18.5
func (a *CachedAlertData) PopulateFromRecord(record *core.Record)
type FetchContainerLogsFunc ¶ added in v0.19.0
FetchContainerLogsFunc retrieves recent logs for a container ID from its connected agent. Implementations should apply their own timeout. This is a type alias (not a defined type) so it satisfies the hubLike interface in internal/hub/systems, which declares the same func signature without importing this package.
type SystemAlertData ¶
type SystemAlertData struct {
// contains filtered or unexported fields
}
type SystemAlertFsStats ¶ added in v0.18.5
type SystemAlertGPUData ¶ added in v0.16.0
type SystemAlertGPUData struct {
Usage float64 `json:"u"`
}
type SystemAlertStats ¶
type SystemAlertStats struct {
Cpu float64 `json:"cpu"`
CpuBreakdown []float64 `json:"cpub"`
Mem float64 `json:"mp"`
Disk float64 `json:"dp"`
Bandwidth [2]uint64 `json:"b"`
GPU map[string]SystemAlertGPUData `json:"g"`
Temperatures map[string]float32 `json:"t"`
LoadAvg [3]float64 `json:"la"`
Battery [2]uint8 `json:"bat"`
Batteries map[string]uint8 `json:"bats"`
ExtraFs map[string]SystemAlertFsStats `json:"efs"`
ZfsPools map[string]SystemAlertZfsPool `json:"z"`
}
Values pulled from system_stats.stats that are relevant to alerts.