alert

package
v0.0.0-...-aa2b1f7 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Copyright 2024 CloudDetail SPDX-License-Identifier: Apache-2.0

Copyright 2024 CloudDetail SPDX-License-Identifier: Apache-2.0

Index

Constants

View Source
const (
	JSONType       string = "json"
	PrometheusType string = "prometheus"
	ZabbixType     string = "zabbix"

	DatadogType   string = "datadog"
	PagerDutyType string = "pagerduty"
)
View Source
const (
	StatusFiring   = "firing"
	StatusResolved = "resolved"
)
View Source
const (
	SeverityCriticalLevel = "critical"
	SeverityErrorLevel    = "error"
	SeverityWarnLevel     = "warning"
	SeverityInfoLevel     = "info"
	SeverityUnknownLevel  = "unknown"
)
View Source
const (
	ZabbixSeverityDisaster = "Disaster"
	ZabbixSeverityHigh     = "High"
	ZabbixSeverityAverage  = "Average"
	ZabbixSeverityWarning  = "Warning"
	ZabbixSeverityInfo     = "Information"
	ZabbixSeverityUnknown  = "Not classified"
)
View Source
const (
	ZabbixStatusOK      = "OK"
	ZabbixStatusProblem = "PROBLEM"
)
View Source
const ApoVMAlertSourceID = "efc91f08-86c4-3696-aba8-570d4a8dc069"

ApoVMAlertSourceID is the default alert source id of 'APO-VM-ALERT' Comes from `uuid.NewMD5(uuid.UUID{}, []byte("APO-VM-ALERT")).String()`

Variables

This section is empty.

Functions

func ConvertSeverity

func ConvertSeverity(sourceType string, severity string) string

func ConvertStatus

func ConvertStatus(sourceType string, status string) string

func FastAlertID

func FastAlertID(alertName string, tags map[string]any) string

calculate AlertID based on alertName and raw_tag

func FastAlertIDByStringMap

func FastAlertIDByStringMap(alertName string, tags map[string]string) string

Types

type AEventWithWRecord

type AEventWithWRecord struct {
	AlertEvent

	LastStatus string `json:"lastStatus,omitempty" ch:"last_status"`

	WorkflowDetail
	NotifyDetail
}

AlertEvent With Workflow record

type Alert

type Alert struct {
	Source   string `json:"source,omitempty" ch:"source"`
	SourceID string `json:"sourceId,omitempty" ch:"source_id"`

	AlertID string `json:"alertId" ch:"alert_id"`
	Group   string `ch:"group" json:"group,omitempty"`
	Name    string `ch:"name" json:"name,omitempty"`

	EnrichTags map[string]string `json:"tags" ch:"tags" mapstructure:"enrich_tags"`

	EnrichTagsDisplay []TagDisplay `json:"tagsDisplay" ch:"-" mapstructure:"-"`
	// HACK the existing clickhouse query uses `tags` as the filter field
	// so enrichTags in ch is named as 'tags' to filter new alertInput
	Tags RawTags `json:"rawTags" ch:"raw_tags" mapstructure:"tags"`
}

Each alert has a unique alertId, and usually contains multi events

func (*Alert) GetContainerIDTag

func (a *Alert) GetContainerIDTag() string

func (*Alert) GetContainerTag

func (a *Alert) GetContainerTag() string

func (*Alert) GetDatabaseIP

func (a *Alert) GetDatabaseIP() string

func (*Alert) GetDatabasePort

func (a *Alert) GetDatabasePort() string

func (*Alert) GetDatabaseURL

func (a *Alert) GetDatabaseURL() string

func (*Alert) GetEndpointTag

func (a *Alert) GetEndpointTag() string

func (*Alert) GetInfraNodeTag

func (a *Alert) GetInfraNodeTag() string

func (*Alert) GetK8sNamespaceTag

func (a *Alert) GetK8sNamespaceTag() string

func (*Alert) GetK8sPodTag

func (a *Alert) GetK8sPodTag() string

func (*Alert) GetLevelTag

func (a *Alert) GetLevelTag() string

GetLevelTag 获取级别,当前只有network告警存在

func (*Alert) GetNetDstIPTag

func (a *Alert) GetNetDstIPTag() string

func (*Alert) GetNetSrcIPTag

func (a *Alert) GetNetSrcIPTag() string

func (*Alert) GetNetSrcNodeTag

func (a *Alert) GetNetSrcNodeTag() string

func (*Alert) GetNetSrcPidTag

func (a *Alert) GetNetSrcPidTag() string

func (*Alert) GetNetSrcPodTag

func (a *Alert) GetNetSrcPodTag() string

func (*Alert) GetPidTag

func (a *Alert) GetPidTag() string

func (*Alert) GetServiceNameTag

func (a *Alert) GetServiceNameTag() string

func (*Alert) GetStringTagWithRaw

func (a *Alert) GetStringTagWithRaw(key string) string

func (*Alert) GetTargetObj

func (a *Alert) GetTargetObj() string

type AlertAnalyzeWorkflowParams

type AlertAnalyzeWorkflowParams struct {
	Node      string `json:"node,omitempty"`
	Namespace string `json:"namespace,omitempty"`
	Pod       string `json:"pod,omitempty"`
	Service   string `json:"service,omitempty"`
	Endpoint  string `json:"endpoint,omitempty"`
	Pid       string `json:"pid,omitempty"`
	AlertName string `json:"alertName,omitempty"`

	Detail      string `json:"detail,omitempty"`
	ContainerID string `json:"containerId,omitempty"`

	Tags         map[string]string `json:"tags,omitempty"`
	RawTags      map[string]any    `json:"raw_tags,omitempty"`
	AlertEventId string            `json:"alertEventId,omitempty"`
}

type AlertEnrichCondition

type AlertEnrichCondition struct {
	EnrichRuleID string `json:"-" gorm:"type:varchar(255);column:enrich_rule_id;index"`
	SourceID     string `json:"-" gorm:"type:varchar(255);column:source_id;index"`

	FromField string `json:"fromField" gorm:"type:varchar(255);column:from_field"`
	Operation string `json:"operation" gorm:"type:varchar(255);column:operation"` // support match,not match,gt,lt,ge,le,eq
	Expr      string `json:"expr" gorm:"type:varchar(255);column:expr"`
}

type AlertEnrichRule

type AlertEnrichRule struct {
	EnrichRuleID string `json:"enrichRuleId" gorm:"primaryKey;type:varchar(255);column:enrich_rule_id"`

	SourceID  string `json:"sourceId" gorm:"type:varchar(255);column:source_id"`
	RType     string `json:"rType" gorm:"type:varchar(255);column:r_type"`
	RuleOrder int    `json:"-" gorm:"type:int;column:rule_order"`

	FromField string `json:"fromField" gorm:"type:varchar(255);column:from_field"`
	FromRegex string `json:"fromRegex" gorm:"type:varchar(255);column:from_regex"`

	// ---------------- tagMapping -----------------
	TargetTagId int    `json:"targetTagId" gorm:"type:int;column:target_tag_id"`
	CustomTag   string `json:"customTag" gorm:"type:varchar(255);column:custom_tag"`

	// ---------------- schemaMapping --------------
	Schema       string `json:"schema,omitempty" gorm:"type:varchar(255);column:schema"`
	SchemaSource string `json:"schemaSource,omitempty" gorm:"type:varchar(255);column:schema_source"`
}

func (AlertEnrichRule) TableName

func (AlertEnrichRule) TableName() string

type AlertEnrichRuleConfigRequest

type AlertEnrichRuleConfigRequest struct {
	SourceId          string              `json:"sourceId"`
	EnrichRuleConfigs []AlertEnrichRuleVO `json:"enrichRuleConfigs"`

	SetAsDefault bool `json:"setAsDefault,omitempty"`
}

type AlertEnrichRuleVO

type AlertEnrichRuleVO struct {
	AlertEnrichRule

	// --------------- conditions ----------------
	Conditions []AlertEnrichCondition `json:"conditions" gorm:"type:varchar(255);column:conditions"`

	// --------------- schemaMapping -------------
	SchemaTargets []AlertEnrichSchemaTarget `json:"schemaTargets" gorm:"type:varchar(255);column:schema_targets"`
}

type AlertEnrichSchemaTarget

type AlertEnrichSchemaTarget struct {
	SourceID     string `json:"-" gorm:"type:varchar(255);column:source_id;index"`
	EnrichRuleID string `json:"-" gorm:"type:varchar(255);column:enrich_rule_id;index"`

	SchemaField string `json:"schemaField" gorm:"type:varchar(255);column:schema_field"`
	TargetTagID int    `json:"targetTagId" gorm:"type:int;column:target_tag_id"`
	CustomTag   string `json:"customTag" gorm:"type:varchar(255);column:custom_tag"`
}

type AlertEvent

type AlertEvent struct {
	Alert `mapstructure:",squash"`

	// Deprecated: use @EventID instead
	ID      uuid.UUID `json:"-" ch:"id"`
	EventID string    `json:"id" ch:"event_id"`

	Detail string `json:"detail" ch:"detail" mapstructure:"detail"`

	CreateTime   time.Time `json:"createTime" ch:"create_time" mapstructure:"createTime"`
	UpdateTime   time.Time `json:"updateTime" ch:"update_time" mapstructure:"updateTime"`
	EndTime      time.Time `json:"endTime" ch:"end_time" mapstructure:"endTime"`
	ReceivedTime time.Time `json:"receivedTime" ch:"received_time"  mapstructure:"receivedTime"`

	Severity string `json:"severity" ch:"severity" mapstructure:"severity"`
	Status   string `json:"status" ch:"status" mapstructure:"status"`
}

func (*AlertEvent) TagsInStr

func (e *AlertEvent) TagsInStr() string

func (*AlertEvent) ToAMAlert

func (e *AlertEvent) ToAMAlert(externalURL string, timeout bool) *types.Alert

type AlertEventFilter

type AlertEventFilter struct {
	Source       string
	Group        string
	Name         string
	EventID      string
	Severity     string
	Status       string
	WithMutation bool

	GroupIDs []string

	*AlertTagsFilter
}

type AlertSchemaRequest

type AlertSchemaRequest struct {
	Schema string `json:"schema" form:"schema"`
}

type AlertSource

type AlertSource struct {
	SourceFrom
	Clusters []integration.Cluster `json:"clusters" gorm:"-"`

	Params integration.JSONField[AlertSourceParams] `json:"params" gorm:"type:varchar(2000);column:params;default:'{}'"`

	EnabledPull    bool  `json:"enabledPull" gorm:"type:bool;column:enabled_pull;default:false"`
	LastPullMillTS int64 `json:"lastPullMillTS" gorm:"type:bigint;column:last_pull_mill_ts;default:0"`
}

func (AlertSource) TableName

func (AlertSource) TableName() string

type AlertSource2Cluster

type AlertSource2Cluster struct {
	SourceID  string `gorm:"type:varchar(255);column:source_id"`
	ClusterID string `gorm:"type:varchar(255);column:cluster_id"`
}

type AlertSourceParams

type AlertSourceParams map[string]any

func (AlertSourceParams) GetBool

func (p AlertSourceParams) GetBool(key string) bool

func (AlertSourceParams) GetInt

func (p AlertSourceParams) GetInt(key string) int

func (AlertSourceParams) GetString

func (p AlertSourceParams) GetString(key string) string

type AlertTagsFilter

type AlertTagsFilter struct {
	ServiceEndpoints []model.EndpointKey
	model.RelatedInstances
}

TagsFilter using field:tags to filter alert Use OR to connect different conditions

type AlertWithEventCount

type AlertWithEventCount struct {
	Alert

	Count uint64 `json:"count" ch:"count"`
}

type CheckSchemaIsUsedReponse

type CheckSchemaIsUsedReponse struct {
	IsUsing          bool     `json:"isUsing"`
	AlertSourceNames []string `json:"alertSourceNames"`
}

type CreateSchemaRequest

type CreateSchemaRequest struct {
	Schema  string   `json:"schema"`
	Columns []string `json:"columns"`

	FullRows [][]string `json:"fullRows"`
}

type DefaultAlertEnrichRuleRequest

type DefaultAlertEnrichRuleRequest struct {
	SourceType string `json:"sourceType" form:"sourceType"`
}

type DefaultAlertEnrichRuleResponse

type DefaultAlertEnrichRuleResponse struct {
	SourceType        string              `json:"sourceType"`
	EnrichRuleConfigs []AlertEnrichRuleVO `json:"enrichRuleConfigs"`
}

type ErrAlertImpactMissingTag

type ErrAlertImpactMissingTag struct {
	TagGroups []TagGroup
	Event     *Alert
}

func (*ErrAlertImpactMissingTag) AddCheckedGroup

func (e *ErrAlertImpactMissingTag) AddCheckedGroup(err ErrAlertImpactMissingTag)

func (ErrAlertImpactMissingTag) CheckedTagGroups

func (e ErrAlertImpactMissingTag) CheckedTagGroups() string

func (ErrAlertImpactMissingTag) Error

func (e ErrAlertImpactMissingTag) Error() string

type ErrAlertImpactNoMatchedService

type ErrAlertImpactNoMatchedService struct {
	TagGroup  TagGroup
	TagValues []string
}

func (ErrAlertImpactNoMatchedService) CheckedTagGroup

func (e ErrAlertImpactNoMatchedService) CheckedTagGroup() string

func (ErrAlertImpactNoMatchedService) Error

type ErrAlertImpactNotFit

type ErrAlertImpactNotFit struct {
	TagGroup
	Group string
}

func (ErrAlertImpactNotFit) Error

func (e ErrAlertImpactNotFit) Error() string

type ErrAlertSourceAlreadyExist

type ErrAlertSourceAlreadyExist struct {
	Name string
}

func (ErrAlertSourceAlreadyExist) Error

type ErrAlertSourceNotExist

type ErrAlertSourceNotExist struct{}

func (ErrAlertSourceNotExist) Error

func (e ErrAlertSourceNotExist) Error() string

type ErrIllegalAlertRule

type ErrIllegalAlertRule struct {
	Err error
}

func (ErrIllegalAlertRule) Error

func (e ErrIllegalAlertRule) Error() string

type ErrMutationCheckFailed

type ErrMutationCheckFailed struct {
	PQL        string
	UpperLimit string
	LowerLimit string
	UserMsg    string
	Err        error
}

func (ErrMutationCheckFailed) Error

func (e ErrMutationCheckFailed) Error() string

func (ErrMutationCheckFailed) Msg

type ErrNotAllowSchema

type ErrNotAllowSchema struct {
	Table  string
	Column string
}

func (ErrNotAllowSchema) Error

func (e ErrNotAllowSchema) Error() string

type GetAlertEnrichRuleResponse

type GetAlertEnrichRuleResponse struct {
	SourceId          string              `json:"sourceId"`
	EnrichRuleConfigs []AlertEnrichRuleVO `json:"enrichRuleConfigs"`
}

type GetSchemaColumnsResponse

type GetSchemaColumnsResponse struct {
	Columns []string `json:"columns"`
}

type GetSchemaDataReponse

type GetSchemaDataReponse struct {
	Columns []string           `json:"columns"`
	Rows    map[int64][]string `json:"rows"`
}

type GetTargetTagsResponse

type GetTargetTagsResponse struct {
	TargetTags []TargetTag `json:"targetTags"`
}

type ListAlertSourceResponse

type ListAlertSourceResponse struct {
	AlertSources []AlertSource `json:"alertSources"`
}

type ListSchemaResponse

type ListSchemaResponse struct {
	Schemas []string `json:"schemas"`
}

type ListSchemaWithColumnsResponse

type ListSchemaWithColumnsResponse struct {
	Schemas map[string][]string `json:"schemas"`
}

type NotifyDetail

type NotifyDetail struct {
	SendSuccess string    `json:"notifySuccess" ch:"notify_success"`
	SendFailed  string    `json:"notifyFailed" ch:"notify_failed"`
	NotifyAt    time.Time `json:"notifyAt" ch:"notify_at"`
}

type RawTags

type RawTags map[string]any

func (*RawTags) Get

func (t *RawTags) Get(key any) (any, bool)

Impl clickhouse OrderedMap interface to accept map[string]string

func (*RawTags) Keys

func (t *RawTags) Keys() <-chan any

func (*RawTags) Put

func (t *RawTags) Put(key any, value any)

type SetDefaultAlertEnrichRuleRequest

type SetDefaultAlertEnrichRuleRequest struct {
	SourceType        string              `json:"sourceType"`
	EnrichRuleConfigs []AlertEnrichRuleVO `json:"enrichRuleConfigs"`
}

type SourceFrom

type SourceFrom struct {
	SourceID string `form:"sourceId" json:"sourceId" gorm:"primaryKey;type:varchar(255);column:source_id"`
	SourceInfo
}

type SourceInfo

type SourceInfo struct {
	SourceName string `form:"sourceName" json:"sourceName" gorm:"unique;type:varchar(255);column:source_name"`
	SourceType string `form:"sourceType" json:"sourceType" gorm:"type:varchar(255);column:source_type"`
}

type TagDisplay

type TagDisplay struct {
	Key   string `json:"key"`
	Name  string `json:"name"`
	Value string `json:"value"`
}

type TagGroup

type TagGroup []string

type TargetTag

type TargetTag struct {
	ID         uint   `gorm:"primaryKey;autoIncrement" json:"id"`
	TagName    string `gorm:"type:varchar(255);column:tag_name" json:"tagName"`
	TagNameEN  string `gorm:"type:varchar(255);column:tag_name_en" json:"-"`
	Describe   string `gorm:"type:varchar(255);column:describe" json:"describe"`
	DescribeEN string `gorm:"type:varchar(255);column:describe_en" json:"-"`
	Field      string `gorm:"type:varchar(255);column:field" json:"targetTag"`
}

func (TargetTag) TableName

func (TargetTag) TableName() string

type UpdateSchemaDataRequest

type UpdateSchemaDataRequest struct {
	Schema  string   `json:"schema"`
	Columns []string `json:"columns"`

	ClearAll bool `json:"clearAll"`

	NewRows    [][]string       `json:"newRows"`
	UpdateRows map[int][]string `json:"updateRows"`
}

type WorkflowDetail

type WorkflowDetail struct {
	WorkflowRunID string `json:"workflowRunId" ch:"workflow_run_id"`

	WorkflowID   string `json:"workflowId" ch:"workflow_id"`
	WorkflowName string `json:"workflowName" ch:"workflow_name"`

	Validity    string    `json:"validity" ch:"validity"`
	Input       string    `json:"input" ch:"input"`
	Output      string    `json:"output" ch:"output"`
	RoundedTime time.Time `json:"-" ch:"rounded_time"`
	Importance  uint8     `json:"-" ch:"importance"`
	LastCheckAt time.Time `json:"lastCheckAt" ch:"last_check_at"`

	Duration string `json:"duration" ch:"-"`

	WorkflowParams WorkflowParams `json:"workflowParams"`

	// Deprecated: use [Validity] instead, will remove after 1.7.x
	IsValid string `json:"isValid" ch:"is_valid"`

	AlertDirection string `json:"alertDirection" ch:"alert_direction"`
	AnalyzeRunID   string `json:"analyzeRunId" ch:"analyze_run_id"`
	AnalyzeErr     string `json:"analyzeErr" ch:"analyze_err"`
}

FIXME add importance field

type WorkflowParams

type WorkflowParams struct {
	StartTime int64 `json:"startTime" form:"startTime"`
	EndTime   int64 `json:"endTime" form:"endTime"`

	NodeName string `json:"nodeName" form:"nodeName"`
	NodeIp   string `json:"nodeIp" form:"nodeIp"`

	Params  string `json:"params"`
	Edition string `json:"edition"`
}

Jump to

Keyboard shortcuts

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