bot

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2024 License: EUPL-1.2 Imports: 21 Imported by: 0

Documentation

Overview

Package bot contains a Matrix Alertmanager bot.

Index

Constants

View Source
const (
	DefaultTextTemplate = "" /* 209-byte string literal not displayed */
	DefaultHTMLTemplate = `` /* 288-byte string literal not displayed */
)

Default alert template values.

View Source
const (
	Day  = 24 * time.Hour
	Week = 7 * Day
	Year = 365 * Day
)

Additional durations.

Variables

View Source
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) Alerts

func (c *Client) Alerts(ctx context.Context, silenced bool, showLabels bool) *bot.Message

Alerts returns all or non-silenced alerts.

func (*Client) DelSilence

func (c *Client) DelSilence(ctx context.Context, ids []string) string

DelSilence deletes silences.

func (*Client) NewSilence

func (c *Client) NewSilence(ctx context.Context, author, durationStr, matchers, comment string) string

NewSilence creates a new silence and returns the ID.

func (*Client) Run

func (c *Client) Run() error

Run the client in a blocking thread.

func (*Client) Silences

func (c *Client) Silences(ctx context.Context, state string) string

Silences returns a Markdown formatted NewMessage containing silences with the specified state.

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

func NewFormatter(textTemplate, htmlTemplate string, colors, icons map[string]string) *Formatter

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.

Jump to

Keyboard shortcuts

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