Documentation
¶
Overview ¶
Package notify is FlatRun's core notification service. It stores delivery targets (email, webhook, chat, ... as shoutrrr URLs), routes events to the enabled ones, and can send a test message. It is a core capability: plugins emit events and the core delivers them, so notification configuration lives in one place rather than per plugin.
Index ¶
- Constants
- func RenderEmail(notification Notification) (string, error)
- type Config
- type Kind
- type Notification
- type Panel
- type Rule
- type Service
- func (s *Service) Close() error
- func (s *Service) Incidents() []events.Incident
- func (s *Service) Load() Config
- func (s *Service) Notify(title, message string) error
- func (s *Service) NotifyNotificationTargets(notification Notification, ids []string) error
- func (s *Service) NotifyTargets(title, message string, ids []string) error
- func (s *Service) Publish(event events.Event) (events.IngestResult, error)
- func (s *Service) Save(cfg Config) error
- func (s *Service) Test(url string) error
- func (s *Service) TestTarget(id string) error
- func (s *Service) Update(cfg Config) error
- func (s *Service) UpdateRules(rules []Rule) error
- type Target
Constants ¶
const MaskedURL = "********"
MaskedURL stands in for a target URL in API responses. A shoutrrr URL carries its credentials inline (an SMTP password, a webhook token), so the real URL is never returned to a client; it is written verbatim only to the on-disk store.
Variables ¶
This section is empty.
Functions ¶
func RenderEmail ¶
func RenderEmail(notification Notification) (string, error)
Types ¶
type Config ¶
type Config struct {
Targets []Target `yaml:"targets" json:"targets"`
Rules []Rule `yaml:"rules,omitempty" json:"rules,omitempty"`
}
Config is the persisted notification settings.
type Notification ¶
type Rule ¶
type Rule struct {
ID string `yaml:"id" json:"id"`
Name string `yaml:"name" json:"name"`
Enabled bool `yaml:"enabled" json:"enabled"`
Topics []string `yaml:"topics,omitempty" json:"topics,omitempty"`
EventTypes []string `yaml:"event_types,omitempty" json:"event_types,omitempty"`
Severities []events.Severity `yaml:"severities,omitempty" json:"severities,omitempty"`
Nodes []string `yaml:"nodes,omitempty" json:"nodes,omitempty"`
Deployments []string `yaml:"deployments,omitempty" json:"deployments,omitempty"`
Notifications []events.NotificationAction `yaml:"notifications,omitempty" json:"notifications,omitempty"`
TargetIDs []string `yaml:"target_ids" json:"target_ids"`
}
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service loads/saves targets and delivers messages.
func NewService ¶
func (*Service) Notify ¶
Notify delivers title + message to every enabled target. It returns the first delivery error, if any, but attempts all targets.
func (*Service) NotifyNotificationTargets ¶
func (s *Service) NotifyNotificationTargets(notification Notification, ids []string) error
func (*Service) NotifyTargets ¶
NotifyTargets delivers to a chosen subset of targets by id. An empty list means every enabled target, which is what plain Notify does.
func (*Service) Test ¶
Test sends a message to a single URL, so an admin can verify a target before saving it.
func (*Service) TestTarget ¶
func (*Service) Update ¶
Update saves targets, restoring the stored URL for any target whose incoming URL is the mask: a client that received a masked target and saved it back unchanged must not overwrite the real URL with the mask.
func (*Service) UpdateRules ¶
type Target ¶
type Target struct {
ID string `yaml:"id" json:"id"`
Name string `yaml:"name" json:"name"`
URL string `yaml:"url" json:"url"`
Enabled bool `yaml:"enabled" json:"enabled"`
Topics []string `yaml:"topics,omitempty" json:"topics,omitempty"`
Severities []events.Severity `yaml:"severities,omitempty" json:"severities,omitempty"`
Nodes []string `yaml:"nodes,omitempty" json:"nodes,omitempty"`
Deployments []string `yaml:"deployments,omitempty" json:"deployments,omitempty"`
}
Target is one delivery destination. URL is a shoutrrr service URL, e.g. "smtp://user:pass@host:587/?from=x&to=y" or "generic+https://example.com/hook".
func (Target) MarshalJSON ¶
MarshalJSON masks the credential-bearing URL. YAML persistence does not use this path, so the stored file keeps the real URL.