alert

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: May 22, 2024 License: MIT Imports: 18 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrChannelNotFound added in v0.2.1

func ErrChannelNotFound(ch string) error

func ErrChannelTypeNotSupported added in v0.2.1

func ErrChannelTypeNotSupported(chType string) error

func MustInitFromViper

func MustInitFromViper()

MustInitFromViper inits alert from viper settings or panic on error.

Types

type Channel added in v0.2.1

type Channel interface {
	Name() string
	Type() ChannelType
	Send(context.Context, *Notification) error
}

Notification channel interface.

type ChannelType added in v0.2.1

type ChannelType string

Notification channel type.

const (
	ChannelTypeDingTalk ChannelType = "dingtalk"
	ChannelTypeTelegram ChannelType = "telegram"
	ChannelTypeSMTP     ChannelType = "smtp"
)

type DingTalkChannel added in v0.2.1

type DingTalkChannel struct {
	Formatter Formatter      // message formatter
	ID        string         // channel id
	Config    DingTalkConfig // channel config
	// contains filtered or unexported fields
}

DingTalkChannel DingTalk notification channel

func NewDingTalkChannel added in v0.2.1

func NewDingTalkChannel(chID string, fmt Formatter, conf DingTalkConfig) *DingTalkChannel

func (*DingTalkChannel) Name added in v0.2.1

func (dtc *DingTalkChannel) Name() string

func (*DingTalkChannel) Send added in v0.2.1

func (dtc *DingTalkChannel) Send(ctx context.Context, note *Notification) error

func (*DingTalkChannel) Type added in v0.2.1

func (dtc *DingTalkChannel) Type() ChannelType

type DingTalkConfig

type DingTalkConfig struct {
	AtMobiles []string // mobiles for @ members
	IsAtAll   bool     // whether to @ all members
	Webhook   string   // webhook url
	Secret    string   // secret token
}

type DingTalkMarkdownFormatter added in v0.2.1

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

func NewDingtalkMarkdownFormatter added in v0.2.1

func NewDingtalkMarkdownFormatter(tags []string) (*DingTalkMarkdownFormatter, error)

func (DingTalkMarkdownFormatter) Format added in v0.2.1

func (f DingTalkMarkdownFormatter) Format(note *Notification) (string, error)

type Formatter added in v0.2.1

type Formatter interface {
	Format(note *Notification) (string, error)
}

Formatter defines how messages are formatted.

type Manager added in v0.2.1

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

func DefaultManager added in v0.2.1

func DefaultManager() *Manager

func NewManager added in v0.2.1

func NewManager() *Manager

func (*Manager) Add added in v0.2.1

func (m *Manager) Add(ch Channel) Channel

func (*Manager) All added in v0.2.1

func (m *Manager) All(name string) (chs []Channel)

func (*Manager) Channel added in v0.2.1

func (m *Manager) Channel(name string) (Channel, bool)

func (*Manager) Del added in v0.2.1

func (m *Manager) Del(name string)

type Notification added in v0.2.1

type Notification struct {
	Title    string      // message title
	Content  interface{} // message content
	Severity Severity    // severity level
}

Notification represents core information for an alert.

type Severity added in v0.2.1

type Severity int

Alert severity level.

const (
	SeverityLow Severity = iota
	SeverityMedium
	SeverityHigh
	SeverityCritical
)

func (Severity) String added in v0.2.1

func (s Severity) String() string

type SimpleTextFormatter added in v0.2.1

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

func NewSimpleTextFormatter added in v0.2.1

func NewSimpleTextFormatter(tags []string) *SimpleTextFormatter

func (*SimpleTextFormatter) Format added in v0.2.1

func (f *SimpleTextFormatter) Format(note *Notification) (string, error)

type SmtpChannel added in v0.2.1

type SmtpChannel struct {
	Formatter Formatter  // Formatter is used to format the notification message
	ID        string     // ID is the identifier of the channel
	Config    SmtpConfig // Config contains the configuration for the SMTP server
}

SmtpChannel represents a SMTP email notification channel

func NewSmtpChannel added in v0.2.1

func NewSmtpChannel(chID string, fmtter Formatter, conf SmtpConfig) *SmtpChannel

NewSmtpChannel creates a new SMTP channel with the given ID, formatter, and configuration

func (*SmtpChannel) Name added in v0.2.1

func (c *SmtpChannel) Name() string

Name returns the ID of the channel

func (*SmtpChannel) Send added in v0.2.1

func (c *SmtpChannel) Send(ctx context.Context, note *Notification) error

Send sends a notification using the SMTP channel

func (*SmtpChannel) Type added in v0.2.1

func (c *SmtpChannel) Type() ChannelType

Type returns the type of the channel, which is SMTP

type SmtpConfig added in v0.2.1

type SmtpConfig struct {
	Host     string   // SMTP endpoint and port
	From     string   // Sender address
	To       []string // Receipt addresses
	Password string   // SMTP password
}

type SmtpHtmlFormatter added in v0.2.1

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

func NewSmtpHtmlFormatter added in v0.2.1

func NewSmtpHtmlFormatter(
	conf SmtpConfig, tags []string) (f *SmtpHtmlFormatter, err error)

func (*SmtpHtmlFormatter) Format added in v0.2.1

func (f *SmtpHtmlFormatter) Format(note *Notification) (msg string, err error)

type TelegramChannel added in v0.2.1

type TelegramChannel struct {
	Formatter Formatter      // message formatter
	ID        string         // channel id
	Config    TelegramConfig // channel config
	// contains filtered or unexported fields
}

TelegramChannel Telegram notification channel

func NewTelegramChannel added in v0.2.1

func NewTelegramChannel(chID string, fmt Formatter, conf TelegramConfig) (*TelegramChannel, error)

func (*TelegramChannel) Name added in v0.2.1

func (tc *TelegramChannel) Name() string

func (*TelegramChannel) Send added in v0.2.1

func (tc *TelegramChannel) Send(ctx context.Context, note *Notification) error

func (*TelegramChannel) Type added in v0.2.1

func (tc *TelegramChannel) Type() ChannelType

type TelegramConfig added in v0.2.1

type TelegramConfig struct {
	ApiToken string // Api token
	ChatId   string // Chat ID
}

type TelegramMarkdownFormatter added in v0.2.1

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

func NewTelegramMarkdownFormatter added in v0.2.1

func NewTelegramMarkdownFormatter(tags []string) (f *TelegramMarkdownFormatter, err error)

func (TelegramMarkdownFormatter) Format added in v0.2.1

func (f TelegramMarkdownFormatter) Format(note *Notification) (string, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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