Documentation ¶
Index ¶
- func ExecTemplate(q QueryFn, annotations map[string]string, tpl AlertTplData) (map[string]string, error)
- func GetTargets() map[TargetType][]Target
- func Init(gen AlertURLGenerator, extLabels map[string]string, extURL string) (func() []Notifier, error)
- func InitTemplateFunc(externalURL *url.URL)
- func Reload() error
- func ValidateTemplates(annotations map[string]string) error
- type Alert
- type AlertManager
- type AlertState
- type AlertTplData
- type AlertURLGenerator
- type Config
- type Notifier
- type QueryFn
- type StaticConfig
- type Target
- type TargetType
- type Time
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExecTemplate ¶ added in v1.50.2
func ExecTemplate(q QueryFn, annotations map[string]string, tpl AlertTplData) (map[string]string, error)
ExecTemplate executes the given template for given annotations map.
func GetTargets ¶ added in v1.73.0
func GetTargets() map[TargetType][]Target
GetTargets returns list of static or discovered targets via notifier configuration.
func Init ¶ added in v1.37.4
func Init(gen AlertURLGenerator, extLabels map[string]string, extURL string) (func() []Notifier, error)
Init returns a function for retrieving actual list of Notifier objects. Init works in two mods:
- configuration via flags (for backward compatibility). Is always static and don't support live reloads.
- configuration via file. Supports live reloads and service discovery.
Init returns an error if both mods are used.
func InitTemplateFunc ¶
InitTemplateFunc initiates template helper functions
func Reload ¶ added in v1.73.0
func Reload() error
Reload checks the changes in configPath configuration file and applies changes if any.
func ValidateTemplates ¶ added in v1.35.0
ValidateTemplates validate annotations for possible template error, uses empty data for template population
Types ¶
type Alert ¶
type Alert struct { // GroupID contains the ID of the parent rules group GroupID uint64 // Name represents Alert name Name string // Labels is the list of label-value pairs attached to the Alert Labels map[string]string // Annotations is the list of annotations generated on Alert evaluation Annotations map[string]string // State represents the current state of the Alert State AlertState // Expr contains expression that was executed to generate the Alert Expr string // Start defines the moment of time when Alert has triggered Start time.Time // End defines the moment of time when Alert supposed to expire End time.Time // LastSent defines the moment when Alert was sent last time LastSent time.Time // Value stores the value returned from evaluating expression from Expr field Value float64 // ID is the unique identifer for the Alert ID uint64 // Restored is true if Alert was restored after restart Restored bool }
Alert the triggered alert TODO: Looks like alert name isn't unique
type AlertManager ¶
type AlertManager struct {
// contains filtered or unexported fields
}
AlertManager represents integration provider with Prometheus alert manager https://github.com/prometheus/alertmanager
func NewAlertManager ¶
func NewAlertManager(alertManagerURL string, fn AlertURLGenerator, authCfg promauth.HTTPClientConfig, timeout time.Duration) (*AlertManager, error)
NewAlertManager is a constructor for AlertManager
func (AlertManager) Addr ¶ added in v1.65.0
func (am AlertManager) Addr() string
Addr returns address where alerts are sent.
func (*AlertManager) Close ¶ added in v1.73.0
func (am *AlertManager) Close()
Close is a destructor method for AlertManager
type AlertState ¶
type AlertState int
AlertState type indicates the Alert state
const ( // StateInactive is the state of an alert that is neither firing nor pending. StateInactive AlertState = iota // StatePending is the state of an alert that has been active for less than // the configured threshold duration. StatePending // StateFiring is the state of an alert that has been active for longer than // the configured threshold duration. StateFiring )
type AlertTplData ¶ added in v1.50.2
AlertTplData is used to execute templating
type AlertURLGenerator ¶
AlertURLGenerator returns URL to single alert by given name
type Config ¶ added in v1.73.0
type Config struct { // Scheme defines the HTTP scheme for Notifier address Scheme string `yaml:"scheme,omitempty"` // PathPrefix is added to URL path before adding alertManagerPath value PathPrefix string `yaml:"path_prefix,omitempty"` // ConsulSDConfigs contains list of settings for service discovery via Consul // see https://prometheus.io/docs/prometheus/latest/configuration/configuration/#consul_sd_config ConsulSDConfigs []consul.SDConfig `yaml:"consul_sd_configs,omitempty"` // StaticConfigs contains list of static targets StaticConfigs []StaticConfig `yaml:"static_configs,omitempty"` // HTTPClientConfig contains HTTP configuration for Notifier clients HTTPClientConfig promauth.HTTPClientConfig `yaml:",inline"` // RelabelConfigs contains list of relabeling rules RelabelConfigs []promrelabel.RelabelConfig `yaml:"relabel_configs,omitempty"` // The timeout used when sending alerts. Timeout promutils.Duration `yaml:"timeout,omitempty"` // Checksum stores the hash of yaml definition for the config. // May be used to detect any changes to the config file. Checksum string // Catches all undefined fields and must be empty after parsing. XXX map[string]interface{} `yaml:",inline"` // contains filtered or unexported fields }
Config contains list of supported configuration settings for Notifier
func (*Config) UnmarshalYAML ¶ added in v1.73.0
UnmarshalYAML implements the yaml.Unmarshaler interface.
type Notifier ¶
type Notifier interface { // Send sends the given list of alerts. // Returns an error if fails to send the alerts. // Must unblock if the given ctx is cancelled. Send(ctx context.Context, alerts []Alert) error // Addr returns address where alerts are sent. Addr() string // Close is a destructor for the Notifier Close() }
Notifier is a common interface for alert manager provider
type QueryFn ¶ added in v1.50.0
type QueryFn func(query string) ([]datasource.Metric, error)
QueryFn is used to wrap a call to datasource into simple-to-use function for templating functions.
type StaticConfig ¶ added in v1.73.0
type StaticConfig struct {
Targets []string `yaml:"targets"`
}
StaticConfig contains list of static targets in the following form:
targets: [ - '<host>' ]
type Target ¶ added in v1.73.0
type Target struct { Notifier Labels []prompbmarshal.Label }
Target represents a Notifier and optional list of labels added during discovery.
type TargetType ¶ added in v1.73.0
type TargetType string
TargetType defines how the Target was discovered
const ( // TargetStatic is for targets configured statically TargetStatic TargetType = "static" // TargetConsul is for targets discovered via Consul TargetConsul TargetType = "consulSD" )
type Time ¶
type Time int64
Time is the number of milliseconds since the epoch (1970-01-01 00:00 UTC) excluding leap seconds.
func TimeFromUnixNano ¶
TimeFromUnixNano returns the Time equivalent to the Unix Time t provided in nanoseconds.