notify

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2022 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Metrics

func Metrics(server, query string, queryTime time.Time, duration, step time.Duration) (promModel.Matrix, error)

func Plot

func Plot(logger log.Logger, expr PlotExpr, queryTime time.Time, duration, resolution time.Duration, prometheusUrl string, alert Alert) (io.WriterTo, error)

func PlotMetric

func PlotMetric(metrics promModel.Matrix, level float64, direction string) (io.WriterTo, error)

func TmplHTML

func TmplHTML(tmpl *template.Template, data *Data, err *error) func(string) string

TmplHTML is using monadic error handling in order to make string templating less verbose. Use with care as the final error checking is easily missed.

func TmplText

func TmplText(tmpl *template.Template, data *Data, err *error) func(string) string

TmplText is using monadic error handling in order to make string templating less verbose. Use with care as the final error checking is easily missed.

Types

type Alert

type Alert struct {
	Status       string    `json:"status"`
	Labels       KV        `json:"labels"`
	Annotations  KV        `json:"annotations"`
	StartsAt     time.Time `json:"startsAt"`
	EndsAt       time.Time `json:"endsAt"`
	GeneratorURL string    `json:"generatorURL"`
	Fingerprint  string    `json:"fingerprint"`
	Images       []AlertImage
}

Alert holds one alert for notification templates.

type AlertImage

type AlertImage struct {
	Url   string `json:"url"`
	Title string `json:"title"`
}

type Alerts

type Alerts []Alert

Alerts is a list of Alert objects.

func (Alerts) Firing

func (as Alerts) Firing() []Alert

Firing returns the subset of alerts that are firing.

func (Alerts) Resolved

func (as Alerts) Resolved() []Alert

Resolved returns the subset of alerts that are resolved.

type Data

type Data struct {
	Receiver string `json:"receiver"`
	Status   string `json:"status"`
	Alerts   Alerts `json:"alerts"`

	GroupLabels       KV `json:"groupLabels"`
	CommonLabels      KV `json:"commonLabels"`
	CommonAnnotations KV `json:"commonAnnotations"`

	ExternalURL string `json:"externalURL"`
}

Data is the data passed to notification templates and webhook pushes.

End-users should not be exposed to Go's type system, as this will confuse them and prevent simple things like simple equality checks to fail. Map everything to float64/string.

func (*Data) MakeAlertImages

func (d *Data) MakeAlertImages(logger log.Logger, config *config.Config) error

type KV

type KV map[string]string

KV is a set of key/value string pairs.

func (KV) Names

func (kv KV) Names() []string

Names returns the names of the label names in the LabelSet.

func (KV) Remove

func (kv KV) Remove(keys []string) KV

Remove returns a copy of the key/value set without the given keys.

func (KV) SortedPairs

func (kv KV) SortedPairs() Pairs

SortedPairs returns a sorted list of key/value pairs.

func (KV) Values

func (kv KV) Values() []string

Values returns a list of the values in the LabelSet.

type Notifier

type Notifier interface {
	Notify(ctx context.Context, alerts *Data) (bool, error)
}

type Pair

type Pair struct {
	Name, Value string
}

Pair is a key/value string pair.

type Pairs

type Pairs []Pair

Pairs is a list of key/value string pairs.

func (Pairs) Names

func (ps Pairs) Names() []string

Names returns a list of names of the pairs.

func (Pairs) Values

func (ps Pairs) Values() []string

Values returns a list of values of the pairs.

type PlotExpr

type PlotExpr struct {
	Formula  string
	Operator string
	Level    float64
}

func GetPlotExpr

func GetPlotExpr(logger log.Logger, alertFormula string) []PlotExpr

func (PlotExpr) String

func (expr PlotExpr) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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