notify

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BudgetAlertNotifier added in v0.1.0

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

BudgetAlertNotifier sends budget threshold alerts via the NotifyService. It implements rule.BudgetAlertNotifier to avoid circular package dependencies.

func NewBudgetAlertNotifier added in v0.1.0

func NewBudgetAlertNotifier(notifyService *NotifyService, channels *Channel) *BudgetAlertNotifier

NewBudgetAlertNotifier creates a new budget alert notifier.

func (*BudgetAlertNotifier) SendBudgetAlert added in v0.1.0

func (n *BudgetAlertNotifier) SendBudgetAlert(
	ctx context.Context,
	ruleID types.RuleID,
	unit string,
	spent string,
	maxTotal string,
	pct int64,
	alertPct int,
) error

SendBudgetAlert sends a budget threshold alert notification.

type Channel

type Channel struct {
	Slack    []string `yaml:"slack,omitempty"`    // Slack channel IDs
	Pushover []string `yaml:"pushover,omitempty"` // Pushover user keys
	Webhook  []string `yaml:"webhook,omitempty"`  // Webhook URLs
	Telegram []string `yaml:"telegram,omitempty"` // Telegram chat IDs or @channel
}

Channel specifies which concrete channels to deliver to.

type Config

type Config struct {
	Slack    *SlackConfig    `yaml:"slack,omitempty"`
	Pushover *PushoverConfig `yaml:"pushover,omitempty"`
	Webhook  *WebhookConfig  `yaml:"webhook,omitempty"`
	Telegram *TelegramConfig `yaml:"telegram,omitempty"`
}

Config is the root notification service configuration.

type NotifyService

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

NotifyService is the unified notification service. It uses async delivery: Send enqueues messages; a consumer goroutine performs the actual send.

func NewNotifyService

func NewNotifyService(cfg *Config) (*NotifyService, error)

NewNotifyService creates the notification service. Call Start() to run the consumer goroutine.

func (*NotifyService) Send

func (n *NotifyService) Send(channel *Channel, message string) error

Send enqueues a message for delivery to the given channels (non-blocking).

func (*NotifyService) SendWithPriority

func (n *NotifyService) SendWithPriority(channel *Channel, message string, priority int, sound string) error

SendWithPriority enqueues a message with Pushover priority and sound (non-blocking).

func (*NotifyService) Start

func (n *NotifyService) Start(ctx context.Context)

Start starts the consumer goroutine.

func (*NotifyService) Stop

func (n *NotifyService) Stop()

Stop stops the service and waits for all queued messages to be sent.

type PushoverClient

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

PushoverClient is the Pushover API client for sending notifications.

func NewPushoverClient

func NewPushoverClient(appToken string, retry, expire, maxRetries, retryDelay int) (*PushoverClient, error)

NewPushoverClient creates a Pushover client.

func (*PushoverClient) SendEmergencyNotification

func (p *PushoverClient) SendEmergencyNotification(userKey, message string) error

SendEmergencyNotification sends an emergency notification (backward compatible).

func (*PushoverClient) SendNotification

func (p *PushoverClient) SendNotification(userKey, message string, priority int, sound string) error

SendNotification sends a notification with optional priority and sound; uses exponential backoff retry.

func (*PushoverClient) SendToUsers

func (p *PushoverClient) SendToUsers(userKeys []string, message string, priority int, sound string) error

SendToUsers sends the notification to multiple Pushover users.

type PushoverConfig

type PushoverConfig struct {
	Enabled    bool   `yaml:"enabled"`
	AppToken   string `yaml:"app_token"`
	Retry      int    `yaml:"retry"`
	Expire     int    `yaml:"expire"`
	MaxRetries int    `yaml:"max_retries"`
	RetryDelay int    `yaml:"retry_delay"`
}

PushoverConfig holds Pushover notification channel configuration.

type PushoverRequest

type PushoverRequest struct {
	Token    string `json:"token"`
	User     string `json:"user"`
	Message  string `json:"message"`
	Priority int    `json:"priority"`
	Sound    string `json:"sound"`
	Retry    int    `json:"retry"`
	Expire   int    `json:"expire"`
}

PushoverRequest is the request body for the Pushover API.

type PushoverResponse

type PushoverResponse struct {
	Status  int      `json:"status"`
	Request string   `json:"request"`
	Errors  []string `json:"errors,omitempty"`
}

PushoverResponse is the response from the Pushover API.

type SlackClient

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

SlackClient is the Slack API client for sending notifications.

func NewSlackClient

func NewSlackClient(botToken string) (*SlackClient, error)

NewSlackClient creates a Slack client.

func (*SlackClient) FindUserByName

func (s *SlackClient) FindUserByName(username string) (string, error)

FindUserByName looks up a user ID by display name.

func (*SlackClient) GetChannelMembers

func (s *SlackClient) GetChannelMembers(channelID string) ([]string, error)

GetChannelMembers returns channel member IDs, excluding bots.

func (*SlackClient) GetUserInfo

func (s *SlackClient) GetUserInfo(userID string) (*UserInfo, error)

GetUserInfo returns Slack user info for the given user ID.

func (*SlackClient) PostMessage

func (s *SlackClient) PostMessage(channelID, message string) error

PostMessage sends a message to the given Slack channel.

func (*SlackClient) ReplyToChannel

func (s *SlackClient) ReplyToChannel(responseURL, message, responseType string) error

ReplyToChannel posts a reply to the channel (response_url from interaction payload).

func (*SlackClient) SendToChannels

func (s *SlackClient) SendToChannels(channelIDs []string, message string) error

SendToChannels sends the message to multiple Slack channels.

type SlackConfig

type SlackConfig struct {
	Enabled  bool   `yaml:"enabled"`
	BotToken string `yaml:"bot_token"`
}

SlackConfig holds Slack notification channel configuration.

type TelegramClient added in v0.1.0

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

TelegramClient sends messages via the Telegram Bot API.

func NewTelegramClient added in v0.1.0

func NewTelegramClient(botToken string) (*TelegramClient, error)

NewTelegramClient creates a Telegram client with the given bot token.

func (*TelegramClient) SendToChats added in v0.1.0

func (c *TelegramClient) SendToChats(chatIDs []string, message string) error

SendToChats sends the message to each chat (chat_id or @channel). chatID can be a numeric ID or a channel username (e.g. @mychannel).

type TelegramConfig added in v0.1.0

type TelegramConfig struct {
	Enabled  bool   `yaml:"enabled"`
	BotToken string `yaml:"bot_token"` // Bot token from @BotFather
}

TelegramConfig configures the Telegram Bot notification channel.

type UserInfo

type UserInfo struct {
	ID       string
	Name     string
	RealName string
}

UserInfo holds Slack user details.

type WebhookClient

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

WebhookClient sends notifications to generic HTTP webhook endpoints.

func NewWebhookClient

func NewWebhookClient(timeout time.Duration, headers map[string]string) (*WebhookClient, error)

NewWebhookClient creates a WebhookClient with the given timeout and optional custom headers (e.g. Authorization tokens).

func (*WebhookClient) SendToURLs

func (w *WebhookClient) SendToURLs(urls []string, message string) error

SendToURLs posts the message to every URL. It returns an error only when all URLs fail; partial failures are logged but do not block the rest.

Security note (SSRF): Webhook URLs are currently sourced from the config file and controlled by the server administrator, so SSRF risk is low. If webhook URLs are ever exposed via API (user-configurable), the following protections MUST be added:

  • Validate URL scheme (allow only http/https, reject file://, gopher://, etc.)
  • Resolve hostname and block private/reserved IP ranges: 127.0.0.0/8, 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 (ip.IsPrivate) 169.254.169.254 (cloud metadata endpoint, ip.IsLinkLocalUnicast) ::1, fc00::/7 (IPv6 loopback/private)
  • Disable HTTP redirects (attacker can redirect to internal IPs)
  • Consider DNS rebinding protection (re-resolve after redirect)

type WebhookConfig

type WebhookConfig struct {
	Enabled bool              `yaml:"enabled"`
	Headers map[string]string `yaml:"headers,omitempty"` // e.g. Authorization: Bearer ...
	Timeout time.Duration     `yaml:"timeout,omitempty"` // HTTP client timeout
}

WebhookConfig configures the generic webhook notification channel.

type WebhookPayload

type WebhookPayload struct {
	Text      string `json:"text"`
	Timestamp string `json:"timestamp"`
}

WebhookPayload is the JSON body posted to each webhook URL.

Jump to

Keyboard shortcuts

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