Documentation ¶
Overview ¶
Package bot contains a Matrix Alertmanager bot.
Index ¶
- Constants
- Variables
- type Client
- func (c *Client) Alerts(ctx context.Context, silenced bool, showLabels bool) *bot.Message
- func (c *Client) DelSilence(ctx context.Context, ids []string) string
- func (c *Client) NewSilence(ctx context.Context, author, durationStr, matchers, comment string) string
- func (c *Client) Run() error
- func (c *Client) Silences(ctx context.Context, state string) string
- type ClientConfig
- type Formatter
- type Message
Constants ¶
const ( DefaultTextTemplate = "" /* 209-byte string literal not displayed */ DefaultHTMLTemplate = `` /* 288-byte string literal not displayed */ )
Default alert template values.
const ( Day = 24 * time.Hour Week = 7 * Day Year = 365 * Day )
Additional durations.
Variables ¶
var ( DefaultColors = map[string]string{ "alert": "black", "information": "blue", "info": "blue", "warning": "orange", "critical": "red", "error": "red", "resolved": "green", "silenced": "gray", } DefaultIcons = map[string]string{ "alert": "🔔️", "information": "ℹ️", "info": "ℹ️", "warning": "⚠️", "critical": "🚨", "error": "🚨", "resolved": "✅", "silenced": "🔕", } )
Default color and icon values.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { Matrix *bot.Client Alertmanager *alertmanager.Client Formatter *Formatter // contains filtered or unexported fields }
Client represents an Alertmanager/Matrix client.
func NewClient ¶
func NewClient(config *ClientConfig, formatter *Formatter) (client *Client, err error)
NewClient creates and starts a new Alertmanager/Matrix client.
func (*Client) DelSilence ¶
DelSilence deletes silences.
type ClientConfig ¶
type ClientConfig struct { Homeserver string // Matrix homeserver URL. UserID string // Matrix user ID. Token string // Matrix token. MessageType string // Matrix NewMessage type (optional). Rooms string // Comma-separated list of matrix rooms (optional). AlertManagerURL string // URL to the Alert Manager API. }
ClientConfig contains the configuration for the client.
type Formatter ¶
type Formatter struct {
// contains filtered or unexported fields
}
Formatter represents a NewMessage formatter with an icon and color set.
func NewFormatter ¶
NewFormatter creates a new formatter with the given text/HTML templates, colors and strings. The default templates, colors or icons are used if "" or nil is provided.
The following functions are registered for use in the templates:
icon: returns the icon for the given string. color: returns the color for the given string. upper: converts the given string to uppercase. lower: converts the given string to lowercase. title: converts the given string to title case.
func (*Formatter) FormatAlerts ¶
func (f *Formatter) FormatAlerts(alerts []*alertmanager.Alert, showLabels bool) (plainContent, htmlContent string)
FormatAlerts formats alerts as plain text and HTML.
func (*Formatter) FormatSilences ¶
func (f *Formatter) FormatSilences(silences []alertmanager.Silence, state string) (md string)
FormatSilences formats silences as Markdown.
type Message ¶
type Message struct { Alerts []*alertmanager.Alert ShowLabels bool }
Message represents the information for a single alert message. It is used for formatting.