notify

package
v0.0.0-...-f7ed62b Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: AGPL-3.0 Imports: 67 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultReceiverName    = "TestReceiver"
	DefaultGroupLabel      = "group_label"
	DefaultGroupLabelValue = "group_label_value"
)
View Source
const ActiveStateLabelValue = "active"
View Source
const InactiveStateLabelValue = "inactive"

Variables

View Source
var (
	ErrGetAlertsInternal        = fmt.Errorf("unable to retrieve alerts(s) due to an internal error")
	ErrGetAlertsUnavailable     = fmt.Errorf("unable to retrieve alerts(s) as alertmanager is not initialised yet")
	ErrGetAlertsBadPayload      = fmt.Errorf("unable to retrieve alerts")
	ErrGetAlertGroupsBadPayload = fmt.Errorf("unable to retrieve alerts groups")
)
View Source
var (
	ErrGetSilencesInternal     = fmt.Errorf("unable to retrieve silence(s) due to an internal error")
	ErrDeleteSilenceInternal   = fmt.Errorf("unable to delete silence due to an internal error")
	ErrCreateSilenceBadPayload = fmt.Errorf("unable to create silence")
	ErrListSilencesBadPayload  = fmt.Errorf("unable to list silences")
	ErrSilenceNotFound         = silence.ErrNotFound
)
View Source
var AllKnownConfigsForTesting = map[string]NotifierConfigTest{
	"prometheus-alertmanager": {
		NotifierType: "prometheus-alertmanager",
		Config:       alertmanager.FullValidConfigForTesting,
		Secrets:      alertmanager.FullValidSecretsForTesting,
	},
	"dingding": {NotifierType: "dingding",
		Config: dinding.FullValidConfigForTesting,
	},
	"discord": {NotifierType: "discord",
		Config: discord.FullValidConfigForTesting,
	},
	"email": {NotifierType: "email",
		Config: email.FullValidConfigForTesting,
	},
	"googlechat": {NotifierType: "googlechat",
		Config: googlechat.FullValidConfigForTesting,
	},
	"kafka": {NotifierType: "kafka",
		Config:  kafka.FullValidConfigForTesting,
		Secrets: kafka.FullValidSecretsForTesting,
	},
	"line": {NotifierType: "line",
		Config:  line.FullValidConfigForTesting,
		Secrets: line.FullValidSecretsForTesting,
	},
	"opsgenie": {NotifierType: "opsgenie",
		Config:  opsgenie.FullValidConfigForTesting,
		Secrets: opsgenie.FullValidSecretsForTesting,
	},
	"pagerduty": {NotifierType: "pagerduty",
		Config:  pagerduty.FullValidConfigForTesting,
		Secrets: pagerduty.FullValidSecretsForTesting,
	},
	"pushover": {NotifierType: "pushover",
		Config:  pushover.FullValidConfigForTesting,
		Secrets: pushover.FullValidSecretsForTesting,
	},
	"sensugo": {NotifierType: "sensugo",
		Config:  sensugo.FullValidConfigForTesting,
		Secrets: sensugo.FullValidSecretsForTesting,
	},
	"slack": {NotifierType: "slack",
		Config:  slack.FullValidConfigForTesting,
		Secrets: slack.FullValidSecretsForTesting,
	},
	"teams": {NotifierType: "teams",
		Config: teams.FullValidConfigForTesting,
	},
	"telegram": {NotifierType: "telegram",
		Config:  telegram.FullValidConfigForTesting,
		Secrets: telegram.FullValidSecretsForTesting,
	},
	"threema": {NotifierType: "threema",
		Config:  threema.FullValidConfigForTesting,
		Secrets: threema.FullValidSecretsForTesting,
	},
	"victorops": {NotifierType: "victorops",
		Config: victorops.FullValidConfigForTesting,
	},
	"webhook": {NotifierType: "webhook",
		Config:  webhook.FullValidConfigForTesting,
		Secrets: webhook.FullValidSecretsForTesting,
	},
	"wecom": {NotifierType: "wecom",
		Config:  wecom.FullValidConfigForTesting,
		Secrets: wecom.FullValidSecretsForTesting,
	},
	"webex": {NotifierType: "webex",
		Config:  webex.FullValidConfigForTesting,
		Secrets: webex.FullValidSecretsForTesting,
	},
}
View Source
var (
	ErrNoReceivers = errors.New("no receivers")
)
View Source
var NewIntegration = notify.NewIntegration
View Source
var OpenAPIAlertsToAlerts = v2.OpenAPIAlertsToAlerts

Functions

func GetDecryptedValueFnForTesting

func GetDecryptedValueFnForTesting(_ context.Context, sjd map[string][]byte, key string, fallback string) string

func ProcessIntegrationError

func ProcessIntegrationError(config *GrafanaIntegrationConfig, err error) error

Types

type APIReceiver

type APIReceiver struct {
	ConfigReceiver      `yaml:",inline"`
	GrafanaIntegrations `yaml:",inline"`
}

type Alert

type Alert = types.Alert

type AlertGroup

type AlertGroup = amv2.AlertGroup

type AlertGroups

type AlertGroups = amv2.AlertGroups

type AlertValidationError

type AlertValidationError struct {
	Alerts amv2.PostableAlerts
	Errors []error // Errors[i] refers to Alerts[i].
}

AlertValidationError is the error capturing the validation errors faced on the alerts.

func (AlertValidationError) Error

func (e AlertValidationError) Error() string

type ClusterPeer

type ClusterPeer interface {
	AddState(string, cluster.State, prometheus.Registerer) cluster.ClusterChannel
	Position() int
	WaitReady(context.Context) error
}

type ConfigReceiver

type ConfigReceiver = config.Receiver

type Configuration

type Configuration interface {
	DispatcherLimits() DispatcherLimits
	InhibitRules() []InhibitRule
	TimeIntervals() []TimeInterval
	// Deprecated: MuteTimeIntervals are deprecated in Alertmanager and will be removed in future versions.
	MuteTimeIntervals() []MuteTimeInterval
	Receivers() []*APIReceiver
	BuildReceiverIntegrationsFunc() func(next *APIReceiver, tmpl *templates.Template) ([]*Integration, error)

	RoutingTree() *Route
	Templates() []string

	Hash() [16]byte
	Raw() []byte
}

Configuration is an interface for accessing Alertmanager configuration.

type DispatcherLimits

type DispatcherLimits = dispatch.Limits

type FakeConfig

type FakeConfig struct {
}

func (*FakeConfig) DispatcherLimits

func (f *FakeConfig) DispatcherLimits() DispatcherLimits

func (*FakeConfig) Hash

func (f *FakeConfig) Hash() [16]byte

func (*FakeConfig) InhibitRules

func (f *FakeConfig) InhibitRules() []*InhibitRule

func (*FakeConfig) MuteTimeIntervals

func (f *FakeConfig) MuteTimeIntervals() []MuteTimeInterval

func (*FakeConfig) Raw

func (f *FakeConfig) Raw() []byte

func (*FakeConfig) ReceiverIntegrations

func (f *FakeConfig) ReceiverIntegrations() (map[string][]Integration, error)

func (*FakeConfig) RoutingTree

func (f *FakeConfig) RoutingTree() *Route

func (*FakeConfig) Templates

func (f *FakeConfig) Templates() *templates.Template

type GetDecryptedValueFn

type GetDecryptedValueFn func(ctx context.Context, sjd map[string][]byte, key string, fallback string) string

GetDecryptedValueFn is a function that returns the decrypted value of the given key. If the key is not present, then it returns the fallback value.

type GettableAlert

type GettableAlert = amv2.GettableAlert

type GettableAlerts

type GettableAlerts = amv2.GettableAlerts

type GettableSilence

type GettableSilence = amv2.GettableSilence

type GettableSilences

type GettableSilences = amv2.GettableSilences

type GrafanaAlertmanager

type GrafanaAlertmanager struct {
	Metrics *GrafanaAlertmanagerMetrics
	// contains filtered or unexported fields
}

func NewGrafanaAlertmanager

func NewGrafanaAlertmanager(tenantKey string, tenantID int64, config *GrafanaAlertmanagerConfig, peer ClusterPeer, logger log.Logger, m *GrafanaAlertmanagerMetrics) (*GrafanaAlertmanager, error)

NewGrafanaAlertmanager creates a new Grafana-specific Alertmanager.

func (*GrafanaAlertmanager) ApplyConfig

func (am *GrafanaAlertmanager) ApplyConfig(cfg Configuration) (err error)

ApplyConfig applies a new configuration by re-initializing all components using the configuration provided. It is not safe to call concurrently.

func (*GrafanaAlertmanager) ConfigHash

func (am *GrafanaAlertmanager) ConfigHash() [16]byte

ConfigHash returns the hash of the current running configuration. It is not safe to call without a lock.

func (*GrafanaAlertmanager) CreateSilence

func (am *GrafanaAlertmanager) CreateSilence(ps *PostableSilence) (string, error)

CreateSilence persists the provided silence and returns the silence ID if successful.

func (*GrafanaAlertmanager) DeleteSilence

func (am *GrafanaAlertmanager) DeleteSilence(silenceID string) error

DeleteSilence looks for and expires the silence by the provided silenceID. It returns ErrSilenceNotFound if the silence is not present.

func (*GrafanaAlertmanager) ExternalURL

func (am *GrafanaAlertmanager) ExternalURL() string

func (*GrafanaAlertmanager) GetAlertGroups

func (am *GrafanaAlertmanager) GetAlertGroups(active, silenced, inhibited bool, filter []string, receivers string) (AlertGroups, error)

func (*GrafanaAlertmanager) GetAlerts

func (am *GrafanaAlertmanager) GetAlerts(active, silenced, inhibited bool, filter []string, receivers string) (GettableAlerts, error)

func (*GrafanaAlertmanager) GetReceivers

func (am *GrafanaAlertmanager) GetReceivers() []*NotifyReceiver

GetReceivers returns the receivers configured as part of the current configuration. It is safe to call concurrently.

func (*GrafanaAlertmanager) GetSilence

func (am *GrafanaAlertmanager) GetSilence(silenceID string) (GettableSilence, error)

GetSilence retrieves a silence by the provided silenceID. It returns ErrSilenceNotFound if the silence is not present.

func (*GrafanaAlertmanager) GetStatus

func (am *GrafanaAlertmanager) GetStatus() []byte

TODO(gotjosh): I don't think this is right, make sure you evaluate it.

func (*GrafanaAlertmanager) ListSilences

func (am *GrafanaAlertmanager) ListSilences(filter []string) (GettableSilences, error)

ListSilences retrieves a list of stored silences. It supports a set of labels as filters.

func (*GrafanaAlertmanager) PutAlerts

func (am *GrafanaAlertmanager) PutAlerts(postableAlerts amv2.PostableAlerts) error

PutAlerts receives the alerts and then sends them through the corresponding route based on whenever the alert has a receiver embedded or not

func (*GrafanaAlertmanager) Ready

func (am *GrafanaAlertmanager) Ready() bool

func (*GrafanaAlertmanager) StopAndWait

func (am *GrafanaAlertmanager) StopAndWait()

func (*GrafanaAlertmanager) TemplateFromPaths

func (am *GrafanaAlertmanager) TemplateFromPaths(paths []string, options ...template.Option) (*templates.Template, error)

TemplateFromPaths returns a set of *Templates based on the paths given.

func (*GrafanaAlertmanager) TestReceivers

func (*GrafanaAlertmanager) TestTemplate

TestTemplate tests the given template string against the given alerts. Existing templates are used to provide context for the test. If an existing template of the same filename as the one being tested is found, it will not be used as context.

func (*GrafanaAlertmanager) WithLock

func (am *GrafanaAlertmanager) WithLock(fn func())

func (*GrafanaAlertmanager) WithReadLock

func (am *GrafanaAlertmanager) WithReadLock(fn func())

func (*GrafanaAlertmanager) WorkingDirectory

func (am *GrafanaAlertmanager) WorkingDirectory() string

type GrafanaAlertmanagerConfig

type GrafanaAlertmanagerConfig struct {
	WorkingDirectory   string
	ExternalURL        string
	AlertStoreCallback mem.AlertStoreCallback
	PeerTimeout        time.Duration

	Silences MaintenanceOptions
	Nflog    MaintenanceOptions
}

func (*GrafanaAlertmanagerConfig) Validate

func (c *GrafanaAlertmanagerConfig) Validate() error

type GrafanaAlertmanagerMetrics

type GrafanaAlertmanagerMetrics struct {
	Registerer prometheus.Registerer
	*metrics.Alerts
	// contains filtered or unexported fields
}

func NewGrafanaAlertmanagerMetrics

func NewGrafanaAlertmanagerMetrics(r prometheus.Registerer) *GrafanaAlertmanagerMetrics

NewGrafanaAlertmanagerMetrics creates a set of metrics for the Alertmanager.

type GrafanaIntegrationConfig

type GrafanaIntegrationConfig struct {
	UID                   string            `json:"uid"`
	Name                  string            `json:"name"`
	Type                  string            `json:"type"`
	DisableResolveMessage bool              `json:"disableResolveMessage"`
	Settings              json.RawMessage   `json:"settings"`
	SecureSettings        map[string]string `json:"secureSettings"`
}

type GrafanaIntegrations

type GrafanaIntegrations struct {
	Integrations []*GrafanaIntegrationConfig `yaml:"grafana_managed_receiver_configs,omitempty" json:"grafana_managed_receiver_configs,omitempty"`
}

type GrafanaReceiverConfig

type GrafanaReceiverConfig struct {
	Name                string
	AlertmanagerConfigs []*NotifierConfig[alertmanager.Config]
	DingdingConfigs     []*NotifierConfig[dinding.Config]
	DiscordConfigs      []*NotifierConfig[discord.Config]
	NtfyConfigs         []*NotifierConfig[ntfy.Config]
	EmailConfigs        []*NotifierConfig[email.Config]
	GooglechatConfigs   []*NotifierConfig[googlechat.Config]
	KafkaConfigs        []*NotifierConfig[kafka.Config]
	LineConfigs         []*NotifierConfig[line.Config]
	OpsgenieConfigs     []*NotifierConfig[opsgenie.Config]
	PagerdutyConfigs    []*NotifierConfig[pagerduty.Config]
	OnCallConfigs       []*NotifierConfig[oncall.Config]
	PushoverConfigs     []*NotifierConfig[pushover.Config]
	SensugoConfigs      []*NotifierConfig[sensugo.Config]
	SlackConfigs        []*NotifierConfig[slack.Config]
	TeamsConfigs        []*NotifierConfig[teams.Config]
	TelegramConfigs     []*NotifierConfig[telegram.Config]
	ThreemaConfigs      []*NotifierConfig[threema.Config]
	VictoropsConfigs    []*NotifierConfig[victorops.Config]
	WebhookConfigs      []*NotifierConfig[webhook.Config]
	WecomConfigs        []*NotifierConfig[wecom.Config]
	WebexConfigs        []*NotifierConfig[webex.Config]
}

GrafanaReceiverConfig represents a parsed and validated APIReceiver

func BuildReceiverConfiguration

func BuildReceiverConfiguration(ctx context.Context, api *APIReceiver, decrypt GetDecryptedValueFn) (GrafanaReceiverConfig, error)

BuildReceiverConfiguration parses, decrypts and validates the APIReceiver.

type InhibitRule

type InhibitRule = config.InhibitRule

type Integration

type Integration = notify.Integration

func BuildReceiverIntegrations

func BuildReceiverIntegrations(
	receiver GrafanaReceiverConfig,
	tmpl *templates.Template,
	img images.Provider,
	logger logging.LoggerFactory,
	newWebhookSender func(n receivers.Metadata) (receivers.WebhookSender, error),
	newEmailSender func(n receivers.Metadata) (receivers.EmailSender, error),
	orgID int64,
	version string,
) ([]*Integration, error)

BuildReceiverIntegrations creates integrations for each configured notification channel in GrafanaReceiverConfig. It returns a slice of Integration objects, one for each notification channel, along with any errors that occurred.

type IntegrationTimeoutError

type IntegrationTimeoutError struct {
	Integration *GrafanaIntegrationConfig
	Err         error
}

func (IntegrationTimeoutError) Error

func (e IntegrationTimeoutError) Error() string

type IntegrationValidationError

type IntegrationValidationError struct {
	Err         error
	Integration *GrafanaIntegrationConfig
}

func (IntegrationValidationError) Error

func (IntegrationValidationError) Unwrap

func (e IntegrationValidationError) Unwrap() error

type MaintenanceOptions

type MaintenanceOptions interface {
	// Filepath returns the string representation of the filesystem path of the file to do maintenance on.
	Filepath() string
	// Retention represents for how long should we keep the artefacts under maintenance.
	Retention() time.Duration
	// MaintenanceFrequency represents how often should we execute the maintenance.
	MaintenanceFrequency() time.Duration
	// MaintenanceFunc returns the function to execute as part of the maintenance process.
	// It returns the size of the file in bytes or an error if the maintenance fails.
	MaintenanceFunc(state State) (int64, error)
}

MaintenanceOptions represent the configuration options available for executing maintenance of Silences and the Notification log that the Alertmanager uses.

type MuteTimeInterval

type MuteTimeInterval = config.MuteTimeInterval

type NilChannel

type NilChannel struct{}

func (*NilChannel) Broadcast

func (c *NilChannel) Broadcast([]byte)

type NilPeer

type NilPeer struct{}

NilPeer and NilChannel implements the Alertmanager clustering interface.

func (*NilPeer) Position

func (p *NilPeer) Position() int

func (*NilPeer) WaitReady

func (p *NilPeer) WaitReady(context.Context) error

type Notifier

type Notifier = notify.Notifier

type NotifierConfig

type NotifierConfig[T interface{}] struct {
	receivers.Metadata
	Settings T
}

NotifierConfig represents parsed GrafanaIntegrationConfig.

type NotifierConfigTest

type NotifierConfigTest struct {
	NotifierType string
	Config       string
	Secrets      string
}

func (NotifierConfigTest) GetRawNotifierConfig

func (n NotifierConfigTest) GetRawNotifierConfig(name string) *GrafanaIntegrationConfig

type NotifyReceiver

type NotifyReceiver = notify.Receiver

type PostableAlert

type PostableAlert = amv2.PostableAlert

type PostableAlerts

type PostableAlerts = amv2.PostableAlerts

type PostableSilence

type PostableSilence = amv2.PostableSilence

type Receiver

type Receiver = amv2.Receiver

type Route

type Route = config.Route

type Silence

type Silence = amv2.Silence

type State

type State interface {
	MarshalBinary() ([]byte, error)
}

State represents any of the two 'states' of the alertmanager. Notification log or Silences. MarshalBinary returns the binary representation of this internal state based on the protobuf.

type TemplateErrorKind

type TemplateErrorKind string
const (
	InvalidTemplate TemplateErrorKind = "invalid_template"
	ExecutionError  TemplateErrorKind = "execution_error"
)

type TestIntegrationConfigResult

type TestIntegrationConfigResult struct {
	Name   string
	UID    string
	Status string
	Error  error
}

type TestReceiverResult

type TestReceiverResult struct {
	Name    string
	Configs []TestIntegrationConfigResult
}

type TestReceiversConfigAlertParams

type TestReceiversConfigAlertParams struct {
	Annotations model.LabelSet `yaml:"annotations,omitempty" json:"annotations,omitempty"`
	Labels      model.LabelSet `yaml:"labels,omitempty" json:"labels,omitempty"`
}

type TestReceiversConfigBodyParams

type TestReceiversConfigBodyParams struct {
	Alert     *TestReceiversConfigAlertParams `yaml:"alert,omitempty" json:"alert,omitempty"`
	Receivers []*APIReceiver                  `yaml:"receivers,omitempty" json:"receivers,omitempty"`
}

type TestReceiversResult

type TestReceiversResult struct {
	Alert     types.Alert
	Receivers []TestReceiverResult
	NotifedAt time.Time
}

type TestTemplatesConfigBodyParams

type TestTemplatesConfigBodyParams struct {
	// Alerts to use as data when testing the template.
	Alerts []*PostableAlert

	// Template string to test.
	Template string

	// Name of the template file.
	Name string
}

type TestTemplatesErrorResult

type TestTemplatesErrorResult struct {
	// Name of the associated template for this error. Will be empty if the Kind is "invalid_template".
	Name string

	// Kind of template error that occurred.
	Kind TemplateErrorKind

	// Error cause.
	Error error
}

type TestTemplatesResult

type TestTemplatesResult struct {
	// Name of the associated template definition for this result.
	Name string

	// Interpolated value of the template.
	Text string
}

type TestTemplatesResults

type TestTemplatesResults struct {
	Results []TestTemplatesResult
	Errors  []TestTemplatesErrorResult
}

type TimeInterval

type TimeInterval = config.TimeInterval

Jump to

Keyboard shortcuts

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