notify

package
v0.3.88 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
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 Channel

type Channel interface {
	Name() string
	Send(alert *Alert) error
	Validate() error
}

Channel is the interface for notification delivery channels.

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 NewManager

func NewManager() *Manager

NewManager creates a new notification manager.

func (*Manager) AddChannel

func (m *Manager) AddChannel(ch Channel)

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) Channels

func (m *Manager) Channels() []string

Channels returns the list of registered channel names.

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

func (m *Manager) RemoveChannel(name string)

RemoveChannel removes a channel by name.

func (*Manager) Send

func (m *Manager) Send(alert *Alert)

Send dispatches an alert to all matching channels (respects filters).

func (*Manager) SendTest

func (m *Manager) SendTest(channelName string) error

SendTest sends a test alert to a specific channel (bypasses filters).

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

type PushoverConfig struct {
	UserKey  string `json:"user_key"`
	AppToken string `json:"app_token"`
}

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

type TelegramConfig struct {
	BotToken string `json:"bot_token"`
	ChatID   string `json:"chat_id"`
}

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

func GenerateVAPIDKeys() (*VAPIDKeys, error)

GenerateVAPIDKeys creates a new P-256 ECDSA key pair for VAPID.

func LoadVAPIDKeys added in v0.3.3

func LoadVAPIDKeys(publicB64, privateB64 string) (*VAPIDKeys, error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL