Skip to content
suprbdevPublic

About

A single-binary, config-driven notification CLI.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

noty

A single-binary, config-driven notification CLI. One tool, any channel: email (SMTP and SMTP-compatible providers), Slack/Discord/Teams webhooks, SMS gateways, push services, arbitrary API calls, and anything else via a local command escape hatch.

echo "deploy finished" | noty --channel slack
noty -m "disk 92% full" --channel email,sms --to +15551234567
noty -m "release v2.4" --var environment=prod --dry-run

Install

go install github.com/suprbdev/noty@latest

or from a checkout:

go build -o noty .

Design

  • YAML config defines named channels. Each channel has a type (the connection/provider) plus provider-specific settings.
  • Three provider types cover everything:
    • smtp — email, including SES/SendGrid/Mailgun/Postmark SMTP endpoints.
    • http — webhooks, REST APIs, SMS gateways (Twilio-style form posts), push services (Pushover, ntfy, Gotify), PagerDuty, etc. URL, headers, form fields, and body are all templates.
    • exec — escape hatch: run any local command (vendor CLIs like aws sns publish, signal-cli, custom scripts). Body is piped to stdin, args are templates.
  • Secrets stay in the environment. Use ${VAR} anywhere in the config; loading fails loudly if a variable is unset. ${VAR:-default} allows a fallback, $$ escapes a literal dollar. --dry-run output and error messages show values substituted via ${VAR} (4+ bytes, raw or URL-escaped) as ${VAR}, and header/query/form fields named like credentials as REDACTED. Values read with the env template function are not masked.
  • Templates live outside the binary as plain files (Go text/template syntax), resolved relative to template_dir, or inline in the config.

Config resolution

--config PATH → $NOTY_CONFIG → ~/.config/noty/config.yaml (or .yml) → /etc/noty/config.yaml

The current directory is never searched: a config can run exec commands, so a checked-out repo must not be able to supply one. Use -c ./noty.yaml for a project-local file.

See noty.example.yaml for a full example with eight channels.

Message and template resolution

Message text: --message flag, else piped stdin. With neither, noty refuses to run from an interactive terminal (-m '' sends an empty message); stdin of /dev/null, as under cron or systemd, is an empty message.

Body: --template FILE flag → channel body_template (file) → channel body (inline) → raw message text.

Subject: the base subject is --subject, else defaults.subject (a template). A channel subject_template / subject renders with the base as {{ .Subject }} (e.g. "[prod] {{ .Subject }}"); without one the base is used as is.

Template variables merge in order: global vars → channel vars → --var key=value flags (repeatable, later wins).

Template data

Field Meaning
{{ .Message }} raw message text
{{ .Subject }} resolved subject (the base subject inside a channel subject template)
{{ .To }} recipients from --to ({{ index .To 0 }} for the first)
{{ .Channel }} channel name
{{ .Vars.key }} merged variables
{{ .Now }} send time ({{ timefmt "15:04" .Now }})
{{ .Hostname }} sending host

Functions: json (safe JSON encoding — always use it when building JSON payloads), upper, lower, title, trim, replace, join, split, contains, default, urlquery, truncate, timefmt, env, plus the text/template builtins (html for escaping into HTML bodies, printf, index, ...).

Referencing an undefined variable is an error, so typos fail loudly. For an optional variable use index, which yields "" when the key is absent: {{ default "general" (index .Vars "topic") }}.

Flags

-c, --config     config file path
    --channel    channel name(s), comma-separated for fan-out
-m, --message    message text (else stdin)
-s, --subject    subject override
-t, --template   body template file override
    --to         recipient override (repeatable)
-v, --var        key=value template variable (repeatable)
    --timeout    per-attempt send timeout (default 30s or defaults.timeout)
    --retries    retry temporary failures N times (default: channel or defaults.retries)
    --dry-run    render and print what would be sent (secrets redacted)
    --list       list configured channels
    --verbose    verbose output
    --version    print version and exit

Fan-out channels are sent concurrently; output is reported in --channel order. Exit code is non-zero if any channel fails; failures on one channel don't stop the others.

retries (under defaults or per channel; --retries overrides both, default 0) retries failures that normally mean nothing was delivered: connection failures, HTTP 429/502/503/504 and SMTP 4xx replies. Timeouts after a request was sent, HTTP 500 and exec failures are never retried, since the notification may already have gone out. Backoff doubles from 1s up to 30s, and each attempt gets the full timeout. HTTP redirects to another host or from https to http are refused, since they would forward headers and the body.

Go package

github.com/suprbdev/noty/notify sends notifications from a Go program with the same config format, templates, fan-out, retries and secret masking as the CLI (which is built on it):

go get github.com/suprbdev/noty@latest
cfg, err := notify.Load("/etc/myapp/noty.yaml") // or notify.Parse(data)
if err != nil {
    return err // errors.Is(err, notify.ErrInvalidConfig) for config problems
}
client, err := notify.New(cfg)
if err != nil {
    return err
}
res, err := client.Send(ctx, notify.Message{
    Channels: []string{"slack", "email"}, // empty: defaults.channel
    Subject:  "deploy finished",
    Text:     "api v2.4 is live",          // {{ .Message }}
    Vars:     map[string]string{"environment": "prod"},
})
var sendErr *notify.SendError
if errors.As(err, &sendErr) {
    // Some channels failed; the others were still attempted.
    log.Printf("failed channels %v: %v", res.Failed(), err)
}

Message also has To (recipient override), Template (body template file override) and DryRun (render and validate only; each ChannelResult.Description says what would be sent). Send returns notify.ErrNoChannel or an error wrapping notify.ErrUnknownChannel before sending anything when the channels can't be resolved.

Options: notify.WithLookupEnv resolves ${VAR} through your own lookup instead of the process environment (for Load/Parse); WithHTTPClient, WithExecRunner (fake or restrict exec channels), WithTimeout, WithRetries, WithBackoff and WithClock customise the client.

Adding a provider type

Implement the Sender interface and register a factory — nothing else changes:

// internal/provider/carrierpigeon.go
func init() {
    Register("pigeon", func(node *yaml.Node, deps Deps) (Sender, error) {
        var cfg pigeonConfig
        if err := Decode(node, "pigeon", &cfg); err != nil { return nil, err }
        return &pigeonSender{cfg}, nil
    })
}

Each provider decodes its own YAML from the channel node, so new settings never touch the core config code. deps.Renderer templates the provider's own fields. Decode rejects keys that are neither provider fields nor common channel fields, so config typos fail loudly with a line number.

Examples

# Pipe a log tail to the default channel
tail -20 app.log | noty -s "app errors"

# SMS a specific number (Twilio-style channel)
noty --channel sms --to +15551234567 -m "Server db-1 unreachable"

# ntfy push to a topic chosen at send time
noty --channel ntfy --var topic=alerts -m "backup done"

# Fan out to email + Slack with a custom template and staging vars
noty --channel email,slack -t incident.tmpl \
  --var environment=staging --var severity=high \
  -m "Elevated 5xx rate on api-gateway"

# Preview exactly what would be sent (auth headers redacted)
noty --channel api -m test --dry-run

About

A single-binary, config-driven notification CLI.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages