notify

package
v0.4.0-beta.5 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2026 License: MIT Imports: 21 Imported by: 0

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

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

type Kind string
const (
	KindGeneric  Kind = "generic"
	KindPositive Kind = "positive"
	KindNegative Kind = "negative"
)

type Notification

type Notification struct {
	Kind    Kind    `json:"type,omitempty"`
	Title   string  `json:"title"`
	Message string  `json:"message"`
	Panels  []Panel `json:"panels,omitempty"`
}

type Panel

type Panel struct {
	Title    string `json:"title,omitempty"`
	Value    string `json:"value,omitempty"`
	Detail   string `json:"detail,omitempty"`
	ImageURL string `json:"image_url,omitempty"`
}

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 NewService(basePath string) *Service

func (*Service) Close

func (s *Service) Close() error

func (*Service) Incidents

func (s *Service) Incidents() []events.Incident

func (*Service) Load

func (s *Service) Load() Config

func (*Service) Notify

func (s *Service) Notify(title, message string) error

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

func (s *Service) NotifyTargets(title, message string, ids []string) error

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

func (s *Service) Publish(event events.Event) (events.IngestResult, error)

func (*Service) Save

func (s *Service) Save(cfg Config) error

func (*Service) Test

func (s *Service) Test(url string) error

Test sends a message to a single URL, so an admin can verify a target before saving it.

func (*Service) TestTarget

func (s *Service) TestTarget(id string) error

func (*Service) Update

func (s *Service) Update(cfg Config) error

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

func (s *Service) UpdateRules(rules []Rule) error

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

func (t Target) MarshalJSON() ([]byte, error)

MarshalJSON masks the credential-bearing URL. YAML persistence does not use this path, so the stored file keeps the real URL.

Jump to

Keyboard shortcuts

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