repository

package
v0.0.0-...-c229084 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 18, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

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"
)
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

func ExpectReadyAt

func ExpectReadyAt(now time.Time, dailyTimes []string) time.Time

func ExpectReadyAtInTimeRange

func ExpectReadyAtInTimeRange(now time.Time, timeRanges []TimeRange) time.Time

ExpectReadyAtInTimeRange 根据当前时间和时间范围,计算预期时间,时间范围为前开后闭区间

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"`
}

func (Agent) Alive

func (agent Agent) Alive() bool

type AgentRepo

type AgentRepo interface {
	Update(agent Agent) (ID, error)
	Get(id ID) (agent Agent, err error)
	Find(filter bson.M) (agents []Agent, err error)
	Delete(filter bson.M) error
	DeleteID(id ID) error
}

type AuditLog

type AuditLog struct {
	ID primitive.ObjectID `bson:"_id,omitempty" json:"id"`

	Type    AuditLogType           `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"`
}

AuditLog 审计日志存储

type AuditLogRepo

type AuditLogRepo interface {
	Add(al AuditLog) (id primitive.ObjectID, err error)
	Get(id primitive.ObjectID) (al AuditLog, err error)
	Paginate(filter bson.M, offset, limit int64) (logs []AuditLog, next int64, err error)
	Delete(filter bson.M) error
	DeleteID(id primitive.ObjectID) error
}

AuditLogRepo 审计日志仓库

type AuditLogType

type AuditLogType string

AuditLogType 审计日志类型

const (
	// AuditLogTypeError 错误日志类型
	AuditLogTypeError AuditLogType = "ERROR"
	// AuditLogTypeAction 行为动作类型
	AuditLogTypeAction AuditLogType = "ACTION"
	// AuditLogTypeSystem 系统类型
	AuditLogTypeSystem AuditLogType = "SYSTEM"
)

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 EventGroupByDatetimeCount

type EventGroupByDatetimeCount struct {
	Datetime      time.Time `bson:"datetime" json:"datetime"`
	Total         int64     `bson:"total" json:"total"`
	TotalMessages int64     `bson:"total_messages" json:"total_messages"`
}

type EventGroupByRuleCount

type EventGroupByRuleCount struct {
	RuleID        primitive.ObjectID `bson:"rule_id" json:"rule_id"`
	RuleName      string             `bson:"rule_name" json:"rule_name"`
	Total         int64              `bson:"total" json:"total"`
	TotalMessages int64              `bson:"total_messages" json:"total_messages"`
}

type EventGroupByUserCount

type EventGroupByUserCount struct {
	UserID        primitive.ObjectID `bson:"user_id" json:"user_id"`
	UserName      string             `bson:"user_name" json:"user_name"`
	Total         int64              `bson:"total" json:"total"`
	TotalMessages int64              `bson:"total_messages" json:"total_messages"`
}

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) (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)

	// Statistics
	// 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"`
	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 EventMeta

type EventMeta map[string]interface{}

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)
	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 EventType

type EventType string

type ID

type ID string

type KV

type KV struct {
	Key       string      `json:"key" bson:"key"`
	Value     interface{} `json:"value" bson:"value"`
	ExpiredAt time.Time   `json:"expired_at" bson:"expired_at"`
	WithTTL   bool        `json:"with_ttl" bson:"with_ttl"`
	CreatedAt time.Time   `json:"created_at" bson:"created_at"`
}

type KVRepo

type KVRepo interface {
	Set(key string, value interface{}) error
	SetWithTTL(key string, value interface{}, ttl time.Duration) error
	Get(key string) (pair KV, err error)
	Remove(key string) (removeCount int64, err error)
	All(filter bson.M) (pairs []KV, err error)
	GC() error
}

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 LockRepo

type LockRepo interface {
	Lock(resource string, owner string, ttl uint) (*Lock, error)
	Renew(lockID primitive.ObjectID, ttl uint) (*Lock, error)
	UnLock(lockID primitive.ObjectID) error
	Remove(resource string) error
}

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 RecoveryRepo interface {
	Register(ctx context.Context, recoveryAt time.Time, recoveryID string, refID primitive.ObjectID) (err error)
	RecoverableEvents(ctx context.Context, deadline time.Time) ([]Recovery, error)
	Delete(ctx context.Context, recoveryID string) error
}

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"`
	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 Sequence

type Sequence struct {
	Name  string `bson:"name" json:"name"`
	Value int64  `bson:"value" json:"value"`
}

type SequenceRepo

type SequenceRepo interface {
	Next(name string) (seq Sequence, err error)
	Truncate(name string) error
}

type Tag

type Tag struct {
	Name  string `bson:"_id" json:"name"`
	Count int64  `bson:"count" json:"count"`
}

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 TimeRange

type TimeRange struct {
	// StartTime 开始时间(包含该时间)
	StartTime string `bson:"start_time" json:"start_time"`
	// EndTime 截止时间(不包含改时间)
	EndTime  string `bson:"end_time" json:"end_time"`
	Interval int64  `bson:"interval" json:"interval"`
}

type Times

type Times []time.Time

func (Times) Len

func (t Times) Len() int

func (Times) Less

func (t Times) Less(i, j int) bool

func (Times) Swap

func (t Times) Swap(i, j int)

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"`
	// 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 UserMeta

type UserMeta struct {
	Key   string `bson:"key" json:"key" schema:"key"`
	Value string `bson:"value" json:"value" schema:"value"`
}

type UserMetas

type UserMetas []UserMeta

func (UserMetas) Get

func (ums UserMetas) Get(key string) string

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)
}

type UserStatus

type UserStatus string
const (
	UserStatusEnabled  UserStatus = "enabled"
	UserStatusDisabled UserStatus = "disabled"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL