notify

package
v0.16.21 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: MIT Imports: 23 Imported by: 1 module, 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

Index

Constants

This section is empty.

Variables

View Source
var GlobalThrottle = NewNotificationThrottle()

Default global throttle instance (same as TS module-level map).

Functions

func CreateNotificationSignature

func CreateNotificationSignature(title, message, level string) string

CreateNotificationSignature creates a signature from title, message, and level. Format: "level||title||message" (three fields joined by ||). Mirrors TS createNotificationSignature().

Types

type BarkChannel

type BarkChannel struct{}

BarkChannel sends notifications via Bark.

func (*BarkChannel) Name

func (c *BarkChannel) Name() string

func (*BarkChannel) Send

func (c *BarkChannel) Send(cfg *config.RuntimeSettings, title, message, level, timeFootnote string) error

type Channel

type Channel interface {
	Name() string
	Send(cfg *config.RuntimeSettings, title, message, level, timeFootnote string) error
}

Channel is the interface for notification channels.

type DingtalkChannel

type DingtalkChannel struct{}

DingtalkChannel sends notifications via a DingTalk custom-bot webhook (https://oapi.dingtalk.com/robot/send?access_token=...).

When DingtalkSecret is set, appends &timestamp=&sign= query params signed per the DingTalk custom-bot protocol: HMAC-SHA256(key = secret, message = timestamp+"\n"+secret) → base64(raw digest), url-encoded. Content uses the DingTalk "text" msgtype (markdown also possible later).

func (*DingtalkChannel) Name

func (c *DingtalkChannel) Name() string

func (*DingtalkChannel) Send

func (c *DingtalkChannel) Send(cfg *config.RuntimeSettings, title, message, level, timeFootnote string) error

type DispatchResult

type DispatchResult struct {
	Throttled      bool
	MergedCount    int // suppressed duplicates merged into the sent notification
	Attempted      int
	Succeeded      int
	Failed         int
	FailedChannels []NotificationChannel
}

DispatchResult is the result of a notification dispatch.

func SendNotification

func SendNotification(cfg *config.RuntimeSettings, title, message, level string, options *SendNotificationOptions) (*DispatchResult, error)

SendNotification dispatches a notification through all configured channels. Mirrors TS sendNotification().

type EvaluateResult

type EvaluateResult struct {
	ShouldSend  bool
	MergedCount int
}

EvaluateResult is the result of a throttle evaluation.

type FeishuChannel

type FeishuChannel struct{}

FeishuChannel sends notifications via a Feishu/Lark custom bot webhook (https://open.feishu.cn/open-apis/bot/v2/hook/<id>).

When FeishuSecret is set, signs the request timestamp with HMAC-SHA256 (secret = key) per the Feishu bot sign protocol so the bot verifies origin. Reuses buildFeishuText from webhook.go for the content body (max-length aware), so text rendering stays consistent with the generic webhook path.

func (*FeishuChannel) Name

func (c *FeishuChannel) Name() string

func (*FeishuChannel) Send

func (c *FeishuChannel) Send(cfg *config.RuntimeSettings, title, message, level, timeFootnote string) error

type NotificationChannel

type NotificationChannel string

NotificationChannel is the channel identifier.

const (
	ChannelWebhook    NotificationChannel = "webhook"
	ChannelBark       NotificationChannel = "bark"
	ChannelServerChan NotificationChannel = "serverchan"
	ChannelTelegram   NotificationChannel = "telegram"
	ChannelSMTP       NotificationChannel = "smtp"
	ChannelFeishu     NotificationChannel = "feishu"
	ChannelDingTalk   NotificationChannel = "dingtalk"
	ChannelWeCom      NotificationChannel = "wecom"
	ChannelNtfy       NotificationChannel = "ntfy"
)

type NotificationLevel

type NotificationLevel string

NotificationLevel is the severity of a notification.

const (
	LevelInfo    NotificationLevel = "info"
	LevelWarning NotificationLevel = "warning"
	LevelError   NotificationLevel = "error"
)

type NotificationThrottle

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

NotificationThrottle is a global throttle for notification deduplication.

func NewNotificationThrottle

func NewNotificationThrottle() *NotificationThrottle

NewNotificationThrottle creates a new throttle instance.

func (*NotificationThrottle) EvaluateNotificationThrottle

func (t *NotificationThrottle) EvaluateNotificationThrottle(signature string, nowMs int64, cooldownMs int64) EvaluateResult

EvaluateNotificationThrottle checks whether a notification should be sent based on the cooldown period. Mirrors TS evaluateNotificationThrottle().

func (*NotificationThrottle) PruneNotificationThrottleState

func (t *NotificationThrottle) PruneNotificationThrottleState(nowMs int64, staleMs int64)

PruneNotificationThrottleState removes stale entries older than staleMs. Mirrors TS pruneNotificationThrottleState().

type NotificationThrottleState

type NotificationThrottleState struct {
	LastSentAtMs    int64
	SuppressedCount int
}

NotificationThrottleState tracks the last sent timestamp and suppressed count.

type NtfyChannel

type NtfyChannel struct{}

NtfyChannel sends notifications via a self-hosted ntfy server (https://ntfy.sh).

Sends a POST to {NtfyUrl}/{NtfyTopic} with the message as the body and the title/priority in headers. If NtfyToken is set, sends it as a Bearer token. NtfyUrl may be the public https://ntfy.sh or a self-hosted instance.

func (*NtfyChannel) Name

func (c *NtfyChannel) Name() string

func (*NtfyChannel) Send

func (c *NtfyChannel) Send(cfg *config.RuntimeSettings, title, message, level, timeFootnote string) error

type SMTPChannel

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

SMTPChannel sends notifications via SMTP email.

func (*SMTPChannel) Name

func (c *SMTPChannel) Name() string

func (*SMTPChannel) Send

func (c *SMTPChannel) Send(cfg *config.RuntimeSettings, title, message, level, timeFootnote string) error

type SendNotificationOptions

type SendNotificationOptions struct {
	BypassThrottle bool
	RequireChannel bool
	ThrowOnFailure bool
	// TaskTag labels the alert type. When set and
	// cfg.NotifyTaskToggles[TaskTag] is false, the notification is skipped so
	// operators can mute a specific alert type (e.g. "low_balance") while
	// still receiving others. Empty TaskTag = no gating (backward-compatible).
	TaskTag string
}

SendNotificationOptions configures notification behavior.

type ServerChanChannel

type ServerChanChannel struct{}

ServerChanChannel sends notifications via Server酱.

func (*ServerChanChannel) Name

func (c *ServerChanChannel) Name() string

func (*ServerChanChannel) Send

func (c *ServerChanChannel) Send(cfg *config.RuntimeSettings, title, message, level, timeFootnote string) error

type TelegramChannel

type TelegramChannel struct{}

TelegramChannel sends notifications via Telegram Bot.

func (*TelegramChannel) Name

func (c *TelegramChannel) Name() string

func (*TelegramChannel) Send

func (c *TelegramChannel) Send(cfg *config.RuntimeSettings, title, message, level, timeFootnote string) error

type WebhookChannel

type WebhookChannel struct{}

WebhookChannel sends notifications via webhook (WeCom/Feishu/generic).

func (*WebhookChannel) Name

func (c *WebhookChannel) Name() string

func (*WebhookChannel) Send

func (c *WebhookChannel) Send(cfg *config.RuntimeSettings, title, message, level, timeFootnote string) error

type WecomChannel

type WecomChannel struct{}

WecomChannel sends notifications via a WeCom (企业微信) custom-bot webhook (https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=...).

Dedicated channel so the operator gets a separate enable toggle + config field from the generic webhook. Reuses buildWeComText from webhook.go for the content body (max-length aware) so rendering stays consistent.

func (*WecomChannel) Name

func (c *WecomChannel) Name() string

func (*WecomChannel) Send

func (c *WecomChannel) Send(cfg *config.RuntimeSettings, title, message, level, timeFootnote string) error

Jump to

Keyboard shortcuts

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