notifier

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: Apache-2.0 Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

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 FuncMap

func FuncMap() template.FuncMap

FuncMap returns a set of custom template functions for use in notifications.

func MaskedTail added in v0.14.0

func MaskedTail(s string, visible int) string

Masked returns a string with only the last N characters visible, the rest masked with '*'.

func MasqueradeURL added in v0.13.0

func MasqueradeURL(raw string, tailLen int) string

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 *servicehistory.Recorder,
	retries int,
	delay time.Duration,
	bufferSize int,
	metricsReg *metrics.Registry,
) *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.

func (*Dispatcher) UpdateStore added in v0.20.0

func (d *Dispatcher) UpdateStore(store *ReceiverStore)

UpdateStore swaps the receiver store used by the dispatcher.

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 (e *EmailConfig) LastErr() error

func (*EmailConfig) LastSent

func (e *EmailConfig) LastSent() time.Time

func (*EmailConfig) Notify

func (e *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 (e *EmailConfig) Target() string

func (*EmailConfig) Type

func (e *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:"is_html,omitempty"`      // Whether to send as HTML.
	SubjectTmpl string   `yaml:"subject_tmpl,omitempty"` // Subject template.
	BodyTmpl    string   `yaml:"body_tmpl,omitempty"`    // Body template.
}

EmailDetails is a simplified version of the email.Message used by heartbeats.

type Formatter added in v0.20.0

type Formatter interface {
	Format(data NotificationData) (NotificationData, error)
}

Formatter optionally formats notifications before sending.

type MSTeamsConfig

type MSTeamsConfig struct {
	WebhookURL string `yaml:"webhook_url"`          // WebhookURL is the webhook URL for the MSTeams webhook.
	SkipTLS    *bool  `yaml:"skip_tls"`             // SkipTLS skipt TLS check when doing the web request.
	TitleTmpl  string `yaml:"title_tmpl,omitempty"` // TitleTmpl is the title template for the notification.
	TextTmpl   string `yaml:"text_tmpl,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 (*MSTeamsConfig) LastErr

func (m *MSTeamsConfig) LastErr() error

func (*MSTeamsConfig) LastSent

func (m *MSTeamsConfig) LastSent() time.Time

func (*MSTeamsConfig) Notify

func (m *MSTeamsConfig) Notify(ctx context.Context, data NotificationData) error

func (*MSTeamsConfig) Resolve

func (m *MSTeamsConfig) Resolve() error

Resolve interpolates variables in the config.

func (*MSTeamsConfig) Target added in v0.13.0

func (m *MSTeamsConfig) Target() string

func (*MSTeamsConfig) Type

func (m *MSTeamsConfig) Type() string

func (*MSTeamsConfig) Validate

func (m *MSTeamsConfig) Validate() error

Validate ensures required fields are set.

type MSTeamsGraphConfig added in v0.10.0

type MSTeamsGraphConfig struct {
	SkipTLS   *bool  `yaml:"skip_tls"`
	Token     string `yaml:"token"`      // bearer token for Graph API
	TeamID    string `yaml:"team_id"`    // ID of the target team
	ChannelID string `yaml:"channel_id"` // ID of the channel in the team
	TitleTmpl string `yaml:"title_tmpl,omitempty"`
	TextTmpl  string `yaml:"text_tmpl,omitempty"`
	// contains filtered or unexported fields
}

MSTeamsGraphConfig sends notifications to Microsoft Teams via Graph API.

func (*MSTeamsGraphConfig) Format added in v0.10.0

func (*MSTeamsGraphConfig) LastErr added in v0.10.0

func (m *MSTeamsGraphConfig) LastErr() error

func (*MSTeamsGraphConfig) LastSent added in v0.10.0

func (m *MSTeamsGraphConfig) LastSent() time.Time

func (*MSTeamsGraphConfig) Notify added in v0.10.0

Notify sends a channel message via Microsoft Graph API.

func (*MSTeamsGraphConfig) Resolve added in v0.10.0

func (m *MSTeamsGraphConfig) Resolve() error

Resolve resolves templated fields and credentials using a variable resolver.

func (*MSTeamsGraphConfig) Target added in v0.13.0

func (m *MSTeamsGraphConfig) Target() string

func (*MSTeamsGraphConfig) Type added in v0.10.0

func (m *MSTeamsGraphConfig) Type() string

func (*MSTeamsGraphConfig) Validate added in v0.10.0

func (m *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 (*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.
	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 safely masked or display version
	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:"skip_tls"`             // 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:"title_tmpl,omitempty"` // title template
	TextTmpl  string `yaml:"text_tmpl,omitempty"`  // text template
	// contains filtered or unexported fields
}

SlackConfig sends notifications to Slack.

func (*SlackConfig) Format

func (*SlackConfig) LastErr

func (s *SlackConfig) LastErr() error

func (*SlackConfig) LastSent

func (s *SlackConfig) LastSent() time.Time

func (*SlackConfig) Notify

func (s *SlackConfig) Notify(ctx context.Context, data NotificationData) error

func (*SlackConfig) Resolve

func (s *SlackConfig) Resolve() error

Resolve interpolates variables in the config.

func (*SlackConfig) Target added in v0.13.0

func (s *SlackConfig) Target() string

func (*SlackConfig) Type

func (s *SlackConfig) Type() string

Type returns the type of the notifier

func (*SlackConfig) Validate

func (s *SlackConfig) Validate() error

Validate ensures required fields are set.

Jump to

Keyboard shortcuts

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