alerting

package
v1.30.1 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2025 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AlertStateAlerting string = "alerting"
	AlertStateOK              = "ok"
	AlertStateError           = "error"
	AlertStateNodata          = "nodata"
)
View Source
const (
	MessageStateAlerting  = "alerting"
	MessageStateIgnored   = "ignored"
	MessageStateRecovered = "recovered"
)
View Source
const (
	ChannelEmail   = "email"
	ChannelWebhook = "webhook"
)

Variables

View Source
var PriorityWeights = map[string]int{
	"info":     1,
	"low":      2,
	"medium":   3,
	"high":     4,
	"critical": 5,
}

Functions

This section is empty.

Types

type ActionExecutionResult

type ActionExecutionResult struct {
	ExecutionTime int    `json:"execution_time"`
	Error         string `json:"error"`
	Result        string `json:"result"`
	Message       string `json:"message"`
	ChannelName   string `json:"channel_name"`
	ChannelType   string `json:"channel_type"`
	ChannelID     string `json:"channel_id"`
}

type Alert

type Alert struct {
	ID                      string                  `json:"id,omitempty"      elastic_meta:"_id" elastic_mapping:"id: { type: keyword }"`
	Created                 time.Time               `json:"created,omitempty" elastic_mapping:"created: { type: date }"`
	Updated                 time.Time               `json:"updated,omitempty" elastic_mapping:"updated: { type: date }"`
	RuleID                  string                  `json:"rule_id"  elastic_mapping:"rule_id: { type: keyword }"`
	RuleName                string                  `json:"rule_name"  elastic_mapping:"rule_name: { type: keyword }"`
	ResourceID              string                  `json:"resource_id"  elastic_mapping:"resource_id: { type: keyword }"`
	ResourceName            string                  `json:"resource_name"  elastic_mapping:"resource_name: { type: keyword }"`
	Expression              string                  `json:"expression"  elastic_mapping:"expression: { type: keyword, copy_to:search_text }"`
	Objects                 []string                `json:"objects" elastic_mapping:"objects: { type:keyword,copy_to:search_text }"`
	Priority                string                  `json:"priority" elastic_mapping:"priority: { type: keyword }"`
	Title                   string                  `json:"title" elastic_mapping:"title: { type: keyword }"`
	Message                 string                  `json:"message" elastic_mapping:"context: { type: keyword, copy_to:search_text }"`
	AcknowledgedTime        interface{}             `json:"acknowledged_time,omitempty"`
	ActionExecutionResults  []ActionExecutionResult `json:"action_execution_results,omitempty"`
	RecoverActionResults    []ActionExecutionResult `json:"recover_action_results,omitempty"`
	EscalationActionResults []ActionExecutionResult `json:"escalation_action_results,omitempty"`
	Users                   []string                `json:"users,omitempty"`
	State                   string                  `json:"state"`
	Error                   string                  `json:"error,omitempty"`
	IsNotified              bool                    `json:"is_notified" elastic_mapping:"is_notified: { type: boolean }"`   //标识本次检测是否发送了告警通知
	IsEscalated             bool                    `json:"is_escalated" elastic_mapping:"is_escalated: { type: boolean }"` //标识本次检测是否发送了升级告警通知
	Conditions              Condition               `json:"condition"`
	ConditionResult         *ConditionResult        `json:"condition_result,omitempty" elastic_mapping:"condition_result: { type: object,enabled:false }"`
	SearchText              string                  `json:"-" elastic_mapping:"search_text:{type:text,index_prefixes:{},index_phrases:true, analyzer:suggest_text_search }"`
}

type AlertMessage

type AlertMessage struct {
	ID            string    `json:"id,omitempty"      elastic_meta:"_id" elastic_mapping:"id: { type: keyword }"`
	Created       time.Time `json:"created,omitempty" elastic_mapping:"created: { type: date }"`
	Updated       time.Time `json:"updated,omitempty" elastic_mapping:"updated: { type: date }"`
	RuleID        string    `json:"rule_id"  elastic_mapping:"rule_id: { type: keyword,copy_to:search_text }"`
	ResourceID    string    `json:"resource_id"  elastic_mapping:"resource_id: { type: keyword,copy_to:search_text }"`
	ResourceName  string    `json:"resource_name"  elastic_mapping:"resource_name: { type: keyword,copy_to:search_text }"`
	Title         string    `json:"title"  elastic_mapping:"title: { type: keyword,copy_to:search_text }"`
	Message       string    `json:"message"  elastic_mapping:"content: { type: keyword,copy_to:search_text }"`
	Status        string    `json:"status" elastic_mapping:"status: { type: keyword,copy_to:search_text }"`
	IgnoredTime   time.Time `json:"ignored_time,omitempty"  elastic_mapping:"ignored_time: { type: date }"`
	IgnoredReason string    `json:"ignored_reason,omitempty" elastic_mapping:"ignored_reason: { type: keyword,copy_to:search_text }"`
	IgnoredUser   string    `json:"ignored_user,omitempty" elastic_mapping:"ignored_user: { type: keyword,copy_to:search_text }"`
	Priority      string    `json:"priority" elastic_mapping:"priority: { type: keyword }"`
	SearchText    string    `json:"-" elastic_mapping:"search_text:{type:text,index_prefixes:{},index_phrases:true, analyzer:suggest_text_search }"`
	Category      string    `json:"category,omitempty"  elastic_mapping:"category: { type: keyword,copy_to:search_text }"`
	Tags          []string  `json:"tags,omitempty"  elastic_mapping:"tags: { type: keyword,copy_to:search_text }"`
}

type AlertMetricItem

type AlertMetricItem struct {
	common.MetricItem
	BucketGroups [][]string `json:"bucket_groups,omitempty"`
}

type BucketDiffType added in v1.28.2

type BucketDiffType string

BucketDiffType represents the type of bucket difference

const (
	// BucketDiffTypeSize indicates the difference in bucket size
	BucketDiffTypeSize BucketDiffType = "size"

	// BucketDiffTypeContent indicates the difference in bucket content
	BucketDiffTypeContent BucketDiffType = "content"
)

Constants defining possible bucket difference types

type Channel

type Channel struct {
	orm.ORMObjectBase
	Name       string         `json:"name" elastic_mapping:"name:{type:keyword,copy_to:search_text}"`
	Type       string         `json:"type" elastic_mapping:"type:{type:keyword,copy_to:search_text}"` // email or webhook
	Priority   int            `json:"priority,omitempty"`
	Webhook    *CustomWebhook `json:"webhook,omitempty" elastic_mapping:"webhook:{type:object}"`
	SearchText string         `json:"-" elastic_mapping:"search_text:{type:text,index_prefixes:{},index_phrases:true, analyzer:suggest_text_search }"`
	SubType    string         `json:"sub_type" elastic_mapping:"sub_type:{type:keyword,copy_to:search_text}"`
	Email      *Email         `json:"email,omitempty" elastic_mapping:"email:{type:object}"`
	Enabled    bool           `json:"enabled" elastic_mapping:"enabled:{type:boolean}"`
}

type Condition

type Condition struct {
	Operator string          `json:"operator"`
	Items    []ConditionItem `json:"items"`
}

func (*Condition) GetMaxBucketCount added in v1.28.2

func (cond *Condition) GetMaxBucketCount() int

func (*Condition) GetMinimumPeriodMatch

func (cond *Condition) GetMinimumPeriodMatch() int

type ConditionItem

type ConditionItem struct {
	//MetricName             string `json:"metric"`
	MinimumPeriodMatch int      `json:"minimum_period_match"`
	Operator           string   `json:"operator"`
	Values             []string `json:"values"`
	Priority           string   `json:"priority"`
	Expression         string   `json:"expression,omitempty"`
	//bucket condition type, e.g: size, content
	Type BucketDiffType `json:"type,omitempty"`
	// Represents the number of buckets in the bucket condition type.
	BucketCount int `json:"bucket_count,omitempty"`
}

func (*ConditionItem) GenerateConditionExpression

func (cond *ConditionItem) GenerateConditionExpression() (conditionExpression string, err error)

type ConditionResult

type ConditionResult struct {
	ResultItems []ConditionResultItem `json:"result_items"`
	QueryResult *QueryResult          `json:"query_result"`
}

type ConditionResultItem

type ConditionResultItem struct {
	GroupValues    []string                  `json:"group_values"`
	Groups         []insight.MetricDataGroup `json:"groups"`
	ConditionItem  *ConditionItem            `json:"condition_item"`
	IssueTimestamp interface{}               `json:"issue_timestamp"`
	ResultValue    interface{}               `json:"result_value"` //满足条件最后一个值
	RelationValues map[string]interface{}    `json:"relation_values"`
}

type Context

type Context struct {
	Fields []string `json:"fields"`
}

type Cron

type Cron struct {
	Expression string `json:"expression" elastic_mapping:"expression:{type:text}"`
	Timezone   string `json:"timezone" elastic_mapping:"timezone:{type:keyword}"`
}

type CustomWebhook

type CustomWebhook struct {
	HeaderParams map[string]string `json:"header_params,omitempty" elastic_mapping:"header_params:{type:object,enabled:false}"`
	Method       string            `json:"method" elastic_mapping:"method:{type:keyword}"`
	URL          string            `json:"url,omitempty"`
	Body         string            `json:"body" elastic_mapping:"body:{type:text}"`
}

type Email

type Email struct {
	ServerID   string `json:"server_id" elastic_mapping:"server_id:{type:keyword}"`
	Recipients struct {
		To  []string `json:"to,omitempty" elastic_mapping:"to:{type:keyword}"`
		CC  []string `json:"cc,omitempty" elastic_mapping:"cc:{type:keyword}"`
		BCC []string `json:"bcc,omitempty" elastic_mapping:"bcc:{type:keyword}"`
	} `json:"recipients" elastic_mapping:"recipients:{type:object}"`
	Subject     string `json:"subject" elastic_mapping:"subject:{type:text}"`
	Body        string `json:"body" elastic_mapping:"body:{type:text}"`
	ContentType string `json:"content_type" elastic_mapping:"content_type:{type:keyword}"`
}

type Filter

type Filter struct {
	And []FilterQuery `json:"and,omitempty"`
	Or  []FilterQuery `json:"or,omitempty"`
	Not []FilterQuery `json:"not,omitempty"`
}

func (Filter) IsEmpty

func (f Filter) IsEmpty() bool

type FilterParam

type FilterParam struct {
	Start      interface{} `json:"start"`
	End        interface{} `json:"end"`
	BucketSize string      `json:"bucket_size"`
}

type FilterQuery

type FilterQuery struct {
	Field    string        `json:"field,omitempty"`
	Operator string        `json:"operator,omitempty"`
	Values   []string      `json:"values,omitempty"`
	And      []FilterQuery `json:"and,omitempty"`
	Or       []FilterQuery `json:"or,omitempty"`
	Not      []FilterQuery `json:"not,omitempty"`
}

func (FilterQuery) IsComplex

func (fq FilterQuery) IsComplex() bool

func (FilterQuery) IsEmpty

func (f FilterQuery) IsEmpty() bool

type MessageTemplate

type MessageTemplate struct {
	Type   string `json:"type"`
	Source string `json:"source"`
}

type Metric

type Metric struct {
	insight.Metric
	Title      string `json:"title,omitempty"`                                                                      //text template
	Message    string `json:"message,omitempty"`                                                                    // text template
	Expression string `json:"expression,omitempty" elastic_mapping:"expression:{type:keyword,copy_to:search_text}"` //告警表达式,自动生成 eg: avg(cpu) > 80
}

func (*Metric) GenerateExpression

func (m *Metric) GenerateExpression() (string, error)

type MetricDataItem added in v1.28.2

type MetricDataItem struct {
	insight.MetricDataItem
}

type MetricItem

type MetricItem struct {
	Name      string `json:"name"`
	Field     string `json:"field"`
	Statistic string `json:"statistic"`
}

type NotificationConfig

type NotificationConfig struct {
	Enabled                  bool      `json:"enabled"`
	Title                    string    `json:"title,omitempty"`   //text template
	Message                  string    `json:"message,omitempty"` // text template
	Normal                   []Channel `json:"normal,omitempty"`
	Escalation               []Channel `json:"escalation,omitempty"`
	ThrottlePeriod           string    `json:"throttle_period,omitempty"` //沉默周期
	AcceptTimeRange          TimeRange `json:"accept_time_range,omitempty"`
	EscalationThrottlePeriod string    `json:"escalation_throttle_period,omitempty"`
	EscalationEnabled        bool      `json:"escalation_enabled,omitempty"`
}

type QueryResult

type QueryResult struct {
	Query      string               `json:"query"`
	Raw        string               `json:"raw"`
	MetricData []insight.MetricData `json:"metric_data"`
	Nodata     bool                 `json:"nodata"`
	Min        interface{}          `json:"-"`
	Max        interface{}          `json:"-"`
}

type RecoveryNotificationConfig

type RecoveryNotificationConfig struct {
	Enabled         bool      `json:"enabled"` // channel enabled
	Title           string    `json:"title"`   //text template
	Message         string    `json:"message"` // text template
	AcceptTimeRange TimeRange `json:"accept_time_range,omitempty"`
	Normal          []Channel `json:"normal,omitempty"`
	EventEnabled    bool      `json:"event_enabled"`
}

type Resource

type Resource struct {
	ID        string                 `json:"resource_id" elastic_mapping:"resource_id:{type:keyword}"`
	Name      string                 `json:"resource_name" elastic_mapping:"resource_name:{type:keyword}"`
	Type      string                 `json:"type" elastic_mapping:"type:{type:keyword}"`
	Objects   []string               `json:"objects" elastic_mapping:"objects:{type:keyword,copy_to:search_text}"`
	Filter    FilterQuery            `json:"filter,omitempty" elastic_mapping:"-"`
	RawFilter map[string]interface{} `json:"raw_filter,omitempty" elastic_mapping:"raw_filter:{type:object,enabled:false}"`
	TimeField string                 `json:"time_field,omitempty" elastic_mapping:"id:{type:keyword}"`
	Context   Context                `json:"context"`
}

func (Resource) Validate

func (r Resource) Validate() error

type Rule

type Rule struct {
	ID                         string                      `json:"id,omitempty"      elastic_meta:"_id" elastic_mapping:"id: { type: keyword }"`
	Created                    time.Time                   `json:"created,omitempty" elastic_mapping:"created: { type: date }"`
	Updated                    time.Time                   `json:"updated,omitempty" elastic_mapping:"updated: { type: date }"`
	Name                       string                      `json:"name" elastic_mapping:"name:{type:keyword,copy_to:search_text}"`
	Enabled                    bool                        `json:"enabled" elastic_mapping:"enabled:{type:keyword}"`
	Resource                   Resource                    `json:"resource" elastic_mapping:"resource:{type:object}"`
	Metrics                    Metric                      `json:"metrics" elastic_mapping:"metrics:{type:object}"`
	Conditions                 Condition                   `json:"conditions" elastic_mapping:"conditions:{type:object}"`
	Channels                   *NotificationConfig         `json:"channels,omitempty" elastic_mapping:"channels:{type:object}"`
	NotificationConfig         *NotificationConfig         `json:"notification_config,omitempty" elastic_mapping:"notification_config:{type:object}"`
	RecoveryNotificationConfig *RecoveryNotificationConfig `json:"recovery_notification_config,omitempty" elastic_mapping:"recovery_notification_config:{type:object}"`
	Schedule                   Schedule                    `json:"schedule" elastic_mapping:"schedule:{type:object}"`
	LastNotificationTime       time.Time                   `json:"-" elastic_mapping:"last_notification_time:{type:date}"`
	LastTermStartTime          time.Time                   `json:"-"` //标识最近一轮告警的开始时间
	LastEscalationTime         time.Time                   `json:"-"` //标识最近一次告警升级发送通知的时间
	SearchText                 string                      `json:"-" elastic_mapping:"search_text:{type:text,index_prefixes:{},index_phrases:true, analyzer:suggest_text_search }"`
	Expression                 string                      `json:"-"`
	Creator                    struct {
		Name string `json:"name" elastic_mapping:"name: { type: keyword }"`
		Id   string `json:"id" elastic_mapping:"id: { type: keyword }"`
	} `json:"creator" elastic_mapping:"creator:{type:object}"`
	Category         string     `json:"category,omitempty"  elastic_mapping:"category: { type: keyword,copy_to:search_text }"`
	Tags             []string   `json:"tags,omitempty"  elastic_mapping:"tags: { type: keyword,copy_to:search_text }"`
	BucketConditions *Condition `json:"bucket_conditions" elastic_mapping:"bucket_conditions:{type:object}"`
}

func (*Rule) GetNotificationConfig

func (rule *Rule) GetNotificationConfig() *NotificationConfig

GetNotificationConfig for adapter old version config

func (*Rule) GetNotificationTitleAndMessage

func (rule *Rule) GetNotificationTitleAndMessage() (string, string)

func (*Rule) GetOrInitExpression

func (rule *Rule) GetOrInitExpression() (string, error)

type Schedule

type Schedule struct {
	Cron     *Cron  `json:"cron,omitempty" elastic_mapping:"cron:{type:object}"`
	Interval string `json:"interval,omitempty" elastic_mapping:"interval:{type:keyword}"`
}

type TimeRange

type TimeRange struct {
	Start string `json:"start"`
	End   string `json:"end"`
}

func (*TimeRange) Include

func (tr *TimeRange) Include(t time.Time) bool

Jump to

Keyboard shortcuts

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