Documentation ¶
Index ¶
- Constants
- Variables
- func GetDecryptedValueFnForTesting(_ context.Context, sjd map[string][]byte, key string, fallback string) string
- func ProcessIntegrationError(config *GrafanaIntegrationConfig, err error) error
- type APIReceiver
- type Alert
- type AlertGroup
- type AlertGroups
- type AlertValidationError
- type ClusterPeer
- type ConfigReceiver
- type Configuration
- type DispatcherLimits
- type FakeConfig
- func (f *FakeConfig) DispatcherLimits() DispatcherLimits
- func (f *FakeConfig) Hash() [16]byte
- func (f *FakeConfig) InhibitRules() []*InhibitRule
- func (f *FakeConfig) MuteTimeIntervals() []MuteTimeInterval
- func (f *FakeConfig) Raw() []byte
- func (f *FakeConfig) ReceiverIntegrations() (map[string][]Integration, error)
- func (f *FakeConfig) RoutingTree() *Route
- func (f *FakeConfig) Templates() *templates.Template
- type GetDecryptedValueFn
- type GettableAlert
- type GettableAlerts
- type GettableSilence
- type GettableSilences
- type GrafanaAlertmanager
- func (am *GrafanaAlertmanager) ApplyConfig(cfg Configuration) (err error)
- func (am *GrafanaAlertmanager) ConfigHash() [16]byte
- func (am *GrafanaAlertmanager) CreateSilence(ps *PostableSilence) (string, error)
- func (am *GrafanaAlertmanager) DeleteSilence(silenceID string) error
- func (am *GrafanaAlertmanager) ExternalURL() string
- func (am *GrafanaAlertmanager) GetAlertGroups(active, silenced, inhibited bool, filter []string, receivers string) (AlertGroups, error)
- func (am *GrafanaAlertmanager) GetAlerts(active, silenced, inhibited bool, filter []string, receivers string) (GettableAlerts, error)
- func (am *GrafanaAlertmanager) GetReceivers() []*NotifyReceiver
- func (am *GrafanaAlertmanager) GetSilence(silenceID string) (GettableSilence, error)
- func (am *GrafanaAlertmanager) GetStatus() []byte
- func (am *GrafanaAlertmanager) ListSilences(filter []string) (GettableSilences, error)
- func (am *GrafanaAlertmanager) PutAlerts(postableAlerts amv2.PostableAlerts) error
- func (am *GrafanaAlertmanager) Ready() bool
- func (am *GrafanaAlertmanager) StopAndWait()
- func (am *GrafanaAlertmanager) TemplateFromPaths(paths []string, options ...template.Option) (*templates.Template, error)
- func (am *GrafanaAlertmanager) TestReceivers(ctx context.Context, c TestReceiversConfigBodyParams) (*TestReceiversResult, error)
- func (am *GrafanaAlertmanager) TestTemplate(ctx context.Context, c TestTemplatesConfigBodyParams) (*TestTemplatesResults, error)
- func (am *GrafanaAlertmanager) WithLock(fn func())
- func (am *GrafanaAlertmanager) WithReadLock(fn func())
- func (am *GrafanaAlertmanager) WorkingDirectory() string
- type GrafanaAlertmanagerConfig
- type GrafanaAlertmanagerMetrics
- type GrafanaIntegrationConfig
- type GrafanaIntegrations
- type GrafanaReceiverConfig
- type InhibitRule
- type Integration
- type IntegrationTimeoutError
- type IntegrationValidationError
- type MaintenanceOptions
- type MuteTimeInterval
- type NilChannel
- type NilPeer
- type Notifier
- type NotifierConfig
- type NotifierConfigTest
- type NotifyReceiver
- type PostableAlert
- type PostableAlerts
- type PostableSilence
- type Receiver
- type Route
- type Silence
- type State
- type TemplateErrorKind
- type TestIntegrationConfigResult
- type TestReceiverResult
- type TestReceiversConfigAlertParams
- type TestReceiversConfigBodyParams
- type TestReceiversResult
- type TestTemplatesConfigBodyParams
- type TestTemplatesErrorResult
- type TestTemplatesResult
- type TestTemplatesResults
- type TimeInterval
Constants ¶
const ( DefaultReceiverName = "TestReceiver" DefaultGroupLabel = "group_label" DefaultGroupLabelValue = "group_label_value" )
const ActiveStateLabelValue = "active"
const InactiveStateLabelValue = "inactive"
Variables ¶
var ( ErrGetAlertsInternal = fmt.Errorf("unable to retrieve alerts(s) due to an internal error") ErrGetAlertsBadPayload = fmt.Errorf("unable to retrieve alerts") ErrGetAlertGroupsBadPayload = fmt.Errorf("unable to retrieve alerts groups") )
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 )
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, }, }
var (
ErrNoReceivers = errors.New("no receivers")
)
var NewIntegration = notify.NewIntegration
var OpenAPIAlertsToAlerts = v2.OpenAPIAlertsToAlerts
Functions ¶
func ProcessIntegrationError ¶
func ProcessIntegrationError(config *GrafanaIntegrationConfig, err error) error
Types ¶
type APIReceiver ¶
type APIReceiver struct { ConfigReceiver `yaml:",inline"` GrafanaIntegrations `yaml:",inline"` }
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 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 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 (am *GrafanaAlertmanager) TestReceivers(ctx context.Context, c TestReceiversConfigBodyParams) (*TestReceiversResult, error)
func (*GrafanaAlertmanager) TestTemplate ¶
func (am *GrafanaAlertmanager) TestTemplate(ctx context.Context, c TestTemplatesConfigBodyParams) (*TestTemplatesResults, error)
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 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 (e IntegrationValidationError) Error() string
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) AddState ¶
func (p *NilPeer) AddState(string, cluster.State, prometheus.Registerer) cluster.ClusterChannel
type NotifierConfig ¶
NotifierConfig represents parsed GrafanaIntegrationConfig.
type NotifierConfigTest ¶
func (NotifierConfigTest) GetRawNotifierConfig ¶
func (n NotifierConfigTest) GetRawNotifierConfig(name string) *GrafanaIntegrationConfig
type NotifyReceiver ¶
type PostableAlert ¶
type PostableAlert = amv2.PostableAlert
type PostableAlerts ¶
type PostableAlerts = amv2.PostableAlerts
type PostableSilence ¶
type PostableSilence = amv2.PostableSilence
type State ¶
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 TestReceiverResult ¶
type TestReceiverResult struct { Name string Configs []TestIntegrationConfigResult }
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 TestTemplatesResults ¶
type TestTemplatesResults struct { Results []TestTemplatesResult Errors []TestTemplatesErrorResult }
type TimeInterval ¶
type TimeInterval = config.TimeInterval