Documentation
¶
Overview ¶
Package notify delivers gantry's deploy/promote/rollback/verify/drift events to configured channels (webhook, email), best-effort.
Index ¶
Constants ¶
const ( KindDeployed = "deployed" KindPromoted = "promoted" KindRolledBack = "rolled_back" KindVerifyFailed = "verify_failed" KindDriftAlarm = "drift_alarm" KindReconcileFailed = "reconcile_failed" )
Event kinds gantry can emit. The config validator and the event constructors reference these so a new kind is added in exactly one place.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Channel ¶
Channel is a notifier plus the event kinds it wants. An empty (nil) Events set means all.
type Dispatcher ¶
type Dispatcher []Channel
Dispatcher fans events out to channels.
func FromConfig ¶ added in v0.12.0
func FromConfig(ctx context.Context, cfg *config.Config, res config.SecretResolver) (Dispatcher, error)
FromConfig builds a Dispatcher from cfg.Notifications, resolving each channel's secrets with res under ctx. An entry's Events become the channel's subscribed kinds (empty = all). Returns an empty (no-op) Dispatcher when no channels are configured. Shared by the daemon and the CLI notification wiring.
func (Dispatcher) Dispatch ¶
func (d Dispatcher) Dispatch(ctx context.Context, events ...Event)
Dispatch sends each event to every subscribed channel. For a single event the subscribed channels are sent concurrently (P4) so slow destinations don't serialize a one-shot CLI run; events themselves are processed in order. Each send is bounded by a per-channel timeout and best-effort: a channel error is logged via the context logger and skipped, never returned, so a broken notification destination can never fail a gantry command. Dispatch runs synchronously so a one-shot CLI run finishes sending before the process exits.
type EmailNotifier ¶
type EmailNotifier struct {
Host string
Port int
Username string
Password string
From string
To []string
// contains filtered or unexported fields
}
EmailNotifier sends one email per event over SMTP. tls selects the transport: "" or "starttls" uses smtp.SendMail (opportunistic STARTTLS); "implicit" dials TLS first (465).
func NewEmailNotifier ¶
func NewEmailNotifier(host string, port int, username, password, from string, to []string, tls string) EmailNotifier
NewEmailNotifier builds an EmailNotifier. tls is "" / "starttls" (opportunistic STARTTLS via smtp.SendMail) or "implicit" (TLS-on-connect, port 465).
func (EmailNotifier) Notify ¶
func (n EmailNotifier) Notify(_ context.Context, e Event) error
Notify sends the event as a single-line email over the configured transport. ctx is accepted for interface symmetry; net/smtp offers no context hook, and the Dispatcher already bounds each send with a timeout.
type Event ¶
type Event struct {
Kind string // deployed | promoted | rolled_back | verify_failed | drift_alarm
Environment string
Commit string
By string
Message string
Time time.Time
}
Event is one thing gantry did (or failed to do) worth reporting. Message is the rendered single line; the other fields populate structured payloads (e.g. the webhook JSON).
type PayloadShape ¶ added in v0.17.0
type PayloadShape string
PayloadShape selects the JSON body a WebhookNotifier posts: the generic structured payload, Telegram's sendMessage shape (chat_id + text), or Slack's minimal {text}. Named kinds are thin wrappers over one webhook core (review D6).
const ( ShapeGeneric PayloadShape = "" // structured fields (kind=webhook) ShapeTelegram PayloadShape = "telegram" // chat_id + text ShapeSlack PayloadShape = "slack" // {"text": …} )
type WebhookNotifier ¶
type WebhookNotifier struct {
URL string
ChatID string // Telegram only; ignored by the other shapes
Shape PayloadShape
Client *http.Client
}
WebhookNotifier POSTs an event as JSON. The payload shape is selected by Shape: the generic structured body (default), Telegram's sendMessage body (chat_id + text), or Slack's minimal {text}. Named notifier kinds (slack/telegram) are thin wrappers over this core (review D6).