Documentation
¶
Overview ¶
Package scriptalert routes the alert a failed scheduled run raises to the notification channels an operator names (#1724).
The alert already reaches the script's owner by email: they are accountable for the automation and can fix it. What this adds is the operations channel beside them, configured once for every script in the platform_settings section this package owns, so a team watching a chat channel sees a nightly automation fail without each owner forwarding it.
Index ¶
Constants ¶
const SettingsSection = "script_run_alert"
SettingsSection is the platform_settings section holding the configuration. It is a stored key: renaming it would strand every deployment's channels behind a section nothing reads.
Variables ¶
var ErrNotFound = errors.New("scriptalert: settings not found")
ErrNotFound is returned by the store when the alert has never been configured. Callers apply the zero Settings, which posts nowhere.
Functions ¶
This section is empty.
Types ¶
type Poster ¶
type Poster struct {
// contains filtered or unexported fields
}
Poster posts a failed run's alert to the configured channels.
func NewPoster ¶
func NewPoster(settings SettingsStore, sender *notifyalert.Sender) *Poster
NewPoster builds the poster, or nil when either dependency is absent.
type Settings ¶
type Settings struct {
Channels []string `json:"channels,omitempty"`
// UpdatedBy and UpdatedAt describe the last admin write. They live in the
// platform_settings audit columns, so they are excluded from the value.
UpdatedBy string `json:"-"`
UpdatedAt time.Time `json:"-"`
}
Settings is the operator's configuration: the channels a failed scheduled run is posted to.
func SettingsOf ¶
func SettingsOf(ctx context.Context, store SettingsStore) (Settings, error)
SettingsOf returns the stored configuration, or the zero Settings when none has been written.
func (Settings) View ¶
func (s Settings) View() SettingsView
View maps stored settings to the read shape, with [] for no channels.
type SettingsInput ¶
type SettingsInput struct {
Channels *[]string `json:"channels,omitempty"`
}
SettingsInput is the write shape. Absent channels keep the stored list; an empty list clears it.
func (*SettingsInput) Settings ¶
func (in *SettingsInput) Settings() Settings
Settings maps the validated input to stored settings.
func (*SettingsInput) Validate ¶
func (in *SettingsInput) Validate() string
Validate trims and de-duplicates the channel list in place and returns a non-empty message when it is invalid. Whether each name is a channel is checked by the admin route, which holds the channel store.
type SettingsStore ¶
type SettingsStore interface {
// Get returns the stored configuration, or ErrNotFound.
Get(ctx context.Context) (*Settings, error)
// Set upserts the configuration.
Set(ctx context.Context, s Settings, author string) error
}
SettingsStore persists the configuration.
func NewPostgresStore ¶
func NewPostgresStore(db *sql.DB) SettingsStore
NewPostgresStore creates the store over db.