Package notify/relay
Go module github.com/bide-ai/bide; all packages.
github.com/bide-ai/bide/notify/relay · pkg.go.dev · Stability: experimental
Package relay receives bide's signed webhooks and forwards each verified notification to Slack, PagerDuty, or any other Sink.
Constants
const DefaultAttempts = 3: DefaultAttempts is how many requests one Send may make.const DefaultRequestTimeout = 3 * time.Second: DefaultRequestTimeout bounds each request.const DefaultBackoff = 250 * time.Millisecond: DefaultBackoff is the wait before the second request; it doubles for each further one.const DefaultDedupeSize = 10000: DefaultDedupeSize is how many delivery IDs a Handler remembers.const DefaultForwardTimeout = 8 * time.Second: DefaultForwardTimeout bounds one delivery's forwarding.const DefaultStateFlushDelay = time.Second: DefaultStateFlushDelay is how long a state file write may be deferred and coalesced.const DefaultPagerDutyURL: DefaultPagerDutyURL is the Events API v2 endpoint.const ResolveKind = "resolved": ResolveKind is the notification kind that clears an incident: the notifier's "resolved" kind (agent.NotificationResolved).
Functions
func ClearsID(p notify.Payload) string: ClearsID returns the ID of the event a clear notification ends, or "" if p is not a clear.func DedupKey(p notify.Payload) string: DedupKey is the PagerDuty dedup_key of the incident an event raises: the event's notification ID, the SHA-256 of its key.func DefaultResolveTarget(p notify.Payload) (string, bool): DefaultResolveTarget treats a notification of kind ResolveKind as a resolve of the incident whose dedup key is the ID of the event it clears (ClearsID), and everything else as a trigger.func DefaultSeverity(p notify.Payload) string: DefaultSeverity is the severity of the incident a notification opens: a halt on an unknown outcome, an overdue notification and an escalation are critical (a missed alert is expensive there), an abort and a failing recovery are errors, and an approval waiting is a warning.func KindTitle(kind string) string: KindTitle is the short heading for a notification kind; a kind it does not know is shown as it is with spaces for underscores.func RejectionClass(err error) string: RejectionClass names which check a failed notify.Verify failed, for a log line.
type Config
type Config struct {
Secrets []string
Tolerance time.Duration
Sinks []Sink
DedupeSize int
ClearsID func(notify.Payload) string
StateFlushDelay time.Duration
StatePath string
ForwardTimeout time.Duration
Logf func(format string, args ...any)
}Config configures a Handler.
type Handler
type Handler struct {
// contains filtered or unexported fields
}A Handler is an http.Handler for bide's webhook requests.
Constructors and functions
func New(c Config) (*Handler, error): New returns a Handler, or an error for a configuration that cannot work.
Methods
func (h *Handler) Close() error: Close writes any pending state and releases the state file's lock, so another relay may use the file.func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request): ServeHTTP verifies the request and forwards it.
type PagerDuty
type PagerDuty struct {
// contains filtered or unexported fields
}PagerDuty is a Sink that triggers and resolves PagerDuty incidents through the Events API v2.
Constructors and functions
func NewPagerDuty(c PagerDutyConfig) (*PagerDuty, error): NewPagerDuty returns a PagerDuty sink.
Methods
func (d *PagerDuty) Name() string: Name is "pagerduty".func (d *PagerDuty) Send(ctx context.Context, p notify.Payload) error: Send triggers an incident for p, or resolves one if p is a clear (see ResolveTarget).
type PagerDutyConfig
type PagerDutyConfig struct {
RoutingKey string
URL string
Source string
Severity func(notify.Payload) string
ResolveTarget func(notify.Payload) (dedupKey string, ok bool)
HTTPClient *http.Client
Attempts int
Timeout time.Duration
Backoff time.Duration
}PagerDutyConfig configures a PagerDuty sink.
type PagerDutyEvent
type PagerDutyEvent struct {
RoutingKey string `json:"routing_key"`
EventAction string `json:"event_action"`
DedupKey string `json:"dedup_key"`
Payload *PagerDutyPayload `json:"payload,omitempty"`
Links []PagerDutyLink `json:"links,omitempty"`
}PagerDutyEvent is an Events API v2 request body.
Constructors and functions
func PagerDutyResolve(routingKey, dedupKey string) PagerDutyEvent: PagerDutyResolve builds the resolve of the incident with dedupKey.func PagerDutyTrigger(routingKey, source, severity string, p notify.Payload) PagerDutyEvent: PagerDutyTrigger builds the trigger for p: the dedup key is DedupKey(p), the summary is the generated one, and the details hold the structured fields (run, kind, policy, approvers, deadline, view command).
type PagerDutyLink
type PagerDutyLink struct {
Href string `json:"href"`
Text string `json:"text"`
}PagerDutyLink is a link on an incident.
type PagerDutyPayload
type PagerDutyPayload struct {
Summary string `json:"summary"`
Source string `json:"source"`
Severity string `json:"severity"`
Timestamp string `json:"timestamp,omitempty"`
Component string `json:"component,omitempty"`
Group string `json:"group,omitempty"`
Class string `json:"class,omitempty"`
CustomDetails map[string]any `json:"custom_details,omitempty"`
}PagerDutyPayload is the payload of a trigger.
type Sink
type Sink interface {
Name() string
Send(ctx context.Context, p notify.Payload) error
}A Sink takes a verified notification to somewhere else.
type Slack
type Slack struct {
// contains filtered or unexported fields
}Slack is a Sink that posts a Block Kit message to a Slack incoming webhook.
Constructors and functions
func NewSlack(c SlackConfig) (*Slack, error): NewSlack returns a Slack sink.
Methods
func (s *Slack) Name() string: Name is "slack".func (s *Slack) Send(ctx context.Context, p notify.Payload) error: Send posts p as a message.
type SlackConfig
type SlackConfig struct {
WebhookURL string
ViewURL string
HTTPClient *http.Client
Attempts int
Timeout time.Duration
Backoff time.Duration
}SlackConfig configures a Slack sink.
type SlackMsg
type SlackMsg struct {
Text string `json:"text"`
Blocks []slackBlock `json:"blocks"`
}A SlackMsg is the JSON body of an incoming-webhook post: a plain-text fallback (what a notification or a screen reader shows) and Block Kit blocks.
Constructors and functions
func SlackMessage(p notify.Payload, viewURL string) SlackMsg: SlackMessage formats p as a Slack message: a header naming what happened, the generated summary, the run, kind, deadline and (for an approval) who may decide, and a button to the run viewer when there is a link: the payload's view.url, else viewURL plus the run ID.
type StatusError
type StatusError struct {
Sink string
Status int
Code string
}A StatusError is a non-2xx answer from a third party.
Methods
func (e *StatusError) Error() string: Error names the sink, the status and the code if there is one; never a URL or reply text.