Documentation
¶
Overview ¶
Package alerting provides a unified notification dispatcher for Prism.
All budget alerts, shortfall warnings, and cushion triggers route through AlertDispatcher so the delivery backend can be swapped without changing callers. The default backend (LogDispatcher) always writes to stdout/stderr — no external dependencies required for basic operation.
Index ¶
- type Alert
- func FormatAutoActionAlert(projectID, projectName string, action types.BudgetActionType, ...) Alert
- func FormatBudgetThresholdAlert(projectID, projectName string, threshold, spentAmount, totalBudget float64) Alert
- func FormatCushionAlert(projectID, projectName string, headroomPct, remaining, total float64, ...) Alert
- func FormatShortfallAlert(projectID, projectName string, dailyRate float64, daysUntil int, ...) Alert
- type AlertDispatcher
- type AlertSeverity
- type Channel
- type ChannelType
- type LogDispatcher
- type SentAlert
- type WebhookConfig
- type WebhookDispatcher
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Alert ¶
type Alert struct {
ID string `json:"id"`
Severity AlertSeverity `json:"severity"`
Title string `json:"title"`
Body string `json:"body"`
ProjectID string `json:"project_id,omitempty"`
ProjectName string `json:"project_name,omitempty"`
Tags map[string]string `json:"tags,omitempty"`
Channels []Channel `json:"channels"`
CreatedAt time.Time `json:"created_at"`
}
Alert is the canonical notification payload.
func FormatAutoActionAlert ¶
func FormatAutoActionAlert(projectID, projectName string, action types.BudgetActionType, spentAmount, totalBudget float64) Alert
FormatAutoActionAlert creates an Alert when an automatic budget action executes.
func FormatBudgetThresholdAlert ¶
func FormatBudgetThresholdAlert(projectID, projectName string, threshold, spentAmount, totalBudget float64) Alert
FormatBudgetThresholdAlert creates an Alert when a budget threshold is crossed.
type AlertDispatcher ¶
type AlertDispatcher interface {
Send(ctx context.Context, alert Alert) error
SendBatch(ctx context.Context, alerts []Alert) error
// History returns the most recent sent alerts (up to limit).
History(limit int) []SentAlert
}
AlertDispatcher is the unified notification interface.
type AlertSeverity ¶
type AlertSeverity string
AlertSeverity classifies the urgency of an alert.
const ( AlertSeverityInfo AlertSeverity = "info" AlertSeverityWarning AlertSeverity = "warning" AlertSeverityCritical AlertSeverity = "critical" )
type Channel ¶
type Channel struct {
Type ChannelType `json:"type"`
Target string `json:"target"` // email addr, webhook URL, etc.
Options map[string]string `json:"options,omitempty"`
}
Channel defines a single notification destination.
type ChannelType ¶
type ChannelType string
ChannelType identifies a notification delivery mechanism.
const ( ChannelLog ChannelType = "log" // always active — stdout/stderr ChannelEmail ChannelType = "email" ChannelSlack ChannelType = "slack" ChannelWebhook ChannelType = "webhook" ChannelDesktop ChannelType = "desktop" // OS desktop notification )
type LogDispatcher ¶
type LogDispatcher struct {
// contains filtered or unexported fields
}
LogDispatcher is the default no-dependency AlertDispatcher. It writes every alert to stdout/stderr and keeps an in-memory history. Used when no external notification channels are configured.
func NewLogDispatcher ¶
func NewLogDispatcher() *LogDispatcher
NewLogDispatcher creates a LogDispatcher.
func (*LogDispatcher) History ¶
func (d *LogDispatcher) History(limit int) []SentAlert
History returns the most recent sent alerts up to limit.
type SentAlert ¶
type SentAlert struct {
Alert Alert `json:"alert"`
SentAt time.Time `json:"sent_at"`
Succeeded bool `json:"succeeded"`
Error string `json:"error,omitempty"`
}
SentAlert records a delivery attempt.
type WebhookConfig ¶
type WebhookConfig struct {
Channels []Channel
RetryCount int // default 2
Timeout time.Duration // default 10s
}
WebhookConfig configures the WebhookDispatcher.
type WebhookDispatcher ¶
type WebhookDispatcher struct {
// contains filtered or unexported fields
}
WebhookDispatcher sends alerts to one or more HTTP endpoints (Slack, generic webhook). Falls back to LogDispatcher for any channel that fails after retries.
func NewWebhookDispatcher ¶
func NewWebhookDispatcher(cfg WebhookConfig) *WebhookDispatcher
NewWebhookDispatcher creates a dispatcher that delivers to all configured channels.
func (*WebhookDispatcher) History ¶
func (d *WebhookDispatcher) History(limit int) []SentAlert
History returns the most recent sent alerts.