Documentation
¶
Index ¶
- func FuncMap() template.FuncMap
- 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) 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) Type() string
- func (mc *MSTeamsConfig) 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) Type() string
- func (m *MockNotifier) Validate() error
- type NotificationData
- type 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) Type() string
- func (sn *SlackConfig) Validate() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
Dispatcher sends alerts to all Notifiers in the ReceiverStore.
func NewDispatcher ¶
func NewDispatcher(store *ReceiverStore, logger *slog.Logger, hist history.Store, retries int, delay time.Duration) *Dispatcher
NewDispatcher returns a Dispatcher backed by the given store.
func (*Dispatcher) Dispatch ¶
func (d *Dispatcher) Dispatch(ctx context.Context, data NotificationData)
Dispatch looks up each receiver’s Notifiers and fires them in parallel, recording the outcome in d.states.
func (*Dispatcher) Get ¶
func (d *Dispatcher) Get(id string) []Notifier
Get returns one notifier’s info by ID.
func (*Dispatcher) List ¶
func (d *Dispatcher) List() map[string][]Notifier
List returns all configured notifier.
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) 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) Type ¶
func (mc *MSTeamsConfig) Type() string
func (*MSTeamsConfig) Validate ¶
func (mc *MSTeamsConfig) Validate() error
Validate ensures required fields are set.
type MockNotifier ¶
type MockNotifier struct {
TypeName string // optional custom type name returned by Type()
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) 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 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".
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 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.
}
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.
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) 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.