Documentation
¶
Index ¶
- func FormatEmailRecipients(details EmailDetails) string
- func FuncMap() template.FuncMap
- func MasqueradeURL(raw string, tailLen int) string
- type Dispatcher
- type EmailConfig
- func (ec *EmailConfig) Format(data NotificationData) (NotificationData, error)
- func (en *EmailConfig) LastErr() error
- func (en *EmailConfig) LastSent() time.Time
- func (en *EmailConfig) Notify(ctx context.Context, data NotificationData) error
- func (ec *EmailConfig) Resolve() error
- func (en *EmailConfig) Target() string
- func (en *EmailConfig) Type() string
- func (ec *EmailConfig) Validate() error
- type EmailDetails
- type MSTeamsConfig
- func (mc *MSTeamsConfig) Format(data NotificationData) (NotificationData, error)
- func (mc *MSTeamsConfig) LastErr() error
- func (mc *MSTeamsConfig) LastSent() time.Time
- func (mc *MSTeamsConfig) Notify(ctx context.Context, data NotificationData) error
- func (mc *MSTeamsConfig) Resolve() error
- func (mc *MSTeamsConfig) Target() string
- func (mc *MSTeamsConfig) Type() string
- func (mc *MSTeamsConfig) Validate() error
- type MSTeamsGraphConfig
- func (c *MSTeamsGraphConfig) Format(data NotificationData) (NotificationData, error)
- func (c *MSTeamsGraphConfig) LastErr() error
- func (c *MSTeamsGraphConfig) LastSent() time.Time
- func (c *MSTeamsGraphConfig) Notify(ctx context.Context, data NotificationData) error
- func (c *MSTeamsGraphConfig) Resolve() error
- func (c *MSTeamsGraphConfig) Target() string
- func (c *MSTeamsGraphConfig) Type() string
- func (c *MSTeamsGraphConfig) Validate() error
- type MockNotifier
- func (m *MockNotifier) Format(data NotificationData) (NotificationData, error)
- func (m *MockNotifier) LastErr() error
- func (m *MockNotifier) LastSent() time.Time
- func (m *MockNotifier) Notify(ctx context.Context, data NotificationData) error
- func (m *MockNotifier) Resolve() error
- func (m *MockNotifier) Target() string
- func (m *MockNotifier) Type() string
- func (m *MockNotifier) Validate() error
- type NotificationData
- type NotificationInfo
- type Notifier
- func NewEmailNotifier(id string, cfg EmailConfig, logger *slog.Logger, sender email.Sender) Notifier
- func NewMSTeamsGraphNotifier(id string, cfg MSTeamsGraphConfig, logger *slog.Logger, ...) Notifier
- func NewSlackNotifier(id string, cfg SlackConfig, logger *slog.Logger, sender slack.Sender) Notifier
- type ReceiverConfig
- type ReceiverStore
- type SlackConfig
- func (sn *SlackConfig) Format(data NotificationData) (NotificationData, error)
- func (sn *SlackConfig) LastErr() error
- func (sn *SlackConfig) LastSent() time.Time
- func (sn *SlackConfig) Notify(ctx context.Context, data NotificationData) error
- func (sn *SlackConfig) Resolve() error
- func (sn *SlackConfig) Target() string
- func (sn *SlackConfig) Type() string
- func (sn *SlackConfig) Validate() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatEmailRecipients ¶ added in v0.13.0
func FormatEmailRecipients(details EmailDetails) string
FormatEmailRecipients returns a string representation of all email recipients.
func MasqueradeURL ¶ added in v0.13.0
MasqueradeURL hides most of a URL, showing only scheme, host, and last N characters of path.
Types ¶
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
Dispatcher handles queued notifications via mailbox.
func NewDispatcher ¶
func NewDispatcher( store *ReceiverStore, logger *slog.Logger, hist history.Store, retries int, delay time.Duration, bufferSize int, ) *Dispatcher
NewDispatcher returns a Dispatcher backed by the given store.
func (*Dispatcher) Get ¶
func (d *Dispatcher) Get(id string) []Notifier
Get returns notifiers for a receiver.
func (*Dispatcher) List ¶
func (d *Dispatcher) List() map[string][]Notifier
List returns all configured notifiers.
func (*Dispatcher) Mailbox ¶ added in v0.13.0
func (d *Dispatcher) Mailbox() chan<- NotificationData
Mailbox returns the channel to send NotificationData.
func (*Dispatcher) Run ¶ added in v0.13.0
func (d *Dispatcher) Run(ctx context.Context)
Dispatch looks up each receiver’s Notifiers and fires them in parallel, recording the outcome in d.states. Run processes NotificationData from the mailbox.
type EmailConfig ¶
type EmailConfig struct {
SMTPConfig email.SMTPConfig `yaml:"smtp"` // SMTPConfig is the SMTP configuration.
EmailDetails EmailDetails `yaml:"email"` // EmailDetails is the email message details.
// contains filtered or unexported fields
}
EmailConfig holds the configuration for sending email notifications.
func (*EmailConfig) Format ¶
func (ec *EmailConfig) Format(data NotificationData) (NotificationData, error)
func (*EmailConfig) LastErr ¶
func (en *EmailConfig) LastErr() error
func (*EmailConfig) LastSent ¶
func (en *EmailConfig) LastSent() time.Time
func (*EmailConfig) Notify ¶
func (en *EmailConfig) Notify(ctx context.Context, data NotificationData) error
Notify formats and sends the email using the configured SMTP settings.
func (*EmailConfig) Resolve ¶
func (ec *EmailConfig) Resolve() error
Resolve interpolates variables in the config.
func (*EmailConfig) Target ¶ added in v0.13.0
func (en *EmailConfig) Target() string
func (*EmailConfig) Type ¶
func (en *EmailConfig) Type() string
func (*EmailConfig) Validate ¶
func (ec *EmailConfig) Validate() error
Resolve interpolates env variables in the config.
type EmailDetails ¶
type EmailDetails struct {
To []string `yaml:"to"` // List of recipients.
CC []string `yaml:"cc,omitempty"` // List of CCs.
BCC []string `yaml:"bcc,omitempty"` // List of BCCs.
IsHTML bool `yaml:"isHTML,omitempty"` // Whether to send as HTML.
SubjectTmpl string `yaml:"subjectTemplate,omitempty"` // Subject template.
BodyTmpl string `yaml:"bodyTemplate,omitempty"` // Body template.
}
EmailDetails is a simplified version of the email.Message used by heartbeats.
type MSTeamsConfig ¶
type MSTeamsConfig struct {
WebhookURL string `yaml:"webhook_url"` // WebhookURL is the webhook URL for the MSTeams webhook.
SkipTLS *bool `yaml:"skipTLS"` // SkipTLS skipt TLS check when doing the web request.
TitleTmpl string `yaml:"titleTemplate,omitempty"` // TitleTmpl is the title template for the notification.
TextTmpl string `yaml:"textTemplate,omitempty"` // TextTmpl is the text template for the notification.
// contains filtered or unexported fields
}
MSTeamsConfig sends notifications to MSTeams.
func NewMSTeamsNotifier ¶
func NewMSTeamsNotifier(id string, cfg MSTeamsConfig, logger *slog.Logger, sender msteams.Sender) *MSTeamsConfig
NewMSTeamsNotifier creates a new MSTeamsNotifier for a single MSTeams configuration.
func (*MSTeamsConfig) Format ¶
func (mc *MSTeamsConfig) Format(data NotificationData) (NotificationData, error)
func (*MSTeamsConfig) LastErr ¶
func (mc *MSTeamsConfig) LastErr() error
func (*MSTeamsConfig) LastSent ¶
func (mc *MSTeamsConfig) LastSent() time.Time
func (*MSTeamsConfig) Notify ¶
func (mc *MSTeamsConfig) Notify(ctx context.Context, data NotificationData) error
func (*MSTeamsConfig) Resolve ¶
func (mc *MSTeamsConfig) Resolve() error
Resolve interpolates variables in the config.
func (*MSTeamsConfig) Target ¶ added in v0.13.0
func (mc *MSTeamsConfig) Target() string
func (*MSTeamsConfig) Type ¶
func (mc *MSTeamsConfig) Type() string
func (*MSTeamsConfig) Validate ¶
func (mc *MSTeamsConfig) Validate() error
Validate ensures required fields are set.
type MSTeamsGraphConfig ¶ added in v0.10.0
type MSTeamsGraphConfig struct {
SkipTLS *bool `yaml:"skipTLS"`
Token string `yaml:"token"` // bearer token for Graph API
TeamID string `yaml:"teamID"` // ID of the target team
ChannelID string `yaml:"channelID"` // ID of the channel in the team
TitleTmpl string `yaml:"titleTemplate,omitempty"`
TextTmpl string `yaml:"textTemplate,omitempty"`
// contains filtered or unexported fields
}
MSTeamsGraphConfig sends notifications to Microsoft Teams via Graph API.
func (*MSTeamsGraphConfig) Format ¶ added in v0.10.0
func (c *MSTeamsGraphConfig) Format(data NotificationData) (NotificationData, error)
func (*MSTeamsGraphConfig) LastErr ¶ added in v0.10.0
func (c *MSTeamsGraphConfig) LastErr() error
func (*MSTeamsGraphConfig) LastSent ¶ added in v0.10.0
func (c *MSTeamsGraphConfig) LastSent() time.Time
func (*MSTeamsGraphConfig) Notify ¶ added in v0.10.0
func (c *MSTeamsGraphConfig) Notify(ctx context.Context, data NotificationData) error
Notify sends a channel message via Microsoft Graph API.
func (*MSTeamsGraphConfig) Resolve ¶ added in v0.10.0
func (c *MSTeamsGraphConfig) Resolve() error
Resolve resolves templated fields and credentials using a variable resolver.
func (*MSTeamsGraphConfig) Target ¶ added in v0.13.0
func (c *MSTeamsGraphConfig) Target() string
func (*MSTeamsGraphConfig) Type ¶ added in v0.10.0
func (c *MSTeamsGraphConfig) Type() string
func (*MSTeamsGraphConfig) Validate ¶ added in v0.10.0
func (c *MSTeamsGraphConfig) Validate() error
Validate ensures required configuration fields are set correctly.
type MockNotifier ¶
type MockNotifier struct {
TypeName string // optional custom type name returned by Type()
TargetName string // optional custom target name returned by Target()
Sent time.Time // mock timestamp returned by LastSent()
FormatFunc func(NotificationData) (NotificationData, error) // optional override for Format behavior
NotifyFunc func(ctx context.Context, data NotificationData) error // optional override for Notify behavior
// contains filtered or unexported fields
}
MockNotifier is a test implementation of the Notifier interface.
func (*MockNotifier) Format ¶
func (m *MockNotifier) Format(data NotificationData) (NotificationData, error)
func (*MockNotifier) LastErr ¶
func (m *MockNotifier) LastErr() error
func (*MockNotifier) LastSent ¶
func (m *MockNotifier) LastSent() time.Time
func (*MockNotifier) Notify ¶
func (m *MockNotifier) Notify(ctx context.Context, data NotificationData) error
func (*MockNotifier) Resolve ¶
func (m *MockNotifier) Resolve() error
func (*MockNotifier) Target ¶ added in v0.13.0
func (m *MockNotifier) Target() string
func (*MockNotifier) Type ¶
func (m *MockNotifier) Type() string
func (*MockNotifier) Validate ¶
func (m *MockNotifier) Validate() error
type NotificationData ¶
type NotificationData struct {
ID string `json:"id"` // heartbeat ID
Name string `json:"name"` // human-friendly name
Description string `json:"description"` // heartbeat description
LastBump time.Time `json:"lastPing"` // time of last ping
Status string `json:"status"` // current status
Receivers []string `json:"receivers"` // list of receiver IDs
Title string `json:"title"` // rendered notification title
Message string `json:"message"` // rendered notification body
}
NotificationData is the payload for alerts.
type NotificationInfo ¶ added in v0.11.1
type NotificationInfo struct {
Receiver string // target receiver ID
Target string // target of the notification
Type string // type of the notification
Error error // nil if successful, otherwise contains the send error
}
NotificationInfo contains the outcome of a notification attempt.
type Notifier ¶
type Notifier interface {
Notify(ctx context.Context, data NotificationData) error // Notify sends a notification.
Format(data NotificationData) (NotificationData, error) // Format formats the notification title and text.
Validate() error // Validate checks whether the notifier is correctly configured.
Resolve() error // Resolve performs any necessary resolution (e.g., secrets, tokens).
LastErr() error // LastError reports whether the last notification attempt succeeded.
Type() string // Type returns the notifier's type, e.g., "slack", "email", "teams".
Target() string // Target returns the notifier's target, e.g., "slack-channel", "email-address",
LastSent() time.Time // LastSent returns the timestamp of the last notification attempt.
}
Notifier defines methods for sending notifications.
func NewEmailNotifier ¶
func NewEmailNotifier(id string, cfg EmailConfig, logger *slog.Logger, sender email.Sender) Notifier
NewEmailNotifier creates a new EmailConfig notifier.
func NewMSTeamsGraphNotifier ¶ added in v0.10.0
func NewMSTeamsGraphNotifier(id string, cfg MSTeamsGraphConfig, logger *slog.Logger, sender msteamsgraph.Sender) Notifier
NewMSTeamsGraphNotifier constructs a new Teams Graph notifier.
func NewSlackNotifier ¶
func NewSlackNotifier(id string, cfg SlackConfig, logger *slog.Logger, sender slack.Sender) Notifier
NewSlackNotifier creates a Slack notifier.
type ReceiverConfig ¶
type ReceiverConfig struct {
SlackConfigs []SlackConfig `yaml:"slack_configs,omitempty"` // SlackConfigs is the list of Slack configurations.
EmailConfigs []EmailConfig `yaml:"email_configs,omitempty"` // EmailConfigs is the list of email configurations.
MSTeamsConfigs []MSTeamsConfig `yaml:"msteams_configs,omitempty"` // MSTeamsConfigs is the list of MSTeams configurations.
MSTeamsGraphConfig []MSTeamsGraphConfig `yaml:"msteamsgraph_configs,omitempty"` // MSTeamsGraphConfigs is the list of MSTeamsGraph configurations.
}
ReceiverConfig holds receiver-specific configurations.
type ReceiverStore ¶
type ReceiverStore struct {
// contains filtered or unexported fields
}
ReceiverStore holds a mapping from receiver ID to a slice of Notifiers.
func InitializeStore ¶
func InitializeStore(cfg map[string]ReceiverConfig, globalSkipTLS bool, version string, logger *slog.Logger) *ReceiverStore
InitializeStore builds a store from the receiver configuration.
func NewReceiverStore ¶ added in v0.10.0
func NewReceiverStore() *ReceiverStore
NewReceiverStore creates an empty ReceiverStore.
func (*ReceiverStore) List ¶ added in v0.13.0
func (s *ReceiverStore) List() map[string][]Notifier
List returns all configured notifiers.
func (*ReceiverStore) Register ¶ added in v0.10.0
func (s *ReceiverStore) Register(receiverID string, n Notifier)
Register adds a Notifier to the list for a given receiver ID.
type SlackConfig ¶
type SlackConfig struct {
SkipTLS *bool `yaml:"skipTLS"` // SkipTLS skipt TLS check when doing the web request.
Channel string `yaml:"channel"` // Slack channel
Token string `yaml:"token"` // Slack API token
Username string `yaml:"username,omitempty"` // display username
TitleTmpl string `yaml:"titleTemplate,omitempty"` // title template
TextTmpl string `yaml:"textTemplate,omitempty"` // text template
// contains filtered or unexported fields
}
SlackConfig sends notifications to Slack.
func (*SlackConfig) Format ¶
func (sn *SlackConfig) Format(data NotificationData) (NotificationData, error)
func (*SlackConfig) LastErr ¶
func (sn *SlackConfig) LastErr() error
func (*SlackConfig) LastSent ¶
func (sn *SlackConfig) LastSent() time.Time
func (*SlackConfig) Notify ¶
func (sn *SlackConfig) Notify(ctx context.Context, data NotificationData) error
func (*SlackConfig) Resolve ¶
func (sn *SlackConfig) Resolve() error
Resolve interpolates variables in the config.
func (*SlackConfig) Target ¶ added in v0.13.0
func (sn *SlackConfig) Target() string
func (*SlackConfig) Type ¶
func (sn *SlackConfig) Type() string
Type returns the type of the notifier
func (*SlackConfig) Validate ¶
func (sn *SlackConfig) Validate() error
Validate ensures required fields are set.