Documentation
¶
Index ¶
- Constants
- type Alert
- type Channel
- type ChannelFilter
- type ChannelInfo
- type HistoryEntry
- type Manager
- func (m *Manager) AddChannel(ch Channel)
- func (m *Manager) AddChannelWithFilter(ch Channel, filter ChannelFilter)
- func (m *Manager) Channels() []string
- func (m *Manager) ChannelsWithFilters() []ChannelInfo
- func (m *Manager) History(limit int) []HistoryEntry
- func (m *Manager) RemoveChannel(name string)
- func (m *Manager) Send(alert *Alert)
- func (m *Manager) SendTest(channelName string) error
- func (m *Manager) UpdateChannelFilter(name string, filter ChannelFilter) error
- type PushSubscription
- type PushSubscriptionKeys
- type PushoverChannel
- type PushoverConfig
- type TelegramChannel
- type TelegramConfig
- type VAPIDKeys
- type WebPushChannel
- func (w *WebPushChannel) AddSubscription(sub PushSubscription)
- func (w *WebPushChannel) Name() string
- func (w *WebPushChannel) PublicKey() string
- func (w *WebPushChannel) RemoveSubscription(endpoint string)
- func (w *WebPushChannel) Send(alert *Alert) error
- func (w *WebPushChannel) SetSubscriptions(subs []PushSubscription)
- func (w *WebPushChannel) SubscriptionCount() int
- func (w *WebPushChannel) Subscriptions() []PushSubscription
- func (w *WebPushChannel) Validate() error
- type WebhookChannel
- type WebhookConfig
Constants ¶
const ( SeverityInfo = "info" SeverityWarning = "warning" SeverityCritical = "critical" )
Severity levels for alerts.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Alert ¶
type Alert struct {
Title string `json:"title"`
Message string `json:"message"`
Severity string `json:"severity"` // info, warning, critical
Source string `json:"source"` // e.g., "node:klever-node1", "system:server1"
AlertType string `json:"alert_type"` // e.g., "node_down", "nonce_stall", "resource", "version"
Time int64 `json:"time"`
}
Alert represents a notification to be sent.
type ChannelFilter ¶
type ChannelFilter struct {
Severities []string `json:"severities,omitempty"` // empty = all
AlertTypes []string `json:"alert_types,omitempty"` // empty = all
}
ChannelFilter defines which alerts a channel should receive.
func (*ChannelFilter) MatchesFilter ¶
func (f *ChannelFilter) MatchesFilter(severity, alertType string) bool
MatchesFilter checks if an alert passes the filter.
type ChannelInfo ¶
type ChannelInfo struct {
Name string `json:"name"`
Filter ChannelFilter `json:"filter"`
}
ChannelInfo contains channel name and its filter for API responses.
type HistoryEntry ¶
type HistoryEntry struct {
ID int64 `json:"id"`
Channel string `json:"channel"`
Title string `json:"title"`
Message string `json:"message"`
Severity string `json:"severity"`
Source string `json:"source"`
Success bool `json:"success"`
Error string `json:"error,omitempty"`
SentAt int64 `json:"sent_at"`
}
HistoryEntry records a sent notification.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager sends alerts to registered channels with optional filtering.
func (*Manager) AddChannel ¶
AddChannel registers a notification channel with no filter (receives all alerts).
func (*Manager) AddChannelWithFilter ¶
func (m *Manager) AddChannelWithFilter(ch Channel, filter ChannelFilter)
AddChannelWithFilter registers a notification channel with a filter.
func (*Manager) ChannelsWithFilters ¶
func (m *Manager) ChannelsWithFilters() []ChannelInfo
ChannelsWithFilters returns channel names and their filters.
func (*Manager) History ¶
func (m *Manager) History(limit int) []HistoryEntry
History returns recent notification history.
func (*Manager) RemoveChannel ¶
RemoveChannel removes a channel by name.
func (*Manager) UpdateChannelFilter ¶
func (m *Manager) UpdateChannelFilter(name string, filter ChannelFilter) error
UpdateChannelFilter updates the filter for a channel by name.
type PushSubscription ¶ added in v0.3.3
type PushSubscription struct {
Endpoint string `json:"endpoint"`
Keys PushSubscriptionKeys `json:"keys"`
}
PushSubscription represents a Web Push subscription from the browser.
type PushSubscriptionKeys ¶ added in v0.3.3
type PushSubscriptionKeys struct {
P256dh string `json:"p256dh"` // base64url-encoded client public key
Auth string `json:"auth"` // base64url-encoded auth secret (16 bytes)
}
PushSubscriptionKeys holds the client keys for push encryption.
type PushoverChannel ¶
type PushoverChannel struct {
// contains filtered or unexported fields
}
PushoverChannel sends notifications via Pushover API.
func NewPushoverChannel ¶
func NewPushoverChannel(cfg PushoverConfig) *PushoverChannel
NewPushoverChannel creates a new Pushover notification channel.
func (*PushoverChannel) Name ¶
func (p *PushoverChannel) Name() string
func (*PushoverChannel) Send ¶
func (p *PushoverChannel) Send(alert *Alert) error
func (*PushoverChannel) Validate ¶
func (p *PushoverChannel) Validate() error
type PushoverConfig ¶
PushoverConfig holds Pushover configuration.
type TelegramChannel ¶
type TelegramChannel struct {
// contains filtered or unexported fields
}
TelegramChannel sends notifications via Telegram Bot API.
func NewTelegramChannel ¶
func NewTelegramChannel(cfg TelegramConfig) *TelegramChannel
NewTelegramChannel creates a new Telegram notification channel.
func (*TelegramChannel) Name ¶
func (t *TelegramChannel) Name() string
func (*TelegramChannel) Send ¶
func (t *TelegramChannel) Send(alert *Alert) error
func (*TelegramChannel) Validate ¶
func (t *TelegramChannel) Validate() error
type TelegramConfig ¶
TelegramConfig holds Telegram bot configuration.
type VAPIDKeys ¶ added in v0.3.3
type VAPIDKeys struct {
PrivateKey *ecdsa.PrivateKey
PublicKey string // base64url-encoded uncompressed public key (65 bytes)
PrivateB64 string // base64url-encoded private key (32 bytes)
}
VAPIDKeys holds a VAPID key pair for Web Push.
func GenerateVAPIDKeys ¶ added in v0.3.3
GenerateVAPIDKeys creates a new P-256 ECDSA key pair for VAPID.
func LoadVAPIDKeys ¶ added in v0.3.3
LoadVAPIDKeys reconstructs VAPID keys from stored base64url-encoded strings.
type WebPushChannel ¶ added in v0.3.3
type WebPushChannel struct {
// contains filtered or unexported fields
}
WebPushChannel sends notifications via Web Push (RFC 8291).
func NewWebPushChannel ¶ added in v0.3.3
func NewWebPushChannel(vapid *VAPIDKeys, subject string) *WebPushChannel
NewWebPushChannel creates a new Web Push notification channel.
func (*WebPushChannel) AddSubscription ¶ added in v0.3.3
func (w *WebPushChannel) AddSubscription(sub PushSubscription)
AddSubscription adds a subscription.
func (*WebPushChannel) Name ¶ added in v0.3.3
func (w *WebPushChannel) Name() string
func (*WebPushChannel) PublicKey ¶ added in v0.3.3
func (w *WebPushChannel) PublicKey() string
PublicKey returns the VAPID public key for the frontend.
func (*WebPushChannel) RemoveSubscription ¶ added in v0.3.3
func (w *WebPushChannel) RemoveSubscription(endpoint string)
RemoveSubscription removes a subscription by endpoint.
func (*WebPushChannel) Send ¶ added in v0.3.3
func (w *WebPushChannel) Send(alert *Alert) error
func (*WebPushChannel) SetSubscriptions ¶ added in v0.3.3
func (w *WebPushChannel) SetSubscriptions(subs []PushSubscription)
SetSubscriptions replaces all subscriptions.
func (*WebPushChannel) SubscriptionCount ¶ added in v0.3.3
func (w *WebPushChannel) SubscriptionCount() int
SubscriptionCount returns the number of active subscriptions.
func (*WebPushChannel) Subscriptions ¶ added in v0.3.3
func (w *WebPushChannel) Subscriptions() []PushSubscription
Subscriptions returns the current list of push subscriptions.
func (*WebPushChannel) Validate ¶ added in v0.3.3
func (w *WebPushChannel) Validate() error
type WebhookChannel ¶
type WebhookChannel struct {
// contains filtered or unexported fields
}
WebhookChannel sends notifications via HTTP webhook.
func NewWebhookChannel ¶
func NewWebhookChannel(cfg WebhookConfig) *WebhookChannel
NewWebhookChannel creates a new webhook notification channel.
func (*WebhookChannel) Name ¶
func (w *WebhookChannel) Name() string
func (*WebhookChannel) Send ¶
func (w *WebhookChannel) Send(alert *Alert) error
func (*WebhookChannel) Validate ¶
func (w *WebhookChannel) Validate() error
type WebhookConfig ¶
type WebhookConfig struct {
URL string `json:"url"`
Headers map[string]string `json:"headers,omitempty"`
}
WebhookConfig holds webhook configuration.