...

Package notify

import "github.com/prometheus/alertmanager/notify"
Overview
Index
Subdirectories

Overview ▾

Index ▾

Constants
Variables
func ActiveTimeIntervalNames(ctx context.Context) ([]string, bool)
func Drain(r *http.Response)
func FiringAlerts(ctx context.Context) ([]uint64, bool)
func Get(ctx context.Context, client *http.Client, url string) (*http.Response, error)
func GetTemplateData(ctx context.Context, tmpl *template.Template, alerts []*types.Alert, l log.Logger) *template.Data
func GroupKey(ctx context.Context) (string, bool)
func GroupLabels(ctx context.Context) (model.LabelSet, bool)
func MuteTimeIntervalNames(ctx context.Context) ([]string, bool)
func Now(ctx context.Context) (time.Time, bool)
func PostJSON(ctx context.Context, client *http.Client, url string, body io.Reader) (*http.Response, error)
func PostText(ctx context.Context, client *http.Client, url string, body io.Reader) (*http.Response, error)
func ReceiverName(ctx context.Context) (string, bool)
func RedactURL(err error) error
func RepeatInterval(ctx context.Context) (time.Duration, bool)
func ResolvedAlerts(ctx context.Context) ([]uint64, bool)
func TmplHTML(tmpl *template.Template, data *template.Data, err *error) func(string) string
func TmplText(tmpl *template.Template, data *template.Data, err *error) func(string) string
func TruncateInBytes(s string, n int) (string, bool)
func TruncateInRunes(s string, n int) (string, bool)
func WithActiveTimeIntervals(ctx context.Context, at []string) context.Context
func WithFiringAlerts(ctx context.Context, alerts []uint64) context.Context
func WithGroupKey(ctx context.Context, s string) context.Context
func WithGroupLabels(ctx context.Context, lset model.LabelSet) context.Context
func WithMuteTimeIntervals(ctx context.Context, mt []string) context.Context
func WithNow(ctx context.Context, t time.Time) context.Context
func WithReceiverName(ctx context.Context, rcv string) context.Context
func WithRepeatInterval(ctx context.Context, t time.Duration) context.Context
func WithResolvedAlerts(ctx context.Context, alerts []uint64) context.Context
type DedupStage
    func NewDedupStage(rs ResolvedSender, l NotificationLog, recv *nflogpb.Receiver) *DedupStage
    func (n *DedupStage) Exec(ctx context.Context, _ log.Logger, alerts ...*types.Alert) (context.Context, []*types.Alert, error)
type FanoutStage
    func (fs FanoutStage) Exec(ctx context.Context, l log.Logger, alerts ...*types.Alert) (context.Context, []*types.Alert, error)
type GossipSettleStage
    func NewGossipSettleStage(p Peer) *GossipSettleStage
    func (n *GossipSettleStage) Exec(ctx context.Context, _ log.Logger, alerts ...*types.Alert) (context.Context, []*types.Alert, error)
type Integration
    func NewIntegration(notifier Notifier, rs ResolvedSender, name string, idx int) Integration
    func (i *Integration) Index() int
    func (i *Integration) Name() string
    func (i *Integration) Notify(ctx context.Context, alerts ...*types.Alert) (bool, error)
    func (i *Integration) SendResolved() bool
    func (i *Integration) String() string
type Key
    func ExtractGroupKey(ctx context.Context) (Key, error)
    func (k Key) Hash() string
    func (k Key) String() string
type Metrics
    func NewMetrics(r prometheus.Registerer) *Metrics
type MultiStage
    func (ms MultiStage) Exec(ctx context.Context, l log.Logger, alerts ...*types.Alert) (context.Context, []*types.Alert, error)
type MuteStage
    func NewMuteStage(m types.Muter) *MuteStage
    func (n *MuteStage) Exec(ctx context.Context, _ log.Logger, alerts ...*types.Alert) (context.Context, []*types.Alert, error)
type NotificationLog
type Notifier
type Peer
type PipelineBuilder
    func NewPipelineBuilder(r prometheus.Registerer) *PipelineBuilder
    func (pb *PipelineBuilder) New(receivers map[string][]Integration, wait func() time.Duration, inhibitor *inhibit.Inhibitor, silencer *silence.Silencer, times map[string][]timeinterval.TimeInterval, notificationLog NotificationLog, peer Peer) RoutingStage
type ResolvedSender
type Retrier
    func (r *Retrier) Check(statusCode int, body io.Reader) (bool, error)
type RetryStage
    func NewRetryStage(i Integration, groupName string, metrics *Metrics) *RetryStage
    func (r RetryStage) Exec(ctx context.Context, l log.Logger, alerts ...*types.Alert) (context.Context, []*types.Alert, error)
type RoutingStage
    func (rs RoutingStage) Exec(ctx context.Context, l log.Logger, alerts ...*types.Alert) (context.Context, []*types.Alert, error)
type SetNotifiesStage
    func NewSetNotifiesStage(l NotificationLog, recv *nflogpb.Receiver) *SetNotifiesStage
    func (n SetNotifiesStage) Exec(ctx context.Context, l log.Logger, alerts ...*types.Alert) (context.Context, []*types.Alert, error)
type Stage
type StageFunc
    func (f StageFunc) Exec(ctx context.Context, l log.Logger, alerts ...*types.Alert) (context.Context, []*types.Alert, error)
type TimeActiveStage
    func NewTimeActiveStage(ti map[string][]timeinterval.TimeInterval) *TimeActiveStage
    func (tas TimeActiveStage) Exec(ctx context.Context, l log.Logger, alerts ...*types.Alert) (context.Context, []*types.Alert, error)
type TimeMuteStage
    func NewTimeMuteStage(ti map[string][]timeinterval.TimeInterval) *TimeMuteStage
    func (tms TimeMuteStage) Exec(ctx context.Context, l log.Logger, alerts ...*types.Alert) (context.Context, []*types.Alert, error)
type WaitStage
    func NewWaitStage(wait func() time.Duration) *WaitStage
    func (ws *WaitStage) Exec(ctx context.Context, _ log.Logger, alerts ...*types.Alert) (context.Context, []*types.Alert, error)

Package files

notify.go util.go

Constants

MinTimeout is the minimum timeout that is set for the context of a call to a notification pipeline.

const MinTimeout = 10 * time.Second

Variables

UserAgentHeader is the default User-Agent for notification requests

var UserAgentHeader = fmt.Sprintf("Alertmanager/%s", version.Version)

func ActiveTimeIntervalNames

func ActiveTimeIntervalNames(ctx context.Context) ([]string, bool)

ActiveTimeIntervalNames extracts a slice of active time names from the context. If none exists, the second argument is false.

func Drain

func Drain(r *http.Response)

Drain consumes and closes the response's body to make sure that the HTTP client can reuse existing connections.

func FiringAlerts

func FiringAlerts(ctx context.Context) ([]uint64, bool)

FiringAlerts extracts a slice of firing alerts from the context. Iff none exists, the second argument is false.

func Get

func Get(ctx context.Context, client *http.Client, url string) (*http.Response, error)

Get sends a GET request to the given URL

func GetTemplateData

func GetTemplateData(ctx context.Context, tmpl *template.Template, alerts []*types.Alert, l log.Logger) *template.Data

GetTemplateData creates the template data from the context and the alerts.

func GroupKey

func GroupKey(ctx context.Context) (string, bool)

GroupKey extracts a group key from the context. Iff none exists, the second argument is false.

func GroupLabels

func GroupLabels(ctx context.Context) (model.LabelSet, bool)

GroupLabels extracts grouping label set from the context. Iff none exists, the second argument is false.

func MuteTimeIntervalNames

func MuteTimeIntervalNames(ctx context.Context) ([]string, bool)

MuteTimeIntervalNames extracts a slice of mute time names from the context. If and only if none exists, the second argument is false.

func Now

func Now(ctx context.Context) (time.Time, bool)

Now extracts a now timestamp from the context. Iff none exists, the second argument is false.

func PostJSON

func PostJSON(ctx context.Context, client *http.Client, url string, body io.Reader) (*http.Response, error)

PostJSON sends a POST request with JSON payload to the given URL.

func PostText

func PostText(ctx context.Context, client *http.Client, url string, body io.Reader) (*http.Response, error)

PostText sends a POST request with text payload to the given URL.

func ReceiverName

func ReceiverName(ctx context.Context) (string, bool)

ReceiverName extracts a receiver name from the context. Iff none exists, the second argument is false.

func RedactURL

func RedactURL(err error) error

RedactURL removes the URL part from an error of *url.Error type.

func RepeatInterval

func RepeatInterval(ctx context.Context) (time.Duration, bool)

RepeatInterval extracts a repeat interval from the context. Iff none exists, the second argument is false.

func ResolvedAlerts

func ResolvedAlerts(ctx context.Context) ([]uint64, bool)

ResolvedAlerts extracts a slice of firing alerts from the context. Iff none exists, the second argument is false.

func TmplHTML

func TmplHTML(tmpl *template.Template, data *template.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 *template.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.

func TruncateInBytes

func TruncateInBytes(s string, n int) (string, bool)

TruncateInBytes truncates a string to fit the given size in Bytes.

func TruncateInRunes

func TruncateInRunes(s string, n int) (string, bool)

TruncateInRunes truncates a string to fit the given size in Runes.

func WithActiveTimeIntervals

func WithActiveTimeIntervals(ctx context.Context, at []string) context.Context

func WithFiringAlerts

func WithFiringAlerts(ctx context.Context, alerts []uint64) context.Context

WithFiringAlerts populates a context with a slice of firing alerts.

func WithGroupKey

func WithGroupKey(ctx context.Context, s string) context.Context

WithGroupKey populates a context with a group key.

func WithGroupLabels

func WithGroupLabels(ctx context.Context, lset model.LabelSet) context.Context

WithGroupLabels populates a context with grouping labels.

func WithMuteTimeIntervals

func WithMuteTimeIntervals(ctx context.Context, mt []string) context.Context

WithMuteTimeIntervals populates a context with a slice of mute time names.

func WithNow

func WithNow(ctx context.Context, t time.Time) context.Context

WithNow populates a context with a now timestamp.

func WithReceiverName

func WithReceiverName(ctx context.Context, rcv string) context.Context

WithReceiverName populates a context with a receiver name.

func WithRepeatInterval

func WithRepeatInterval(ctx context.Context, t time.Duration) context.Context

WithRepeatInterval populates a context with a repeat interval.

func WithResolvedAlerts

func WithResolvedAlerts(ctx context.Context, alerts []uint64) context.Context

WithResolvedAlerts populates a context with a slice of resolved alerts.

type DedupStage

DedupStage filters alerts. Filtering happens based on a notification log.

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

func NewDedupStage

func NewDedupStage(rs ResolvedSender, l NotificationLog, recv *nflogpb.Receiver) *DedupStage

NewDedupStage wraps a DedupStage that runs against the given notification log.

func (*DedupStage) Exec

func (n *DedupStage) Exec(ctx context.Context, _ log.Logger, alerts ...*types.Alert) (context.Context, []*types.Alert, error)

Exec implements the Stage interface.

type FanoutStage

FanoutStage executes its stages concurrently

type FanoutStage []Stage

func (FanoutStage) Exec

func (fs FanoutStage) Exec(ctx context.Context, l log.Logger, alerts ...*types.Alert) (context.Context, []*types.Alert, error)

Exec attempts to execute all stages concurrently and discards the results. It returns its input alerts and a types.MultiError if one or more stages fail.

type GossipSettleStage

GossipSettleStage waits until the Gossip has settled to forward alerts.

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

func NewGossipSettleStage

func NewGossipSettleStage(p Peer) *GossipSettleStage

NewGossipSettleStage returns a new GossipSettleStage.

func (*GossipSettleStage) Exec

func (n *GossipSettleStage) Exec(ctx context.Context, _ log.Logger, alerts ...*types.Alert) (context.Context, []*types.Alert, error)

type Integration

Integration wraps a notifier and its configuration to be uniquely identified by name and index from its origin in the configuration.

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

func NewIntegration

func NewIntegration(notifier Notifier, rs ResolvedSender, name string, idx int) Integration

NewIntegration returns a new integration.

func (*Integration) Index

func (i *Integration) Index() int

Index returns the index of the integration.

func (*Integration) Name

func (i *Integration) Name() string

Name returns the name of the integration.

func (*Integration) Notify

func (i *Integration) Notify(ctx context.Context, alerts ...*types.Alert) (bool, error)

Notify implements the Notifier interface.

func (*Integration) SendResolved

func (i *Integration) SendResolved() bool

SendResolved implements the ResolvedSender interface.

func (*Integration) String

func (i *Integration) String() string

String implements the Stringer interface.

type Key

Key is a string that can be hashed.

type Key string

func ExtractGroupKey

func ExtractGroupKey(ctx context.Context) (Key, error)

ExtractGroupKey gets the group key from the context.

func (Key) Hash

func (k Key) Hash() string

Hash returns the sha256 for a group key as integrations may have maximum length requirements on deduplication keys.

func (Key) String

func (k Key) String() string

type Metrics

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

func NewMetrics

func NewMetrics(r prometheus.Registerer) *Metrics

type MultiStage

A MultiStage executes a series of stages sequentially.

type MultiStage []Stage

func (MultiStage) Exec

func (ms MultiStage) Exec(ctx context.Context, l log.Logger, alerts ...*types.Alert) (context.Context, []*types.Alert, error)

Exec implements the Stage interface.

type MuteStage

MuteStage filters alerts through a Muter.

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

func NewMuteStage

func NewMuteStage(m types.Muter) *MuteStage

NewMuteStage return a new MuteStage.

func (*MuteStage) Exec

func (n *MuteStage) Exec(ctx context.Context, _ log.Logger, alerts ...*types.Alert) (context.Context, []*types.Alert, error)

Exec implements the Stage interface.

type NotificationLog

type NotificationLog interface {
    Log(r *nflogpb.Receiver, gkey string, firingAlerts, resolvedAlerts []uint64, expiry time.Duration) error
    Query(params ...nflog.QueryParam) ([]*nflogpb.Entry, error)
}

type Notifier

Notifier notifies about alerts under constraints of the given context. It returns an error if unsuccessful and a flag whether the error is recoverable. This information is useful for a retry logic.

type Notifier interface {
    Notify(context.Context, ...*types.Alert) (bool, error)
}

type Peer

Peer represents the cluster node from where we are the sending the notification.

type Peer interface {
    // WaitReady waits until the node silences and notifications have settled before attempting to send a notification.
    WaitReady(context.Context) error
}

type PipelineBuilder

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

func NewPipelineBuilder

func NewPipelineBuilder(r prometheus.Registerer) *PipelineBuilder

func (*PipelineBuilder) New

func (pb *PipelineBuilder) New(
    receivers map[string][]Integration,
    wait func() time.Duration,
    inhibitor *inhibit.Inhibitor,
    silencer *silence.Silencer,
    times map[string][]timeinterval.TimeInterval,
    notificationLog NotificationLog,
    peer Peer,
) RoutingStage

New returns a map of receivers to Stages.

type ResolvedSender

ResolvedSender returns true if resolved notifications should be sent.

type ResolvedSender interface {
    SendResolved() bool
}

type Retrier

Retrier knows when to retry an HTTP request to a receiver. 2xx status codes are successful, anything else is a failure and only 5xx status codes should be retried.

type Retrier struct {
    // Function to return additional information in the error message.
    CustomDetailsFunc func(code int, body io.Reader) string
    // Additional HTTP status codes that should be retried.
    RetryCodes []int
}

func (*Retrier) Check

func (r *Retrier) Check(statusCode int, body io.Reader) (bool, error)

Check returns a boolean indicating whether the request should be retried and an optional error if the request has failed. If body is not nil, it will be included in the error message.

type RetryStage

RetryStage notifies via passed integration with exponential backoff until it succeeds. It aborts if the context is canceled or timed out.

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

func NewRetryStage

func NewRetryStage(i Integration, groupName string, metrics *Metrics) *RetryStage

NewRetryStage returns a new instance of a RetryStage.

func (RetryStage) Exec

func (r RetryStage) Exec(ctx context.Context, l log.Logger, alerts ...*types.Alert) (context.Context, []*types.Alert, error)

type RoutingStage

RoutingStage executes the inner stages based on the receiver specified in the context.

type RoutingStage map[string]Stage

func (RoutingStage) Exec

func (rs RoutingStage) Exec(ctx context.Context, l log.Logger, alerts ...*types.Alert) (context.Context, []*types.Alert, error)

Exec implements the Stage interface.

type SetNotifiesStage

SetNotifiesStage sets the notification information about passed alerts. The passed alerts should have already been sent to the receivers.

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

func NewSetNotifiesStage

func NewSetNotifiesStage(l NotificationLog, recv *nflogpb.Receiver) *SetNotifiesStage

NewSetNotifiesStage returns a new instance of a SetNotifiesStage.

func (SetNotifiesStage) Exec

func (n SetNotifiesStage) Exec(ctx context.Context, l log.Logger, alerts ...*types.Alert) (context.Context, []*types.Alert, error)

Exec implements the Stage interface.

type Stage

A Stage processes alerts under the constraints of the given context.

type Stage interface {
    Exec(ctx context.Context, l log.Logger, alerts ...*types.Alert) (context.Context, []*types.Alert, error)
}

type StageFunc

StageFunc wraps a function to represent a Stage.

type StageFunc func(ctx context.Context, l log.Logger, alerts ...*types.Alert) (context.Context, []*types.Alert, error)

func (StageFunc) Exec

func (f StageFunc) Exec(ctx context.Context, l log.Logger, alerts ...*types.Alert) (context.Context, []*types.Alert, error)

Exec implements Stage interface.

type TimeActiveStage

type TimeActiveStage timeStage

func NewTimeActiveStage

func NewTimeActiveStage(ti map[string][]timeinterval.TimeInterval) *TimeActiveStage

func (TimeActiveStage) Exec

func (tas TimeActiveStage) Exec(ctx context.Context, l log.Logger, alerts ...*types.Alert) (context.Context, []*types.Alert, error)

Exec implements the stage interface for TimeActiveStage. TimeActiveStage is responsible for muting alerts whose route is not in an active time.

type TimeMuteStage

type TimeMuteStage timeStage

func NewTimeMuteStage

func NewTimeMuteStage(ti map[string][]timeinterval.TimeInterval) *TimeMuteStage

func (TimeMuteStage) Exec

func (tms TimeMuteStage) Exec(ctx context.Context, l log.Logger, alerts ...*types.Alert) (context.Context, []*types.Alert, error)

Exec implements the stage interface for TimeMuteStage. TimeMuteStage is responsible for muting alerts whose route is not in an active time.

type WaitStage

WaitStage waits for a certain amount of time before continuing or until the context is done.

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

func NewWaitStage

func NewWaitStage(wait func() time.Duration) *WaitStage

NewWaitStage returns a new WaitStage.

func (*WaitStage) Exec

func (ws *WaitStage) Exec(ctx context.Context, _ log.Logger, alerts ...*types.Alert) (context.Context, []*types.Alert, error)

Exec implements the Stage interface.

Subdirectories