Documentation ¶
Index ¶
- Constants
- Variables
- func AllTemplateTypes() []string
- func ExpectReadyAt(now time.Time, dailyTimes []string) time.Time
- func ExpectReadyAtInTimeRange(now time.Time, timeRanges []TimeRange) time.Time
- type Agent
- type AgentRepo
- type DingdingRobot
- type DingdingRobotRepo
- type Event
- type EventByDatetimeCount
- type EventGroup
- type EventGroupAggByDatetimeCount
- type EventGroupAggCount
- type EventGroupByDatetimeCount
- type EventGroupByRuleCount
- type EventGroupByUserCount
- type EventGroupRepo
- type EventGroupRule
- type EventGroupStatus
- type EventMeta
- type EventRelation
- type EventRelationNote
- type EventRelationNoteRepo
- type EventRelationRepo
- type EventRepo
- type EventStatus
- type EventType
- type ID
- type KV
- type KVRepo
- type Lock
- type LockRepo
- type QueueItemStatus
- type QueueJob
- type QueueRepo
- type Recovery
- type RecoveryRepo
- type Rule
- type RuleRepo
- type RuleStatus
- type Sequence
- type SequenceRepo
- type Syslog
- type SyslogRepo
- type SyslogType
- type Tag
- type Template
- type TemplateRepo
- type TemplateType
- type TimeRange
- type Times
- type Trigger
- type TriggerStatus
- type User
- type UserIDWithMeta
- type UserMeta
- type UserMetas
- type UserRepo
- type UserStatus
Constants ¶
View Source
const ( // EventStatusPending 待处理 EventStatusPending EventStatus = "pending" // EventStatusGrouped 已分组(已经匹配规则并且分组) EventStatusGrouped EventStatus = "grouped" // EventStatusCanceled 已取消(没有任何匹配的规则) EventStatusCanceled EventStatus = "canceled" // EventStatusExpired 已过期(有匹配的规则,但是当时没有匹配) EventStatusExpired EventStatus = "expired" // EventStatusIgnored 死信(匹配规则,但是被主动忽略) EventStatusIgnored EventStatus = "ignored" // EventTypePlain 普通事件 EventTypePlain EventType = "plain" // EventTypeRecoverable 可恢复事件 EventTypeRecoverable EventType = "recoverable" // EventTypeRecovery 恢复事件 EventTypeRecovery EventType = "recovery" // EventTypeIgnored 被忽略的事件 EventTypeIgnored EventType = "ignored" // EventTypeIgnoredExceed 被忽略的事件,由于数量超过最大忽略阈值, // 加入到报警行列中,只在 Group.Type 中使用 EventTypeIgnoredExceed EventType = "ignoredExceed" )
View Source
const ( ReadyTypeInterval = "interval" ReadyTypeDailyTime = "daily_time" ReadyTypeTimeRange = "time_range" )
Variables ¶
View Source
var ( // ErrAlreadyLocked is returned by a locking operation when a resource // is already locked. ErrAlreadyLocked = errors.New("unable to acquire lock (resource is already locked)") // ErrLockNotFound is returned when a lock cannot be found. ErrLockNotFound = errors.New("unable to find lock") )
View Source
var ErrNotFound = errors.New("not found")
Functions ¶
func AllTemplateTypes ¶
func AllTemplateTypes() []string
Types ¶
type Agent ¶
type Agent struct { ID primitive.ObjectID `bson:"_id,omitempty" json:"id"` IP string `bson:"ip" json:"ip"` AgentID string `bson:"agent_id" json:"agent_id"` Version string `bson:"version" json:"version"` LastAliveAt time.Time `bson:"last_alive_at" json:"last_alive_at"` LastStat interface{} `bson:"last_stat" json:"last_stat"` CreatedAt time.Time `bson:"created_at" json:"created_at"` UpdatedAt time.Time `bson:"updated_at" json:"updated_at"` }
type DingdingRobot ¶
type DingdingRobot struct { ID primitive.ObjectID `bson:"_id,omitempty" json:"id"` Name string `bson:"name" json:"name"` Description string `bson:"description" json:"description"` Token string `bson:"token" json:"token"` Secret string `bson:"secret" json:"secret"` CreatedAt time.Time `bson:"created_at" json:"created_at"` UpdatedAt time.Time `bson:"updated_at" json:"updated_at"` }
type DingdingRobotRepo ¶
type DingdingRobotRepo interface { Add(robot DingdingRobot) (id primitive.ObjectID, err error) Get(id primitive.ObjectID) (robot DingdingRobot, err error) Find(filter bson.M) (robots []DingdingRobot, err error) Paginate(filter bson.M, offset, limit int64) (robots []DingdingRobot, next int64, err error) DeleteID(id primitive.ObjectID) error Delete(filter bson.M) error Update(id primitive.ObjectID, robot DingdingRobot) error Count(filter bson.M) (int64, error) }
type Event ¶
type Event struct { ID primitive.ObjectID `bson:"_id,omitempty" json:"id"` RelationID []primitive.ObjectID `bson:"relation_ids" json:"relation_ids"` SeqNum int64 `bson:"seq_num" json:"seq_num"` Content string `bson:"content" json:"content"` Meta EventMeta `bson:"meta" json:"meta"` Tags []string `bson:"tags" json:"tags"` Origin string `bson:"origin" json:"origin"` GroupID []primitive.ObjectID `bson:"group_ids" json:"group_ids"` Type EventType `bson:"type" json:"type"` Status EventStatus `bson:"status" json:"status"` CreatedAt time.Time `bson:"created_at" json:"created_at"` }
Event 事件
type EventByDatetimeCount ¶
type EventByDatetimeCount struct { Datetime time.Time `bson:"datetime" json:"datetime"` Total int64 `bson:"total" json:"total"` }
EventByDatetimeCount 时间范围内的事件数量
type EventGroup ¶
type EventGroup struct { ID primitive.ObjectID `bson:"_id,omitempty" json:"id"` SeqNum int64 `bson:"seq_num" json:"seq_num"` // AggregateKey 与 .Rule.AggregateKey 相同,方便读取 AggregateKey string `bson:"aggregate_key" json:"aggregate_key"` Type EventType `bson:"type" json:"type"` MessageCount int64 `bson:"message_count" json:"message_count"` Rule EventGroupRule `bson:"rule" json:"rule"` Actions []Trigger `bson:"actions" json:"actions"` Status EventGroupStatus `bson:"status" json:"status"` CreatedAt time.Time `bson:"created_at" json:"created_at"` UpdatedAt time.Time `bson:"updated_at" json:"updated_at"` }
func (*EventGroup) Ready ¶
func (grp *EventGroup) Ready() bool
Ready return whether the message group has reached close conditions
type EventGroupAggByDatetimeCount ¶
type EventGroupAggByDatetimeCount struct { Datetime time.Time `bson:"datetime" json:"datetime"` AggregateKey string `bson:"aggregate_key" json:"aggregate_key"` Total int64 `bson:"total" json:"total"` TotalMessages int64 `bson:"total_messages" json:"total_messages"` }
EventGroupAggByDatetimeCount 时间范围内事件组聚合数量
type EventGroupAggCount ¶
type EventGroupAggCount struct { AggregateKey string `bson:"aggregate_key" json:"aggregate_key"` Total int64 `bson:"total" json:"total"` }
EventGroupAggCount 事件组聚合数量
type EventGroupByRuleCount ¶
type EventGroupByUserCount ¶
type EventGroupRepo ¶
type EventGroupRepo interface { Add(grp EventGroup) (id primitive.ObjectID, err error) Get(id primitive.ObjectID) (grp EventGroup, err error) Find(filter bson.M) (grps []EventGroup, err error) Paginate(filter bson.M, offset, limit int64, sortByCreatedAtDesc bool) (grps []EventGroup, next int64, err error) Delete(filter bson.M) error DeleteID(id primitive.ObjectID) error Traverse(filter bson.M, cb func(grp EventGroup) error) error UpdateID(id primitive.ObjectID, grp EventGroup) error Count(filter bson.M) (int64, error) // LastGroup get last group which match the filter in messageGroups LastGroup(filter bson.M) (grp EventGroup, err error) CollectingGroup(rule EventGroupRule) (group EventGroup, err error) // StatByRuleCount 按照规则的维度,查询规则相关的报警次数 StatByRuleCount(ctx context.Context, startTime, endTime time.Time) ([]EventGroupByRuleCount, error) StatByUserCount(ctx context.Context, startTime, endTime time.Time) ([]EventGroupByUserCount, error) StatByDatetimeCount(ctx context.Context, filter bson.M, startTime, endTime time.Time, hour int64) ([]EventGroupByDatetimeCount, error) StatByAggCountInPeriod(ctx context.Context, ruleID primitive.ObjectID, startTime, endTime time.Time, hour int64) ([]EventGroupAggByDatetimeCount, error) StatByAggCount(ctx context.Context, ruleID primitive.ObjectID, startTime, endTime time.Time) ([]EventGroupAggCount, error) }
type EventGroupRule ¶
type EventGroupRule struct { ID primitive.ObjectID `bson:"_id" json:"id"` Name string `bson:"name" json:"name"` // AggregateKey 通过该 Key 对同一个规则下的 message 分组 AggregateKey string `bson:"aggregate_key" json:"aggregate_key"` Type EventType `bson:"type" json:"type"` // ExpectReadyAt 预期就绪时间,当超过该时间后,Group自动关闭,发起通知 ExpectReadyAt time.Time `bson:"expect_ready_at" json:"expect_ready_at"` Realtime bool `bson:"realtime" json:"realtime"` Rule string `bson:"rule" json:"rule"` IgnoreRule string `bson:"ignore_rule" json:"ignore_rule"` IgnoreMaxCount int `bson:"ignore_max_count" json:"ignore_max_count"` Template string `bson:"template" json:"template"` SummaryTemplate string `bson:"summary_template" json:"summary_template"` // Report template ReportTemplateID primitive.ObjectID `bson:"report_template_id" json:"report_template_id"` }
type EventGroupStatus ¶
type EventGroupStatus string
const ( EventGroupStatusCollecting EventGroupStatus = "collecting" EventGroupStatusPending EventGroupStatus = "pending" EventGroupStatusOK EventGroupStatus = "ok" EventGroupStatusFailed EventGroupStatus = "failed" EventGroupStatusCanceled EventGroupStatus = "canceled" )
type EventRelation ¶
type EventRelation struct { ID primitive.ObjectID `bson:"_id,omitempty" json:"id,omitempty"` MatchedRuleID primitive.ObjectID `bson:"matched_rule_id,omitempty" json:"matched_rule_id,omitempty"` Summary string `bson:"summary" json:"summary,omitempty"` EventCount int64 `bson:"event_count" json:"event_count,omitempty"` CreatedAt time.Time `bson:"created_at" json:"created_at,omitempty"` UpdatedAt time.Time `bson:"updated_at" json:"updated_at,omitempty"` }
EventRelation 事件关联
type EventRelationNote ¶
type EventRelationNote struct { ID primitive.ObjectID `bson:"_id,omitempty" json:"id"` RelationID primitive.ObjectID `bson:"relation_id,omitempty" json:"relation_id"` EventID primitive.ObjectID `bson:"event_id,omitempty" json:"event_id"` Note string `bson:"note" json:"note"` CreatorID primitive.ObjectID `bson:"creator_id,omitempty" json:"creator_id"` CreatorName string `bson:"creator_name" json:"creator_name"` CreatedAt time.Time `bson:"created_at" json:"created_at"` DeletedAt time.Time `bson:"deleted_at" json:"deleted_at"` }
EventRelationNote 事件关联备注
type EventRelationNoteRepo ¶
type EventRelationNoteRepo interface { AddNote(ctx context.Context, note EventRelationNote) (ID, error) PaginateNotes(ctx context.Context, relID primitive.ObjectID, filter bson.M, offset, limit int64) (notes []EventRelationNote, next int64, err error) DeleteNote(ctx context.Context, relID primitive.ObjectID, filter bson.M) error }
EventRelationNoteRepo 事件关联备注仓库接口
type EventRelationRepo ¶
type EventRelationRepo interface { AddOrUpdateEventRelation(ctx context.Context, summary string, matchedRuleID primitive.ObjectID) (EventRelation, error) Get(ctx context.Context, id primitive.ObjectID) (eventRel EventRelation, err error) Paginate(ctx context.Context, filter interface{}, offset, limit int64) (eventRels []EventRelation, next int64, err error) Count(ctx context.Context, filter interface{}) (int64, error) }
EventRelationRepo 事件关联仓库接口
type EventRepo ¶
type EventRepo interface { AddWithContext(ctx context.Context, msg Event) (id primitive.ObjectID, err error) Add(msg Event) (id primitive.ObjectID, err error) Get(id primitive.ObjectID) (msg Event, err error) Has(filter interface{}) (bool, error) Find(filter interface{}) (messages []Event, err error) FindIDs(ctx context.Context, filter interface{}, limit int64) ([]primitive.ObjectID, error) Paginate(filter interface{}, offset, limit int64) (messages []Event, next int64, err error) Delete(filter interface{}) error DeleteID(id primitive.ObjectID) error Traverse(filter interface{}, cb func(msg Event) error) error UpdateID(id primitive.ObjectID, update Event) error Count(filter interface{}) (int64, error) CountByDatetime(ctx context.Context, filter bson.M, startTime, endTime time.Time, hour int64) ([]EventByDatetimeCount, error) }
EventRepo 事件管理仓库接口
type EventStatus ¶
type EventStatus string
type Lock ¶
type Lock struct { LockID primitive.ObjectID `bson:"lock_id" json:"lock_id"` Resource string `bson:"resource" json:"resource"` Acquired bool `bson:"acquired" json:"acquired"` Owner string `bson:"owner" json:"owner"` TTL uint `bson:"ttl" json:"ttl"` CreatedAt time.Time `bson:"created_at" json:"created_at"` RenewedAt time.Time `bson:"renewed_at" json:"renewed_at"` ExpiredAt time.Time `bson:"expired_at" json:"expired_at"` }
type QueueItemStatus ¶
type QueueItemStatus string
const ( QueueItemStatusWait QueueItemStatus = "wait" QueueItemStatusRunning QueueItemStatus = "running" QueueItemStatusFailed QueueItemStatus = "failed" QueueItemStatusSucceed QueueItemStatus = "succeed" QueueItemStatusCanceled QueueItemStatus = "canceled" )
type QueueJob ¶
type QueueJob struct { ID primitive.ObjectID `bson:"_id,omitempty" json:"id"` Name string `bson:"name" json:"name"` Payload string `bson:"payload" json:"payload"` Status QueueItemStatus `bson:"status" json:"status"` LastError string `bson:"last_error" json:"last_error"` RequeueTimes int `bson:"requeue_times" json:"requeue_times"` NextExecuteAt time.Time `bson:"next_execute_at" json:"next_execute_at"` CreatedAt time.Time `bson:"created_at" json:"created_at"` UpdatedAt time.Time `bson:"updated_at" json:"updated_at"` }
type QueueRepo ¶
type QueueRepo interface { // Enqueue add a item to queue // if the item is new(id is empty), add it to queue // if the item is already existed, replace it Enqueue(ctx context.Context, item QueueJob) (primitive.ObjectID, error) Dequeue(ctx context.Context) (QueueJob, error) UpdateID(ctx context.Context, id primitive.ObjectID, jobItem QueueJob) error Update(ctx context.Context, filter bson.M, item QueueJob) error Paginate(filter bson.M, offset, limit int64) (items []QueueJob, next int64, err error) Delete(filter bson.M) error DeleteID(id primitive.ObjectID) error Get(id primitive.ObjectID) (QueueJob, error) Count(filter bson.M) (int64, error) }
type Recovery ¶
type Recovery struct { RecoveryID string `json:"recovery_id" bson:"recovery_id"` RecoveryAt time.Time `json:"recovery_at" bson:"recovery_at"` RefIDs []primitive.ObjectID `json:"ref_ids" bson:"ref_ids"` CreatedAt time.Time `json:"created_at" bson:"created_at"` UpdatedAt time.Time `json:"updated_at" json:"updated_at"` }
type RecoveryRepo ¶
type Rule ¶
type Rule struct { ID primitive.ObjectID `bson:"_id,omitempty" json:"id"` Name string `bson:"name" json:"name"` Description string `bson:"description" json:"description"` Tags []string `bson:"tags" json:"tags"` // AggregateRule 聚合规则,同一个规则匹配的事件,会按照该规则返回的值进行更加精细的分组 AggregateRule string `bson:"aggregate_rule" json:"aggregate_rule"` // RelationRule 关联规则,匹配的事件会被创建关联关系 RelationRule string `bson:"relation_rule" json:"relation_rule"` // ReadType 就绪类型,支持 interval/daily_time ReadyType string `bson:"ready_type" json:"ready_type"` Interval int64 `bson:"interval" json:"interval"` DailyTimes []string `bson:"daily_times" json:"daily_times"` TimeRanges []TimeRange `bson:"time_ranges" json:"time_ranges"` // RealtimeInterval 即时触发,当该值 > 0 时,将会采用即时触发,超过周期后,第一个发生的事件将会立即触发告警 RealtimeInterval int64 `bson:"realtime_interval" json:"realtime_interval"` // Rule 用于分组匹配的规则 Rule string `bson:"rule" json:"rule"` // IgnoreRule 分组匹配后,检查 message 是否应该被忽略 IgnoreRule string `bson:"ignore_rule" json:"ignore_rule"` IgnoreMaxCount int `bson:"ignore_max_count" json:"ignore_max_count"` Template string `bson:"template" json:"template"` SummaryTemplate string `bson:"summary_template" json:"summary_template"` Triggers []Trigger `bson:"triggers" json:"triggers"` // ReportTemplateID 报表模板 ID ReportTemplateID primitive.ObjectID `bson:"report_template_id" json:"report_template_id"` Status RuleStatus `bson:"status" json:"status"` CreatedAt time.Time `bson:"created_at" json:"created_at"` UpdatedAt time.Time `bson:"updated_at" json:"updated_at"` }
Rule is a rule definition
func (Rule) ToGroupRule ¶
func (rule Rule) ToGroupRule(aggregateKey string, msgType EventType) EventGroupRule
ToGroupRule convert Rule to EventGroupRule
type RuleRepo ¶
type RuleRepo interface { Add(rule Rule) (id primitive.ObjectID, err error) Get(id primitive.ObjectID) (rule Rule, err error) Paginate(filter interface{}, offset, limit int64) (rules []Rule, next int64, err error) Find(filter bson.M) (rules []Rule, err error) Traverse(filter bson.M, cb func(rule Rule) error) error UpdateID(id primitive.ObjectID, rule Rule) error Count(filter bson.M) (int64, error) Delete(filter bson.M) error DeleteID(id primitive.ObjectID) error Tags(ctx context.Context) ([]Tag, error) }
type RuleStatus ¶
type RuleStatus string
const ( RuleStatusEnabled RuleStatus = "enabled" RuleStatusDisabled RuleStatus = "disabled" )
type SequenceRepo ¶
type Syslog ¶
type Syslog struct { ID primitive.ObjectID `bson:"_id,omitempty" json:"id"` Type SyslogType `bson:"type" json:"type"` Context map[string]interface{} `bson:"context" json:"context"` Body string `bson:"body" json:"body"` CreatedAt time.Time `bson:"created_at" json:"created_at"` }
Syslog 系统日志存储
type SyslogRepo ¶
type SyslogRepo interface { Add(al Syslog) (id primitive.ObjectID, err error) Get(id primitive.ObjectID) (al Syslog, err error) Paginate(filter bson.M, offset, limit int64) (logs []Syslog, next int64, err error) Delete(filter bson.M) error DeleteID(id primitive.ObjectID) error }
SyslogRepo 系统日志仓库
type SyslogType ¶
type SyslogType string
SyslogType 系统日志类型
const ( // SyslogTypeError 错误日志类型 SyslogTypeError SyslogType = "ERROR" // SyslogTypeAction 行为动作类型 SyslogTypeAction SyslogType = "ACTION" // SyslogTypeSystem 系统类型 SyslogTypeSystem SyslogType = "SYSTEM" )
type Template ¶
type Template struct { ID primitive.ObjectID `bson:"_id,omitempty" json:"id"` Name string `bson:"name" json:"name"` Description string `bson:"description" json:"description"` Content string `bson:"content" json:"content"` Type TemplateType `bson:"type" json:"type"` Predefined bool `bson:"predefined" json:"predefined"` CreatedAt time.Time `bson:"created_at" json:"created_at"` UpdatedAt time.Time `bson:"updated_at" json:"updated_at"` }
type TemplateRepo ¶
type TemplateRepo interface { Add(temp Template) (id primitive.ObjectID, err error) Get(id primitive.ObjectID) (temp Template, err error) Find(filter bson.M) (templates []Template, err error) Paginate(filter bson.M, offset, limit int64) (templates []Template, next int64, err error) DeleteID(id primitive.ObjectID) error Delete(filter bson.M) error Update(id primitive.ObjectID, temp Template) error Count(filter bson.M) (int64, error) }
type TemplateType ¶
type TemplateType string
const ( TemplateTypeMatchRule TemplateType = "match_rule" TemplateTypeTemplate TemplateType = "template" TemplateTypeTriggerRule TemplateType = "trigger_rule" TemplateTypeDingdingTemplate TemplateType = "template_dingding" TemplateTypeReport TemplateType = "template_report" )
type Trigger ¶
type Trigger struct { ID primitive.ObjectID `bson:"_id,omitempty" json:"id"` Name string `bson:"name" json:"name"` // IsElseTrigger 是否是兜底的 Trigger,当所有的非 ElseTrigger 均未匹配时生效 // IsElseTrigger 为 true 时,忽略 PreCondition 规则,全部匹配 IsElseTrigger bool `bson:"is_else_trigger" json:"is_else_trigger"` PreCondition string `bson:"pre_condition" json:"pre_condition"` Action string `bson:"action" json:"action"` Meta string `bson:"meta" json:"meta"` UserRefs []primitive.ObjectID `bson:"user_refs" json:"user_refs"` UserEvalFunc string `bson:"user_eval_func" json:"user_eval_func"` // UserNames 最终匹配的用户列表 UserNames []string `bson:"user_names,omitempty" json:"user_names,omitempty"` // for group actions Status TriggerStatus `bson:"trigger_status,omitempty" json:"trigger_status,omitempty"` FailedCount int `bson:"failed_count" json:"failed_count"` FailedReason string `bson:"failed_reason" json:"failed_reason"` }
Trigger is a action trigger for matched rules
type TriggerStatus ¶
type TriggerStatus string
const ( TriggerStatusOK TriggerStatus = "ok" TriggerStatusFailed TriggerStatus = "failed" )
type User ¶
type User struct { ID primitive.ObjectID `bson:"_id,omitempty" json:"id"` Name string `bson:"name" json:"name"` Email string `bson:"email" json:"email"` Phone string `bson:"phone" json:"phone"` Password string `bson:"password" json:"password"` Role string `bson:"role" json:"role"` Metas UserMetas `bson:"metas" json:"metas"` Status UserStatus `bson:"status" json:"status"` CreatedAt time.Time `bson:"created_at" json:"created_at"` UpdatedAt time.Time `bson:"updated_at" json:"updated_at"` }
type UserIDWithMeta ¶
type UserRepo ¶
type UserRepo interface { Add(user User) (id primitive.ObjectID, err error) Get(id primitive.ObjectID) (user User, err error) GetByEmail(email string) (user User, err error) Find(filter bson.M) (users []User, err error) Paginate(filter bson.M, offset, limit int64) (users []User, next int64, err error) DeleteID(id primitive.ObjectID) error Delete(filter bson.M) error Update(id primitive.ObjectID, user User) error Count(filter bson.M) (int64, error) GetUserMetas(queryK, queryV, field string) ([]string, error) GetUserIDWithMetas(queryK, queryV, field string) ([]UserIDWithMeta, error) GetUserMetasRegex(queryK, queryVRegex, field string) ([]string, error) GetUserIDWithMetasRegex(queryK, queryVRegex, field string) ([]UserIDWithMeta, error) }
type UserStatus ¶
type UserStatus string
const ( UserStatusEnabled UserStatus = "enabled" UserStatusDisabled UserStatus = "disabled" )
Source Files ¶
Click to show internal directories.
Click to hide internal directories.