scriptalert

package
v1.143.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

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

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

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

func (*Poster) Post

func (p *Poster) Post(ctx context.Context, key string, payload notification.Payload) (int, error)

Post sends the alert under key to the configured channels and returns how many it was queued for. A failure to read the settings is returned for the caller to log; it posts nowhere and fails nothing else.

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.

type SettingsView

type SettingsView struct {
	Channels  []string  `json:"channels"`
	UpdatedBy string    `json:"updated_by,omitempty" example:"admin@example.com"`
	UpdatedAt time.Time `json:"updated_at"`
}

SettingsView is the read shape.

Jump to

Keyboard shortcuts

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