Documentation
¶
Index ¶
- func FormatPagerDutyPayload(n Notification, routingKey string) ([]byte, error)
- func FormatSlackPayload(n Notification) ([]byte, error)
- type Action
- type Channel
- type ChannelFieldSchema
- type ChannelRef
- type ChannelSchema
- type DeliveryRecord
- type EmailChannel
- type MaintenanceWindow
- type Notification
- type PagerDutyChannel
- type Route
- type RouteMatch
- type Router
- func (r *Router) AddRoute(route Route) error
- func (r *Router) AddWindow(w MaintenanceWindow) MaintenanceWindow
- func (r *Router) History(limit int) []DeliveryRecord
- func (r *Router) ListRoutes() []Route
- func (r *Router) ListTeams() []Team
- func (r *Router) ListWindows() []MaintenanceWindow
- func (r *Router) LoadChannels(refs []ChannelRef)
- func (r *Router) LoadRoutes(routes []Route)
- func (r *Router) LoadWindows(ws []MaintenanceWindow)
- func (r *Router) Notify(ctx context.Context, n Notification) error
- func (r *Router) RegisterChannel(name string, ch Channel)
- func (r *Router) RemoveRoute(id string) error
- func (r *Router) RemoveWindow(id string) bool
- func (r *Router) SetTeam(team Team, services []string)
- func (r *Router) UpdateRoute(route Route) error
- type SlackChannel
- type Team
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatPagerDutyPayload ¶
func FormatPagerDutyPayload(n Notification, routingKey string) ([]byte, error)
FormatPagerDutyPayload formats a notification as a PagerDuty Events API v2 payload (exported for testing).
func FormatSlackPayload ¶
func FormatSlackPayload(n Notification) ([]byte, error)
FormatSlackPayload formats a notification as a Slack Block Kit payload (exported for testing).
Types ¶
type Action ¶
type Action struct {
Label string `json:"label"`
URL string `json:"url"`
Style string `json:"style"` // "primary", "danger"
}
Action represents an interactive button in a notification.
type Channel ¶
type Channel interface {
Send(ctx context.Context, notification Notification) error
Type() string
}
Channel is the interface that notification channels must implement.
type ChannelFieldSchema ¶
type ChannelFieldSchema struct {
Name string `json:"name"`
Label string `json:"label"`
Type string `json:"type"` // "string", "url", "email", "number"
Required bool `json:"required"`
Secret bool `json:"secret"`
Placeholder string `json:"placeholder,omitempty"`
}
ChannelFieldSchema describes a single config field for a channel type.
type ChannelRef ¶
type ChannelRef struct {
Type string `json:"type"` // "slack", "pagerduty", "email"
Name string `json:"name"` // human-readable name
Config map[string]string `json:"config"` // webhook_url, routing_key, etc.
}
ChannelRef references a configured channel with optional overrides.
type ChannelSchema ¶
type ChannelSchema struct {
Type string `json:"type"`
Description string `json:"description"`
Fields []ChannelFieldSchema `json:"fields"`
}
ChannelSchema describes a channel type's configuration schema for the API.
func AvailableChannelSchemas ¶
func AvailableChannelSchemas() []ChannelSchema
AvailableChannelSchemas returns the config schemas for all built-in channel types.
type DeliveryRecord ¶
type DeliveryRecord struct {
ID string `json:"id"`
Notification Notification `json:"notification"`
ChannelType string `json:"channel_type"`
ChannelName string `json:"channel_name"`
RouteID string `json:"route_id"`
Status string `json:"status"` // "success", "failed"
Error string `json:"error,omitempty"`
Timestamp time.Time `json:"timestamp"`
}
DeliveryRecord tracks a single notification delivery attempt.
type EmailChannel ¶
type EmailChannel struct {
SMTPHost string
SMTPPort int
Username string
Password string
From string
To []string
Name string
}
EmailChannel sends notifications via SMTP.
func NewEmailChannel ¶
func NewEmailChannel(name, host string, port int, username, password, from string, to []string) *EmailChannel
NewEmailChannel creates an email notification channel.
func (*EmailChannel) Send ¶
func (e *EmailChannel) Send(ctx context.Context, n Notification) error
Send delivers a notification via SMTP email.
func (*EmailChannel) Type ¶
func (e *EmailChannel) Type() string
type MaintenanceWindow ¶
type MaintenanceWindow struct {
ID string `json:"id"`
Name string `json:"name"`
Start time.Time `json:"start"`
End time.Time `json:"end"`
Services []string `json:"services,omitempty"`
Severities []string `json:"severities,omitempty"`
}
MaintenanceWindow suppresses notifications during a scheduled time range. An empty Services or Severities slice means "all". This is a routing-layer suppression, distinct from pkg/monitor's per-monitor MutedUntil.
type Notification ¶
type Notification struct {
Title string `json:"title"`
Message string `json:"message"`
Severity string `json:"severity"` // "critical", "warning", "info"
Service string `json:"service"`
URL string `json:"url"` // link back to DevTools
Timestamp time.Time `json:"timestamp"`
Fields map[string]string `json:"fields,omitempty"` // extra key-value pairs
Actions []Action `json:"actions,omitempty"` // interactive buttons
Type string `json:"type"` // "incident", "regression", "slo_breach", "error"
DedupKey string `json:"dedup_key,omitempty"`
}
Notification is the payload sent to notification channels.
type PagerDutyChannel ¶
type PagerDutyChannel struct {
RoutingKey string
Name string
// contains filtered or unexported fields
}
PagerDutyChannel sends notifications via PagerDuty Events API v2.
func NewPagerDutyChannel ¶
func NewPagerDutyChannel(name, routingKey string) *PagerDutyChannel
NewPagerDutyChannel creates a PagerDuty notification channel.
func (*PagerDutyChannel) Send ¶
func (p *PagerDutyChannel) Send(ctx context.Context, n Notification) error
Send delivers a notification to PagerDuty Events API v2.
func (*PagerDutyChannel) SendResolve ¶
func (p *PagerDutyChannel) SendResolve(ctx context.Context, dedupKey string) error
SendResolve sends a resolve event to PagerDuty for a given dedup key.
func (*PagerDutyChannel) Type ¶
func (p *PagerDutyChannel) Type() string
type Route ¶
type Route struct {
ID string `json:"id"`
Name string `json:"name"`
Match RouteMatch `json:"match"`
Channels []ChannelRef `json:"channels"`
Enabled bool `json:"enabled"`
}
Route defines a routing rule that matches notifications to channels.
type RouteMatch ¶
type RouteMatch struct {
Services []string `json:"services,omitempty"` // match specific services (empty = all)
Severities []string `json:"severities,omitempty"` // match severities (empty = all)
Types []string `json:"types,omitempty"` // "incident", "regression", "slo_breach", "error"
}
RouteMatch defines the conditions that a notification must match.
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router matches incoming notifications against routing rules and dispatches them to the appropriate channels. It is safe for concurrent use.
func (*Router) AddWindow ¶
func (r *Router) AddWindow(w MaintenanceWindow) MaintenanceWindow
AddWindow registers a maintenance window, generating an ID if empty.
func (*Router) History ¶
func (r *Router) History(limit int) []DeliveryRecord
History returns recent delivery records.
func (*Router) ListRoutes ¶
ListRoutes returns a copy of all routing rules.
func (*Router) ListWindows ¶
func (r *Router) ListWindows() []MaintenanceWindow
ListWindows returns a copy of the configured maintenance windows.
func (*Router) LoadChannels ¶
func (r *Router) LoadChannels(refs []ChannelRef)
LoadChannels creates and registers channels from ChannelRef configs.
func (*Router) LoadRoutes ¶
LoadRoutes loads routes from config, replacing any existing routes.
func (*Router) LoadWindows ¶
func (r *Router) LoadWindows(ws []MaintenanceWindow)
LoadWindows replaces all maintenance windows (from config).
func (*Router) Notify ¶
func (r *Router) Notify(ctx context.Context, n Notification) error
Notify evaluates all enabled routes against the notification and dispatches to matching channels. Errors from individual channels are logged but do not prevent delivery to other channels (graceful degradation).
func (*Router) RegisterChannel ¶
RegisterChannel adds a pre-built channel to the router.
func (*Router) RemoveRoute ¶
RemoveRoute removes a routing rule by ID.
func (*Router) RemoveWindow ¶
RemoveWindow deletes a maintenance window by ID; reports whether it existed.
func (*Router) SetTeam ¶
SetTeam registers/updates a team and the services it owns. Services map to the team's channels in addition to any direct service→channel routes.
func (*Router) UpdateRoute ¶
UpdateRoute replaces a route by ID.
type SlackChannel ¶
type SlackChannel struct {
WebhookURL string
Name string
// contains filtered or unexported fields
}
SlackChannel sends notifications via Slack Incoming Webhooks using Block Kit.
func NewSlackChannel ¶
func NewSlackChannel(name, webhookURL string) *SlackChannel
NewSlackChannel creates a Slack notification channel.
func (*SlackChannel) Send ¶
func (s *SlackChannel) Send(ctx context.Context, n Notification) error
Send delivers a notification to Slack using Block Kit formatting.
func (*SlackChannel) Type ¶
func (s *SlackChannel) Type() string
type Team ¶
type Team struct {
Name string `json:"name"`
Channels []ChannelRef `json:"channels"`
}
Team owns one or more notification channels. Notifications for a service owned by a team are also delivered to the team's channels (supplementing any direct service→channel routes, which remain unchanged).