notifier

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2026 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package notifier provides clients for sending notifications to various providers.

Index

Constants

View Source
const (
	SeverityCritical = "critical"
	SeverityHigh     = "high"
	SeverityMedium   = "medium"
	SeverityLow      = "low"
)

Severity constants.

Variables

This section is empty.

Functions

func GetSeverityColor

func GetSeverityColor(severity string) string

GetSeverityColor returns a hex color for the given severity.

func GetSeverityEmoji

func GetSeverityEmoji(severity string) string

GetSeverityEmoji returns an emoji for the given severity.

Types

type Attachment

type Attachment struct {
	Title string
	Text  string
	Color string
	URL   string
}

Attachment represents a message attachment.

type Client

type Client interface {
	// Send sends a notification message.
	Send(ctx context.Context, msg Message) (*SendResult, error)

	// TestConnection tests the notification configuration.
	TestConnection(ctx context.Context) (*SendResult, error)

	// Provider returns the provider name.
	Provider() string
}

Client defines the interface for notification providers.

type ClientFactory

type ClientFactory struct{}

ClientFactory creates notification clients for different providers.

func NewClientFactory

func NewClientFactory() *ClientFactory

NewClientFactory creates a new ClientFactory.

func (*ClientFactory) CreateClient

func (f *ClientFactory) CreateClient(config Config) (Client, error)

CreateClient creates a notification client based on the configuration.

type Config

type Config struct {
	Provider    Provider
	WebhookURL  string       // For Slack, Teams, generic webhook
	BotToken    string       // For Telegram, Slack (bot token)
	ChatID      string       // For Telegram
	ChannelID   string       // For Slack
	APIEndpoint string       // Custom API endpoint
	Email       *EmailConfig // For Email (SMTP)
}

Config holds the configuration for creating a notification client.

type EmailClient

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

EmailClient implements the Client interface for email notifications via SMTP.

func NewEmailClient

func NewEmailClient(config Config) (*EmailClient, error)

NewEmailClient creates a new email notification client.

func (*EmailClient) Provider

func (c *EmailClient) Provider() string

Provider returns the provider name.

func (*EmailClient) Send

func (c *EmailClient) Send(ctx context.Context, msg Message) (*SendResult, error)

Send sends a notification email.

func (*EmailClient) TestConnection

func (c *EmailClient) TestConnection(ctx context.Context) (*SendResult, error)

TestConnection tests the SMTP configuration.

type EmailConfig

type EmailConfig struct {
	SMTPHost     string   // SMTP server host
	SMTPPort     int      // SMTP server port (25, 465, 587)
	Username     string   // SMTP username
	Password     string   // SMTP password
	FromEmail    string   // Sender email address
	FromName     string   // Sender display name
	ToEmails     []string // Recipient email addresses
	UseTLS       bool     // Use direct TLS (port 465)
	UseSTARTTLS  bool     // Use STARTTLS (port 587)
	SkipVerify   bool     // Skip TLS certificate verification (dev only)
	ReplyTo      string   // Optional reply-to address
	TemplateName string   // Optional custom template name
}

EmailConfig holds the SMTP configuration.

type Message

type Message struct {
	Title       string            // Message title/subject
	Body        string            // Main message body
	Severity    string            // critical, high, medium, low
	URL         string            // Optional link URL
	Fields      map[string]string // Additional fields to display
	Color       string            // Optional color (hex)
	FooterText  string            // Optional footer text
	IconURL     string            // Optional icon URL
	Attachments []Attachment      // Optional attachments
}

Message represents a notification message.

type Provider

type Provider string

Provider represents a notification provider.

const (
	ProviderSlack    Provider = "slack"
	ProviderTeams    Provider = "teams"
	ProviderTelegram Provider = "telegram"
	ProviderWebhook  Provider = "webhook"
	ProviderEmail    Provider = "email"
)

func (Provider) String

func (p Provider) String() string

String returns the string representation of the provider.

type SendResult

type SendResult struct {
	Success   bool
	MessageID string // Provider-specific message ID
	Error     string
}

SendResult represents the result of sending a notification.

type SlackClient

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

SlackClient implements the Client interface for Slack notifications.

func NewSlackClient

func NewSlackClient(config Config) (*SlackClient, error)

NewSlackClient creates a new Slack notification client.

func (*SlackClient) Provider

func (c *SlackClient) Provider() string

Provider returns the provider name.

func (*SlackClient) Send

func (c *SlackClient) Send(ctx context.Context, msg Message) (*SendResult, error)

Send sends a notification message to Slack.

func (*SlackClient) TestConnection

func (c *SlackClient) TestConnection(ctx context.Context) (*SendResult, error)

TestConnection tests the Slack webhook configuration.

type TeamsClient

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

TeamsClient implements the Client interface for Microsoft Teams notifications.

func NewTeamsClient

func NewTeamsClient(config Config) (*TeamsClient, error)

NewTeamsClient creates a new Teams notification client.

func (*TeamsClient) Provider

func (c *TeamsClient) Provider() string

Provider returns the provider name.

func (*TeamsClient) Send

func (c *TeamsClient) Send(ctx context.Context, msg Message) (*SendResult, error)

Send sends a notification message to Teams.

func (*TeamsClient) TestConnection

func (c *TeamsClient) TestConnection(ctx context.Context) (*SendResult, error)

TestConnection tests the Teams webhook configuration.

type TelegramClient

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

TelegramClient implements the Client interface for Telegram notifications.

func NewTelegramClient

func NewTelegramClient(config Config) (*TelegramClient, error)

NewTelegramClient creates a new Telegram notification client.

func (*TelegramClient) Provider

func (c *TelegramClient) Provider() string

Provider returns the provider name.

func (*TelegramClient) Send

func (c *TelegramClient) Send(ctx context.Context, msg Message) (*SendResult, error)

Send sends a notification message to Telegram.

func (*TelegramClient) TestConnection

func (c *TelegramClient) TestConnection(ctx context.Context) (*SendResult, error)

TestConnection tests the Telegram bot configuration.

type WebhookAttachment

type WebhookAttachment struct {
	Title string `json:"title"`
	Text  string `json:"text"`
	Color string `json:"color,omitempty"`
	URL   string `json:"url,omitempty"`
}

WebhookAttachment represents an attachment in the webhook payload.

type WebhookClient

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

WebhookClient implements the Client interface for generic webhook notifications.

func NewWebhookClient

func NewWebhookClient(config Config) (*WebhookClient, error)

NewWebhookClient creates a new generic webhook notification client.

func (*WebhookClient) Provider

func (c *WebhookClient) Provider() string

Provider returns the provider name.

func (*WebhookClient) Send

func (c *WebhookClient) Send(ctx context.Context, msg Message) (*SendResult, error)

Send sends a notification message to the webhook.

func (*WebhookClient) TestConnection

func (c *WebhookClient) TestConnection(ctx context.Context) (*SendResult, error)

TestConnection tests the webhook configuration.

type WebhookPayload

type WebhookPayload struct {
	EventType   string              `json:"event_type"`
	Timestamp   string              `json:"timestamp"`
	Title       string              `json:"title"`
	Body        string              `json:"body"`
	Severity    string              `json:"severity"`
	URL         string              `json:"url,omitempty"`
	Fields      map[string]string   `json:"fields,omitempty"`
	Color       string              `json:"color,omitempty"`
	FooterText  string              `json:"footer_text,omitempty"`
	Attachments []WebhookAttachment `json:"attachments,omitempty"`
	Source      string              `json:"source"`
}

WebhookPayload represents the JSON payload sent to the webhook.

Jump to

Keyboard shortcuts

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