Documentation ¶
Index ¶
- Variables
- func BgNotMatchMuteStrategy(rule *models.AlertRule, event *models.AlertCurEvent) bool
- func EventMuteStrategy(rule *models.AlertRule, event *models.AlertCurEvent) bool
- func HandleEventNotify(event *models.AlertCurEvent, isSubscribe bool)
- func IdentNotExistsMuteStrategy(rule *models.AlertRule, event *models.AlertCurEvent) bool
- func IsMuted(rule *models.AlertRule, event *models.AlertCurEvent) bool
- func LogEvent(event *models.AlertCurEvent, location string, err ...error)
- func Reload()
- func Report(errorType ErrorType)
- func Send(rule *models.AlertRule, event *models.AlertCurEvent, ...)
- func Start(ctx context.Context) error
- func TimeNonEffectiveMuteStrategy(rule *models.AlertRule, event *models.AlertCurEvent) bool
- type AlertCurEventMap
- func (a *AlertCurEventMap) Delete(key string)
- func (a *AlertCurEventMap) Get(key string) (*models.AlertCurEvent, bool)
- func (a *AlertCurEventMap) GetAll() map[string]*models.AlertCurEvent
- func (a *AlertCurEventMap) Keys() []string
- func (a *AlertCurEventMap) Set(key string, value *models.AlertCurEvent)
- func (a *AlertCurEventMap) SetAll(data map[string]*models.AlertCurEvent)
- func (a *AlertCurEventMap) UpdateLastEvalTime(key string, lastEvalTime int64)
- type AlertRuleContext
- func (arc *AlertRuleContext) Eval()
- func (arc *AlertRuleContext) HandleRecover(alertingKeys map[string]struct{}, now int64)
- func (arc *AlertRuleContext) HandleVectors(vectors []conv.Vector, from string)
- func (arc *AlertRuleContext) Hash() string
- func (arc *AlertRuleContext) Key() string
- func (arc *AlertRuleContext) Prepare()
- func (arc *AlertRuleContext) RecoverSingle(hash string, now int64, value *string)
- func (arc *AlertRuleContext) RuleFromCache() *models.AlertRule
- func (arc *AlertRuleContext) Start()
- func (arc *AlertRuleContext) Stop()
- type AlertVector
- type ErrorType
- type MaintainMessage
- type MuteStrategyFunc
- type Notice
- type NotifyChannels
- type RecordRuleContext
- type Router
- type RuleContext
- type RuleHolder
- type Subscription
- func EventCallbacksRouter(rule *models.AlertRule, event *models.AlertCurEvent, prev *Subscription) *Subscription
- func GlobalWebhookRouter(rule *models.AlertRule, event *models.AlertCurEvent, prev *Subscription) *Subscription
- func GroupRouter(rule *models.AlertRule, event *models.AlertCurEvent, prev *Subscription) *Subscription
- func NewSubscription() *Subscription
- func NewSubscriptionFromUsers(users []*models.User) *Subscription
Constants ¶
This section is empty.
Variables ¶
var AlertMuteStrategies = []MuteStrategyFunc{ TimeNonEffectiveMuteStrategy, IdentNotExistsMuteStrategy, BgNotMatchMuteStrategy, EventMuteStrategy, }
var EventQueue = list.NewSafeListLimited(10000000)
var (
Senders map[string]sender.Sender
)
Functions ¶
func BgNotMatchMuteStrategy ¶ added in v5.14.5
func BgNotMatchMuteStrategy(rule *models.AlertRule, event *models.AlertCurEvent) bool
BgNotMatchMuteStrategy 当规则开启只在bg内部告警时,对于非bg内部的机器过滤
func EventMuteStrategy ¶ added in v5.14.5
func EventMuteStrategy(rule *models.AlertRule, event *models.AlertCurEvent) bool
func HandleEventNotify ¶ added in v5.15.0
func HandleEventNotify(event *models.AlertCurEvent, isSubscribe bool)
HandleEventNotify 处理event事件的主逻辑 event: 告警/恢复事件 isSubscribe: 告警事件是否由subscribe的配置产生
func IdentNotExistsMuteStrategy ¶ added in v5.14.5
func IdentNotExistsMuteStrategy(rule *models.AlertRule, event *models.AlertCurEvent) bool
IdentNotExistsMuteStrategy 根据ident是否存在过滤,如果ident不存在,则target_up的告警直接过滤掉
func IsMuted ¶ added in v5.9.7
func IsMuted(rule *models.AlertRule, event *models.AlertCurEvent) bool
func LogEvent ¶ added in v5.8.0
func LogEvent(event *models.AlertCurEvent, location string, err ...error)
func Send ¶ added in v5.15.0
func Send(rule *models.AlertRule, event *models.AlertCurEvent, subscription *Subscription, isSubscribe bool)
func TimeNonEffectiveMuteStrategy ¶ added in v5.14.5
func TimeNonEffectiveMuteStrategy(rule *models.AlertRule, event *models.AlertCurEvent) bool
TimeNonEffectiveMuteStrategy 根据规则配置的告警时间过滤,如果产生的告警不在规则配置的告警时间内,则不告警
Types ¶
type AlertCurEventMap ¶ added in v5.11.0
type AlertCurEventMap struct { sync.RWMutex Data map[string]*models.AlertCurEvent }
func NewAlertCurEventMap ¶ added in v5.11.0
func NewAlertCurEventMap(data map[string]*models.AlertCurEvent) *AlertCurEventMap
func (*AlertCurEventMap) Delete ¶ added in v5.11.0
func (a *AlertCurEventMap) Delete(key string)
func (*AlertCurEventMap) Get ¶ added in v5.11.0
func (a *AlertCurEventMap) Get(key string) (*models.AlertCurEvent, bool)
func (*AlertCurEventMap) GetAll ¶ added in v5.11.0
func (a *AlertCurEventMap) GetAll() map[string]*models.AlertCurEvent
func (*AlertCurEventMap) Keys ¶ added in v5.11.0
func (a *AlertCurEventMap) Keys() []string
func (*AlertCurEventMap) Set ¶ added in v5.11.0
func (a *AlertCurEventMap) Set(key string, value *models.AlertCurEvent)
func (*AlertCurEventMap) SetAll ¶ added in v5.11.0
func (a *AlertCurEventMap) SetAll(data map[string]*models.AlertCurEvent)
func (*AlertCurEventMap) UpdateLastEvalTime ¶ added in v5.11.0
func (a *AlertCurEventMap) UpdateLastEvalTime(key string, lastEvalTime int64)
type AlertRuleContext ¶ added in v5.14.5
type AlertRuleContext struct {
// contains filtered or unexported fields
}
func GetExternalAlertRule ¶ added in v5.14.5
func GetExternalAlertRule(cluster string, id int64) (*AlertRuleContext, bool)
func NewAlertRuleContext ¶ added in v5.14.5
func NewAlertRuleContext(rule *models.AlertRule, cluster string) *AlertRuleContext
func (*AlertRuleContext) Eval ¶ added in v5.14.5
func (arc *AlertRuleContext) Eval()
func (*AlertRuleContext) HandleRecover ¶ added in v5.14.5
func (arc *AlertRuleContext) HandleRecover(alertingKeys map[string]struct{}, now int64)
func (*AlertRuleContext) HandleVectors ¶ added in v5.14.5
func (arc *AlertRuleContext) HandleVectors(vectors []conv.Vector, from string)
func (*AlertRuleContext) Hash ¶ added in v5.14.5
func (arc *AlertRuleContext) Hash() string
func (*AlertRuleContext) Key ¶ added in v5.14.5
func (arc *AlertRuleContext) Key() string
func (*AlertRuleContext) Prepare ¶ added in v5.14.5
func (arc *AlertRuleContext) Prepare()
func (*AlertRuleContext) RecoverSingle ¶ added in v5.14.5
func (arc *AlertRuleContext) RecoverSingle(hash string, now int64, value *string)
func (*AlertRuleContext) RuleFromCache ¶ added in v5.14.5
func (arc *AlertRuleContext) RuleFromCache() *models.AlertRule
func (*AlertRuleContext) Start ¶ added in v5.14.5
func (arc *AlertRuleContext) Start()
func (*AlertRuleContext) Stop ¶ added in v5.14.5
func (arc *AlertRuleContext) Stop()
type AlertVector ¶ added in v5.14.5
type AlertVector struct { Ctx *AlertRuleContext Rule *models.AlertRule Vector conv.Vector From string // contains filtered or unexported fields }
AlertVector 包含一个告警事件的告警上下文
func NewAlertVector ¶ added in v5.14.5
func NewAlertVector(ctx *AlertRuleContext, rule *models.AlertRule, vector conv.Vector, from string) *AlertVector
func (*AlertVector) BuildEvent ¶ added in v5.14.5
func (av *AlertVector) BuildEvent(now int64) *models.AlertCurEvent
func (*AlertVector) Hash ¶ added in v5.14.5
func (av *AlertVector) Hash() string
type MaintainMessage ¶ added in v5.9.7
type MuteStrategyFunc ¶ added in v5.15.0
type MuteStrategyFunc func(rule *models.AlertRule, event *models.AlertCurEvent) bool
type Notice ¶
type Notice struct { Event *models.AlertCurEvent `json:"event"` Tpls map[string]string `json:"tpls"` }
type NotifyChannels ¶ added in v5.15.0
NotifyChannels channelKey -> bool
func NewNotifyChannels ¶ added in v5.15.0
func NewNotifyChannels(channels []string) NotifyChannels
func (NotifyChannels) AndMerge ¶ added in v5.15.0
func (nc NotifyChannels) AndMerge(other NotifyChannels)
func (NotifyChannels) OrMerge ¶ added in v5.15.0
func (nc NotifyChannels) OrMerge(other NotifyChannels)
type RecordRuleContext ¶ added in v5.14.5
type RecordRuleContext struct {
// contains filtered or unexported fields
}
func NewRecordRuleContext ¶ added in v5.14.5
func NewRecordRuleContext(rule *models.RecordingRule, cluster string) *RecordRuleContext
func (*RecordRuleContext) Eval ¶ added in v5.14.5
func (rrc *RecordRuleContext) Eval()
func (*RecordRuleContext) Hash ¶ added in v5.14.5
func (rrc *RecordRuleContext) Hash() string
func (*RecordRuleContext) Key ¶ added in v5.14.5
func (rrc *RecordRuleContext) Key() string
func (*RecordRuleContext) Prepare ¶ added in v5.14.5
func (rrc *RecordRuleContext) Prepare()
func (*RecordRuleContext) Start ¶ added in v5.14.5
func (rrc *RecordRuleContext) Start()
func (*RecordRuleContext) Stop ¶ added in v5.14.5
func (rrc *RecordRuleContext) Stop()
type Router ¶ added in v5.15.0
type Router func(rule *models.AlertRule, event *models.AlertCurEvent, prev *Subscription) *Subscription
Router 抽象由告警事件到订阅者的路由策略 rule: 告警规则 event: 告警事件 prev: 前一次路由结果, Router的实现可以直接修改prev, 也可以返回一个新的Subscription用于AndMerge/OrMerge
type RuleContext ¶ added in v5.14.5
RuleContext is the interface for alert rule and record rule
type RuleHolder ¶ added in v5.14.5
type RuleHolder struct {
// contains filtered or unexported fields
}
RuleHolder is the global rule holder
func (*RuleHolder) LoopSyncRules ¶ added in v5.14.5
func (rh *RuleHolder) LoopSyncRules(ctx context.Context)
func (*RuleHolder) SyncAlertRules ¶ added in v5.14.5
func (rh *RuleHolder) SyncAlertRules()
func (*RuleHolder) SyncRecordRules ¶ added in v5.14.5
func (rh *RuleHolder) SyncRecordRules()
type Subscription ¶ added in v5.15.0
type Subscription struct {
// contains filtered or unexported fields
}
Subscription 维护所有需要发送的用户-通道/回调/钩子信息,用map维护的数据结构具有去重功能
func EventCallbacksRouter ¶ added in v5.15.0
func EventCallbacksRouter(rule *models.AlertRule, event *models.AlertCurEvent, prev *Subscription) *Subscription
func GlobalWebhookRouter ¶ added in v5.15.0
func GlobalWebhookRouter(rule *models.AlertRule, event *models.AlertCurEvent, prev *Subscription) *Subscription
func GroupRouter ¶ added in v5.15.0
func GroupRouter(rule *models.AlertRule, event *models.AlertCurEvent, prev *Subscription) *Subscription
GroupRouter 处理告警规则的组订阅关系
func NewSubscription ¶ added in v5.15.0
func NewSubscription() *Subscription
func NewSubscriptionFromUsers ¶ added in v5.15.0
func NewSubscriptionFromUsers(users []*models.User) *Subscription
NewSubscriptionFromUsers 根据用户的token配置,生成订阅信息,用于notifyMaintainer
func (*Subscription) AndMerge ¶ added in v5.15.0
func (s *Subscription) AndMerge(other *Subscription)
AndMerge 将channelMap中的bool值按照and的逻辑进行合并,可以单独将人/通道维度的通知移除 常用的场景有: 1. 人员离职了不需要发送告警了 2. 某个告警通道进行维护,暂时不需要发送告警了 3. 业务值班的重定向逻辑,将高等级的告警额外发送给应急人员等 可以结合业务需求自己实现router
func (*Subscription) OrMerge ¶ added in v5.15.0
func (s *Subscription) OrMerge(other *Subscription)
OrMerge 将channelMap按照or的方式合并,方便实现多种组合的策略,比如根据某个tag进行路由等
func (*Subscription) ToCallbackList ¶ added in v5.15.0
func (s *Subscription) ToCallbackList() []string
func (*Subscription) ToChannelUserMap ¶ added in v5.15.0
func (s *Subscription) ToChannelUserMap() map[string][]int64
ToChannelUserMap userMap(map[uid][channel]bool) 转换为 map[channel][]uid 的结构
func (*Subscription) ToWebhookList ¶ added in v5.15.0
func (s *Subscription) ToWebhookList() []config.Webhook