Documentation ¶
Index ¶
- Variables
- func InitChannels(settings []ChannelSpec) error
- type Alert
- type ChannelReceiverProvider
- type ChannelSpec
- type Emitter
- type Engine
- func (engine *Engine) AckEvent(ctx context.Context, fingerprint, username string) error
- func (engine *Engine) AddEventReceiver(ctx context.Context, user string, eventID int64) error
- func (engine *Engine) AddEventTag(ctx context.Context, id int64, tag string) error
- func (engine *Engine) CloseEvent(ctx context.Context, name, metric string, settings ...EventSetting) error
- func (engine *Engine) CloseEventByFingerprint(ctx context.Context, fingerprint string, settings ...EventSetting) error
- func (engine *Engine) DeleteEventTag(ctx context.Context, id int64, tag string) error
- func (engine *Engine) FireEvent(ctx context.Context, name, metric string, settings ...EventSetting) (Event, error)
- func (engine *Engine) GetEvent(ctx context.Context, id int64) (Event, error)
- func (engine *Engine) GetEventReceivers(ctx context.Context, eventID int64) ([]string, error)
- func (engine *Engine) GetEvents(ctx context.Context, user string, name, metric string, closed, acked bool, ...) ([]Event, error)
- type Event
- type EventCommand
- type EventSetting
- func WithEventACK() EventSetting
- func WithEventEmitter(emitter Emitter) EventSetting
- func WithEventExpire() EventSetting
- func WithEventExpiretime(t time.Time) EventSetting
- func WithEventHandlers(handlers ...Handler) EventSetting
- func WithEventLevel(level types.Level) EventSetting
- func WithEventMessage(msg string) EventSetting
- func WithEventName(name string) EventSetting
- func WithEventRecovery() EventSetting
- func WithEventRecoveryNotice(notice bool) EventSetting
- type GroupProvider
- type Handler
- type Mute
- type Mutes
- type Pipeline
- type Receiver
- type Stage
- type StageMute
- func (stage *StageMute) GetMutes(ctx context.Context, user ...string) Mutes
- func (stage *StageMute) Handle(alert Alert) []Alert
- func (stage *StageMute) Mute(ctx context.Context, name string, fingerprint, user string, deadline time.Time, ...) (Mute, error)
- func (stage *StageMute) Muted(name, fingerprint, user string) bool
- func (stage *StageMute) Unmute(ctx context.Context, fingerprint string) error
- func (stage *StageMute) UnmuteByID(ctx context.Context, id int64) error
- type StageSend
Constants ¶
This section is empty.
Variables ¶
var ( UntilRecoveryDeadline = time.Date(2019, 2, 19, 18, 03, 31, 0, time.Local) UntilRecoveryDeadlineUnix = UntilRecoveryDeadline.Unix() )
关闭通知 直到 告警恢复时, deadline 的取值
var (
Channels map[string]ChannelSpec
)
Functions ¶
Types ¶
type Alert ¶
type Alert struct {
// contains filtered or unexported fields
}
Alert represent a notice will be send
type ChannelReceiverProvider ¶
type ChannelSpec ¶
type ChannelSpec struct { Key string `yaml:"key" json:"key"` Name string `yaml:"name" json:"name"` MaxLength int `yaml:"max_length" json:"-"` // 允许最大消息长度,单位字节 Append string `yaml:"message_addon" json:"-"` Prepend string `yaml:"message_header" json:"-"` Setting map[string]string `yaml:"setting" json:"-"` // contains filtered or unexported fields }
ChannelSpec 表示一类通道 (channel) 的配置项
func (ChannelSpec) AppendText ¶
func (spec ChannelSpec) AppendText(data map[string]interface{}) string
AppendText 生成后缀缀内容
func (ChannelSpec) PrependText ¶
func (spec ChannelSpec) PrependText(data map[string]interface{}) string
PrependText 生成前缀内容
type Engine ¶
Engine manage a event pool, process the events, including persistent and notify etc
func NewEngine ¶
func NewEngine(ctx context.Context, storage *store.MySQL, emitter Emitter, g2u GroupProvider) (*Engine, error)
NewEngine create a new event engine
func (*Engine) AddEventReceiver ¶
AddEventReceiver 增加事件与接收人关联记录
func (*Engine) AddEventTag ¶
AddEventTag 为 一个事件增加标签
func (*Engine) CloseEvent ¶
func (engine *Engine) CloseEvent(ctx context.Context, name, metric string, settings ...EventSetting) error
CloseEvent 使事件恢复
func (*Engine) CloseEventByFingerprint ¶
func (engine *Engine) CloseEventByFingerprint(ctx context.Context, fingerprint string, settings ...EventSetting) error
CloseEventByFingerprint 使事件恢复
func (*Engine) DeleteEventTag ¶
DeleteEventTag 为 一个事件删除标签
func (*Engine) FireEvent ¶
func (engine *Engine) FireEvent(ctx context.Context, name, metric string, settings ...EventSetting) (Event, error)
FireEvent 方法, 用来创建 Event, 方法发现如果 Event 已存在则返回已存在的, 如果不存在再调用 CreateEvent 创建. 同时也要负责更新 Expire 等
func (*Engine) GetEventReceivers ¶
GetEventReceivers 获取与事件相关的接收人
type Event ¶
type Event struct { ID int64 `json:"id" db:"id"` Name string `json:"name" db:"name"` Fingerprint string `json:"fingerprint" db:"fingerprint"` Level types.Level `json:"level" db:"level"` Metric string `json:"metric" db:"metric"` Message string `json:"message" db:"message"` Notified int64 `json:"notified" db:"notified"` // 记录事件累计通知人次 RecoveryNotice bool `json:"recovery_notice" db:"recovery_notice"` // 是否发送恢复通知 ExpireTime time.Time `json:"expire_time" db:"expire_time"` CreatedTime time.Time `json:"created_time" db:"created_time"` UpdatedTime time.Time `json:"updated_time" db:"updated_time"` Expired bool `json:"expired" db:"expired"` // 事件是否过期, 只有 Closed = true 时才为 true, 表示是因过期而关闭, 而不是恢复关闭 Acked bool `json:"acked" db:"acked"` // 事件是否被认领(确认) AckUser string `json:"ackuser" db:"ackuser"` Recovery bool `json:"recovery" db:"recovery"` // 事件是否恢复, 只有 Closed = true 时这个值才有意义 Closed bool `json:"closed" db:"closed"` // 事件是否关闭, 即非活动 CloseTimeUnixnano int64 `json:"close_time_unixnano" db:"close_time_unixnano"` Handlers []Handler `json:"handlers" db:"-"` Tags types.StringList `json:"tags" db:"tags"` // contains filtered or unexported fields }
Event 代表一次异常事件 Event 的发送方面, 只要 AlertName 相同, 就会作为一个 Group 统一发送. 并不会像 Prometheus 那样根据 label 的 key-value 对匹配进行合并. 如果有这种情况, 要根据 key-value 对匹配, 那么就在外层做, 根据这些 event 的 key-value 对, 生成一个统一的 TaskName, 再交给 ecenter
func Clone ¶
func Clone(e Event, settings ...EventSetting) Event
Clone generate a new event from a given event
func New ¶
func New(ctx context.Context, name, metric string, settings ...EventSetting) Event
New generate a new event
func (*Event) GetFingerprint ¶
GetFingerprint return the fingerprint value for event, it generate fingerprint if it not generated
type EventCommand ¶
EventCommand 表示一个对 event 进行变更处理的命令, 比如更新关闭等等
type EventSetting ¶
type EventSetting func(event *Event)
EventSetting 代表配置选项
func WithEventExpiretime ¶
func WithEventExpiretime(t time.Time) EventSetting
WithEventExpiretime 修改 Event 的过期时间
func WithEventHandlers ¶
func WithEventHandlers(handlers ...Handler) EventSetting
WithEventHandlers 设置 handlers
func WithEventLevel ¶
func WithEventLevel(level types.Level) EventSetting
WithEventLevel 修改 Event 的 Level
func WithEventMessage ¶
func WithEventMessage(msg string) EventSetting
WithEventMessage 修改 Event 的 Message
func WithEventName ¶
func WithEventName(name string) EventSetting
WithEventName 设置 Event 的 TaskName, 任务名称更新时会用到
func WithEventRecoveryNotice ¶
func WithEventRecoveryNotice(notice bool) EventSetting
WithEventRecoveryNotice 设置事件确认
type GroupProvider ¶
GroupProvider convert group list to username list, if it is group name
type Handler ¶
type Handler struct { ID int64 `json:"id" db:"id"` EventID int64 `json:"event_id" db:"event_id"` Receivers types.StringList `json:"receivers" db:"receivers"` // 接收人 Channels types.Chan `json:"channels" db:"channels"` // 发送渠道 Everytime bool `json:"everytime" db:"everytime"` // 每次事件来了都通知, 如果为 true, delay 和 interval 会被忽略. Delay time.Duration `json:"delay" db:"delay"` // 延迟多久后通知 Interval time.Duration `json:"interval" db:"interval"` // 到达 delay 的时间后, 每隔 interval 时间, 就通知一次 CreatedTime time.Time `json:"created_time" db:"created_time"` UpdatedTime time.Time `json:"updated_time" db:"updated_time"` }
Handler is Event handler policy mainly used for emitting
type Mute ¶
type Mute struct { ID int64 `json:"id" db:"id"` User string `json:"user" db:"user"` Name string `json:"name" db:"name"` Fingerprint string `json:"fingerprint" db:"fingerprint"` Deadline time.Time `json:"deadline" db:"deadline"` Description string `json:"description" db:"description"` CreatedTime time.Time `json:"created_time" db:"created_time"` UpdatedTime time.Time `json:"updated_time" db:"updated_time"` }
Mute 代表一个屏蔽规则
type Pipeline ¶
type Pipeline struct {
// contains filtered or unexported fields
}
Pipeline is a kind of Emitter, and also the core Emitter
func NewPipeline ¶
NewPipeline create a new pipeline with handlers
type Receiver ¶
type Receiver struct {
// contains filtered or unexported fields
}
Receiver 表示一个告警接收人, 一个人收到的所有事件都会通过 input 发送近来;Receiver 会对事件做自动合并调用 Sender 发送消息
type StageMute ¶
func NewMuteStage ¶
func NewMuteStage(ctx context.Context, storage *store.MySQL, crp ChannelReceiverProvider) (*StageMute, error)
NewMuteStage create the mute stage for pipeline
func (*StageMute) Mute ¶
func (stage *StageMute) Mute(ctx context.Context, name string, fingerprint, user string, deadline time.Time, desc string) (Mute, error)
Mute 创建一条拦截规则, 对指定消息进行免通知