alerts

package
v0.4.15 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package alerts notifies Slack, Discord, email and webhooks when a scan finds new or regressed findings at or above a severity threshold.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Sign

func Sign(secret, timestamp string, body []byte) string

Sign computes the webhook signature for a timestamp and body.

func VerifyWebhook

func VerifyWebhook(secret, timestamp, signature string, body []byte, now time.Time, maxAge time.Duration) bool

VerifyWebhook checks a received webhook's signature and rejects timestamps older than maxAge, for receivers written in Go.

Types

type Alert

type Alert struct {
	Target       string         `json:"target"`
	ScanID       string         `json:"scan_id"`
	Grade        string         `json:"grade"`
	Score        float64        `json:"score"`
	Threshold    core.Severity  `json:"threshold"`
	New          []core.Finding `json:"new"`
	Regressed    []core.Finding `json:"regressed"`
	DashboardURL string         `json:"dashboard_url,omitempty"`
	At           time.Time      `json:"at"`
}

Alert is one notification: what changed in one scan.

func (Alert) Summary

func (a Alert) Summary() string

Summary is the one-line headline used by every channel.

func (Alert) Text

func (a Alert) Text() string

Text renders the alert as plain text for chat and email.

type Discord

type Discord struct {
	WebhookURL string `json:"webhook_url" yaml:"webhook_url"`
}

Discord posts to a Discord webhook. Messages are capped at 2000 characters.

func (Discord) Name

func (Discord) Name() string

func (Discord) Notify

func (d Discord) Notify(ctx context.Context, a Alert) error

type Dispatcher

type Dispatcher struct {
	Notifiers    []Notifier
	MinSeverity  core.Severity
	DashboardURL string
	Store        storage.Store
	Logger       *slog.Logger
	// Timeout bounds each notifier call.
	Timeout time.Duration
}

Dispatcher turns finished scans into alerts.

func (*Dispatcher) Build

func (d *Dispatcher) Build(ctx context.Context, scanID string) (Alert, error)

Build compares a stored scan with its target's previous scan and returns the alert, or errNothingToSend. Unsaved (ephemeral) scans return storage.ErrNotFound.

func (*Dispatcher) Run

func (d *Dispatcher) Run(ctx context.Context, bus *engine.Bus)

Run listens for scan.finished events until ctx ends.

func (*Dispatcher) Send

func (d *Dispatcher) Send(ctx context.Context, a Alert)

Send delivers an alert to every notifier, logging failures.

type Email

type Email struct {
	Host     string   `json:"host" yaml:"host"`
	Port     int      `json:"port" yaml:"port"`
	Username string   `json:"username,omitempty" yaml:"username"`
	Password string   `json:"-" yaml:"password"`
	From     string   `json:"from" yaml:"from"`
	To       []string `json:"to" yaml:"to"`
}

Email sends alerts over SMTP. smtp.SendMail upgrades to STARTTLS when the server offers it; implicit-TLS port 465 is not supported.

func (Email) Name

func (Email) Name() string

func (Email) Notify

func (e Email) Notify(_ context.Context, a Alert) error

type Notifier

type Notifier interface {
	Name() string
	Notify(ctx context.Context, a Alert) error
}

Notifier delivers an alert to one channel.

type Slack

type Slack struct {
	WebhookURL string `json:"webhook_url" yaml:"webhook_url"`
}

Slack posts to a Slack incoming webhook.

func (Slack) Name

func (Slack) Name() string

func (Slack) Notify

func (s Slack) Notify(ctx context.Context, a Alert) error

type Webhook

type Webhook struct {
	URL    string `json:"url" yaml:"url"`
	Secret string `json:"-" yaml:"secret"`
}

Webhook posts the alert as JSON, signed with HMAC-SHA256 so the receiver can verify it came from Scout:

X-Scout-Timestamp: <unix seconds>
X-Scout-Signature: sha256=<hex HMAC(secret, timestamp + "." + body)>

func (Webhook) Name

func (Webhook) Name() string

func (Webhook) Notify

func (w Webhook) Notify(ctx context.Context, a Alert) error

type WebhookPayload

type WebhookPayload struct {
	Event string `json:"event"`
	Alert
}

WebhookPayload is the JSON body of a webhook alert.

Jump to

Keyboard shortcuts

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