notify

package
v0.0.0-...-a02776c Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package notify ships incoming-webhook alerts for Slack and Teams. Sprint 15 (Phase 5.3): post a one-line summary per high-severity finding to one or both endpoints, with an in-memory dedup window that suppresses duplicate alerts for the same finding ID.

The package is designed to be embeddable in three places:

  • `fendix notify --findings findings.json` (one-shot CLI). The `cmd/fendix` subcommand wires Config from env vars, reads findings from disk, calls (*Notifier).NotifyAll, and exits.

  • Future `fendix serve` post-scan-complete hook (Sprint 07). The serve loop instantiates one Notifier per process and calls NotifyAll after every scan completes; dedup state is shared across scans within the process lifetime.

  • The GitHub App handler's post-scan path (Sprint 13). Hooks into ghapp.Handler.runScan after the PR comment posts.

The dedup map is in-memory only: process restart re-alerts on the same findings. Sprint 15.5 (depends on Sprint 07.5 SQLite) persists the dedup state.

Index

Constants

View Source
const (
	EnvSlackWebhookURL = "FENDIX_SLACK_WEBHOOK_URL"
	EnvTeamsWebhookURL = "FENDIX_TEAMS_WEBHOOK_URL"
	EnvMinSeverity     = "FENDIX_NOTIFY_MIN_SEVERITY"
	EnvDedupWindow     = "FENDIX_NOTIFY_DEDUP_WINDOW"
)

EnvVar names recognised by NewFromEnv. Kept in one place so the CLI --help text can list them without divergence.

Variables

View Source
var ErrEmptyConfig = errors.New("notify: no FENDIX_SLACK_WEBHOOK_URL or FENDIX_TEAMS_WEBHOOK_URL set")

ErrEmptyConfig is returned by NewFromEnv when no webhook URL is set. Callers can errors.Is-check it to differentiate "user didn't configure notify" from a real config error.

Functions

func SlackPayload

func SlackPayload(f models.Finding) map[string]any

SlackPayload builds a Block Kit message for one finding. The shape matches the sprint-15 brief's Slack section.

Slack accepts arbitrary JSON via incoming-webhook; we keep the schema strict enough that block-kit-builder.tools/slack.dev/block-kit validates without warnings. Color-by-severity is conveyed via emoji in the section text (Slack doesn't expose the attachment-color API to incoming webhooks).

func TeamsPayload

func TeamsPayload(f models.Finding) map[string]any

TeamsPayload builds an Adaptive Card 1.3 message for one finding. Adaptive Card 1.3 is broadly supported across Teams desktop, mobile, and the web client; 1.4+ adds features (e.g. input.text) we don't need for read-only alerts, and 1.3's compatibility surface is the widest. Pinning the schema version lets Teams ignore future Microsoft changes that break newer versions.

Types

type Config

type Config struct {
	// SlackWebhookURL is a Slack incoming-webhook URL
	// (https://hooks.slack.com/services/...). Empty disables.
	SlackWebhookURL string

	// TeamsWebhookURL is a Teams incoming-webhook URL
	// (https://outlook.office.com/webhook/... or
	// https://*.webhook.office.com/...). Empty disables.
	TeamsWebhookURL string

	// MinSeverity is the floor for alerts. Findings strictly below this
	// severity are silently skipped. Default: CRITICAL.
	MinSeverity models.Severity

	// DedupWindow is the duration during which a repeat alert for the
	// same finding ID is suppressed. Default: 1 hour. Set
	// DisableDedup to opt out entirely.
	DedupWindow time.Duration

	// DisableDedup turns off the in-memory dedup map. Every qualifying
	// finding alerts on every NotifyAll call. Useful for test fixtures
	// and short-lived CI runs where dedup state is meaningless.
	DisableDedup bool

	// HTTPClient is reused across Notify calls. Nil uses
	// http.DefaultClient with a 10s timeout.
	HTTPClient *http.Client

	// Now lets tests inject a clock. Production callers leave nil
	// (time.Now is used).
	Now func() time.Time
}

Config controls per-process notifier behaviour. Zero-value fields disable the corresponding sink; a Config with both webhook URLs empty is a no-op notifier.

type Notifier

type Notifier struct {
	// contains filtered or unexported fields
}

Notifier holds the resolved Config plus the dedup map. Construct via NewNotifier; methods are safe for concurrent use.

func NewFromEnv

func NewFromEnv() (*Notifier, error)

NewFromEnv reads notify Config from environment variables. Used by the `fendix notify` CLI subcommand and by future serve / ghapp integrations.

At least one of FENDIX_SLACK_WEBHOOK_URL or FENDIX_TEAMS_WEBHOOK_URL must be set; otherwise NewFromEnv returns ErrEmptyConfig so callers can errors.Is-distinguish "user didn't configure notify" from a malformed value.

Defaults:

  • FENDIX_NOTIFY_MIN_SEVERITY: CRITICAL
  • FENDIX_NOTIFY_DEDUP_WINDOW: 1h (Go duration string, e.g. "30m", "2h"). Set to "0" to disable dedup entirely (every alert fires).

func NewNotifier

func NewNotifier(cfg Config) *Notifier

NewNotifier constructs a Notifier from cfg. Sensible defaults are applied for zero-valued fields:

  • MinSeverity defaults to CRITICAL
  • DedupWindow defaults to 1 hour
  • HTTPClient defaults to a 10s-timeout client
  • Now defaults to time.Now

func (*Notifier) Enabled

func (n *Notifier) Enabled() bool

Enabled reports whether the notifier has at least one configured sink. A no-op notifier (both URLs empty) is useful as a default in hot paths so callers don't have to nil-check.

func (*Notifier) NotifyAll

func (n *Notifier) NotifyAll(ctx context.Context, findings []models.Finding) []SinkResult

NotifyAll iterates findings and posts qualifying ones to all configured sinks. Each finding is processed independently: a sink failure on one finding does not abort the next. Returns the full list of SinkResult entries so callers can log / surface per-attempt outcomes.

The returned error is non-nil only when the *first* per-finding per-sink call hit an unrecoverable error AND every subsequent attempt also failed — the orchestrator-level "notify completely broken" signal. Otherwise individual failures live in the SinkResult.Err fields.

type SinkResult

type SinkResult struct {
	Sink    string // "slack" or "teams"
	Finding string // finding ID
	Sent    bool
	Skipped string // "below_min_severity" | "dedup" | ""
	Err     error
}

SinkResult records the outcome of posting to one webhook. Both sinks are attempted independently per finding; one failing does not block the other.

Jump to

Keyboard shortcuts

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