Documentation ¶
Index ¶
- func LogEvent(event *models.AlertCurEvent, location string, err ...error)
- type Consumer
- type Dispatch
- type Notice
- type NotifyChannels
- type NotifyTarget
- func EventCallbacksDispatch(rule *models.AlertRule, event *models.AlertCurEvent, prev *NotifyTarget, ...) *NotifyTarget
- func GlobalWebhookDispatch(rule *models.AlertRule, event *models.AlertCurEvent, prev *NotifyTarget, ...) *NotifyTarget
- func NewNotifyTarget() *NotifyTarget
- func NotifyGroupDispatch(rule *models.AlertRule, event *models.AlertCurEvent, prev *NotifyTarget, ...) *NotifyTarget
- type NotifyTargetDispatch
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Consumer ¶
type Consumer struct {
// contains filtered or unexported fields
}
func NewConsumer ¶
创建一个 Consumer 实例
func (*Consumer) LoopConsume ¶
func (e *Consumer) LoopConsume()
type Dispatch ¶
func NewDispatch ¶
func NewDispatch(alertRuleCache *memsto.AlertRuleCacheType, userCache *memsto.UserCacheType, userGroupCache *memsto.UserGroupCacheType, alertSubscribeCache *memsto.AlertSubscribeCacheType, targetCache *memsto.TargetCacheType, notifyConfigCache *memsto.NotifyConfigCacheType, alerting aconf.Alerting, ctx *ctx.Context) *Dispatch
创建一个 Notify 实例
func (*Dispatch) HandleEventNotify ¶
func (e *Dispatch) HandleEventNotify(event *models.AlertCurEvent, isSubscribe bool)
HandleEventNotify 处理event事件的主逻辑 event: 告警/恢复事件 isSubscribe: 告警事件是否由subscribe的配置产生
func (*Dispatch) ReloadTpls ¶
func (*Dispatch) Send ¶
func (e *Dispatch) Send(rule *models.AlertRule, event *models.AlertCurEvent, notifyTarget *NotifyTarget, isSubscribe bool)
type Notice ¶
type Notice struct { Event *models.AlertCurEvent `json:"event"` Tpls map[string]string `json:"tpls"` }
type NotifyChannels ¶
NotifyChannels channelKey -> bool
func NewNotifyChannels ¶
func NewNotifyChannels(channels []string) NotifyChannels
func (NotifyChannels) AndMerge ¶
func (nc NotifyChannels) AndMerge(other NotifyChannels)
func (NotifyChannels) OrMerge ¶
func (nc NotifyChannels) OrMerge(other NotifyChannels)
type NotifyTarget ¶
type NotifyTarget struct {
// contains filtered or unexported fields
}
NotifyTarget 维护所有需要发送的目标 用户-通道/回调/钩子信息,用map维护的数据结构具有去重功能
func EventCallbacksDispatch ¶
func EventCallbacksDispatch(rule *models.AlertRule, event *models.AlertCurEvent, prev *NotifyTarget, dispatch *Dispatch) *NotifyTarget
func GlobalWebhookDispatch ¶
func GlobalWebhookDispatch(rule *models.AlertRule, event *models.AlertCurEvent, prev *NotifyTarget, dispatch *Dispatch) *NotifyTarget
func NewNotifyTarget ¶
func NewNotifyTarget() *NotifyTarget
func NotifyGroupDispatch ¶
func NotifyGroupDispatch(rule *models.AlertRule, event *models.AlertCurEvent, prev *NotifyTarget, dispatch *Dispatch) *NotifyTarget
GroupDispatch 处理告警规则的组订阅关系
func (*NotifyTarget) AndMerge ¶
func (s *NotifyTarget) AndMerge(other *NotifyTarget)
AndMerge 将 channelMap 中的 bool 值按照 and 的逻辑进行合并,可以单独将人/通道维度的通知移除 常用的场景有: 1. 人员离职了不需要发送告警了 2. 某个告警通道进行维护,暂时不需要发送告警了 3. 业务值班的重定向逻辑,将高等级的告警额外发送给应急人员等 可以结合业务需求自己实现router
func (*NotifyTarget) OrMerge ¶
func (s *NotifyTarget) OrMerge(other *NotifyTarget)
OrMerge 将 channelMap 按照 or 的方式合并,方便实现多种组合的策略,比如根据某个 tag 进行路由等
func (*NotifyTarget) ToCallbackList ¶
func (s *NotifyTarget) ToCallbackList() []string
func (*NotifyTarget) ToChannelUserMap ¶
func (s *NotifyTarget) ToChannelUserMap() map[string][]int64
ToChannelUserMap userMap(map[uid][channel]bool) 转换为 map[channel][]uid 的结构
func (*NotifyTarget) ToWebhookList ¶
func (s *NotifyTarget) ToWebhookList() []*models.Webhook
type NotifyTargetDispatch ¶
type NotifyTargetDispatch func(rule *models.AlertRule, event *models.AlertCurEvent, prev *NotifyTarget, dispatch *Dispatch) *NotifyTarget
Dispatch 抽象由告警事件到信息接收者的路由策略 rule: 告警规则 event: 告警事件 prev: 前一次路由结果, Dispatch 的实现可以直接修改 prev, 也可以返回一个新的 NotifyTarget 用于 AndMerge/OrMerge