Documentation
¶
Index ¶
- Variables
- func CreateNotificationSignature(title, message, level string) string
- type BarkChannel
- type Channel
- type DingtalkChannel
- type DispatchResult
- type EvaluateResult
- type FeishuChannel
- type NotificationChannel
- type NotificationLevel
- type NotificationThrottle
- type NotificationThrottleState
- type NtfyChannel
- type SMTPChannel
- type SendNotificationOptions
- type ServerChanChannel
- type TelegramChannel
- type WebhookChannel
- type WecomChannel
Constants ¶
This section is empty.
Variables ¶
var GlobalThrottle = NewNotificationThrottle()
Default global throttle instance (same as TS module-level map).
Functions ¶
func CreateNotificationSignature ¶
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 ×tamp=&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 ¶
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 ¶
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