common

package
v0.0.0-...-efd361b Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2021 License: GPL-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HashObject

func HashObject(obj interface{}) string

func Join

func Join(strings ...string) string

func Md5SumByte

func Md5SumByte(Byte []byte) (Hash string)

func ToJson

func ToJson(obj interface{}) ([]byte, error)

Types

type AlertCache

type AlertCache struct {
	StartTime   string `json:"StartTime"`   // "1627639497" 秒级时间戳,表示故障开始时间 当AlertStatus为problem时生效 //当无该字段时,或故障未恢复且时间改变时,沿用老时间
	Recoverable string `json:"Recoverable"` // true/false 是否发送恢复通知,若调用方在故障恢复时不调用此接口,则配置为false ,避免因未接收到恢复而导致告警升级
	AlertStatus string `json:"AlertStatus"` // firing/resovled 告警状态,当Recoverable为true时生效,标记当前告警为故障或恢复
}

type AlertInfo

type AlertInfo struct {
	AlertCache
	ObjectData map[string]interface{} `json:"ObjectData"` // 告警对象唯一标识,同一项目下唯一,用于告警抑制,分组,通知策略配置或告警模板定制 例如 {"hostname":"aliyun-blackbox-01","ip":"10.59.63.4","supplier":"ucloud"}
	AlertData  map[string]interface{} `json:"AlertData"`  //  告警事件唯一标识,同一项目下唯一,用于告警抑制,分组,通知策略配置或告警模板定制 例如 {"alertname":"CPU使用率达到90%"}
	NotifyData map[string]interface{} `json:"NotifyData"` // 告警通知字段 当前支持飞书(群组key为groups,值需要服务端提供,个人使用emails或mobiles,飞书关联联系方式) 格式为{"flybook":{"groups":["groupname"],"mobiles":["13917104943"],"emails":["liaopeng@52tt.com"]}}
	Severity   string                 `json:"Severity"`   //告警等级 "disaster/critical/warning"
	EndTime    string                 `json:"EndTime"`    // "1627639497" 秒级时间戳,表示故障恢复时间 当AlertStatus为ok时生效
	AlertText  string                 `json:"AlertText"`  // 告警文本 "HBase_rcmd_core1(10.10.113.160:59100) 内存可用率是6.917% ,  可用内存是 1.615GiB"
	SrcData    map[string]interface{} `json:"SrcData"`    // 原始告警数据 例如 {"alertname":"AggregatedAPIDown","cluster":"prod-bj2-02","env":"production","name":"v1beta1.metrics.k8s.io","namespace":"default","prometheus":"monitoring/prometheus-quicksilver","severity":"warning"}
}

告警信息

type AlertNocache

type AlertNocache struct {
	HandleStatus string `json:"HandleStatus"` // 新告警 (初次告警) 未确认 (确认) 处理中 (恢复) 待关闭 与mongodb状态对应
}

type AlertmanagerAlert

type AlertmanagerAlert struct {
	model.Alert
	// The authoritative timestamp.
	UpdatedAt time.Time
	Timeout   bool
}

alertmanager告警结构体

func (*AlertmanagerAlert) ToCommonAlert

func (e *AlertmanagerAlert) ToCommonAlert(pi *ProjectInfo) *CommonAlert

type AliyunAlert

type AliyunAlert struct {
	AlertName       string `json:"alertName"`
	AlertState      string `json:"alertState"`
	CurValue        string `json:"curValue"`
	Dimensions      string `json:"dimensions"`
	Expression      string `json:"expression"`
	InstanceName    string `json:"instanceName"`
	MetricName      string `json:"metricName"` // cluster.cpu.allocatable
	MetricProject   string `json:"metricProject"`
	Namespace       string `json:"namespace"` // kafka
	PreTriggerLevel string `json:"preTriggerLevel"`
	RuleId          string `json:"ruleId"`
	Timestamp       string `json:"timestamp"`
	TriggerLevel    string `json:"triggerLevel"`
	UserId          string `json:"userId"`
}

func (*AliyunAlert) Severity

func (e *AliyunAlert) Severity() string

func (*AliyunAlert) Status

func (e *AliyunAlert) Status() string

func (*AliyunAlert) ToCommonAlert

func (e *AliyunAlert) ToCommonAlert(pi *ProjectInfo) *CommonAlert

type AppAlert

type AppAlert interface {
	ToCommonAlert() (*CommonAlert, error)
}

type CommonAlert

type CommonAlert struct {
	ProjectInfo
	AlertInfo
	HashInfo
	AlertNocache
}

通用告警结构体

func (*CommonAlert) DumpCache

func (ca *CommonAlert) DumpCache(h *HandleInfo)

func (*CommonAlert) Hash

func (ca *CommonAlert) Hash()

func (*CommonAlert) LoadCache

func (ca *CommonAlert) LoadCache(h HandleInfo)

根据redis缓存,更新告警状态

type EventAlert

type EventAlert struct {
	AlertInfo
}

自定义事件告警结构体,结构与通用结构体一致,避免再次转换

func (*EventAlert) ToCommonAlert

func (e *EventAlert) ToCommonAlert(pi *ProjectInfo) *CommonAlert

仅进行格式转换

type HandleInfo

type HandleInfo struct {
	AlertNocache
	AlertCache
}

redis状态缓存

type HashInfo

type HashInfo struct {
	// contains filtered or unexported fields
}

对象与告警唯一id

func (*HashInfo) GetAlertId

func (h *HashInfo) GetAlertId() string

func (*HashInfo) GetGlobalId

func (h *HashInfo) GetGlobalId() string

func (*HashInfo) GetObjectId

func (h *HashInfo) GetObjectId() string

type HuaweiAlarmValue

type HuaweiAlarmValue struct {
	Time  int     `json:"time"`
	Value float32 `json:"value"`
}

type HuaweiyunAlert

type HuaweiyunAlert struct {
	Message_type        string `json:"message_type"`
	Alarm_id            string `json:"alarm_id"`
	Alarm_name          string `json:"alarm_name"`
	Alarm_status        string `json:"alarm_status"`
	Time                int    `json:"time"`
	Namespace           string `json:"namespace"`
	Metric_name         string `json:"metric_name"`
	Dimension           string `json:"dimension"`
	Period              int    `json:"period"`
	Filter              string `json:"filter"`
	Comparison_operator string `json:"comparison_operator"`

	Value int    `json:"value"`
	Unit  string `json:"unit"`
	Count int    `json:"count"`

	AlarmValue        []HuaweiAlarmValue   `json:"alarmValue"`
	Sms_content       string               `json:"sms_content"`
	Template_variable HuaweiyunTemplateVar `json:"template_variable"`
}

type HuaweiyunMessage

type HuaweiyunMessage struct {
	Signature         string         `json:"signature"`
	Subject           string         `json:"subject"`
	Topic_urn         string         `json:"topic_urn"`
	Message_id        string         `json:"message_id"`
	Signature_version string         `json:"signature_version"`
	Type              string         `json:"type"`
	Message           HuaweiyunAlert `json:"exchanged_message"`
	MessageString     string         `json:"message"`
	// Unsubscribe_url   string         `json:"unsubscribe_url"`  避免误点击,取消该解析
	Signing_cert_url string `json:"signing_cert_url"`
	Timestamp        string `json:"timestamp"`
}

func (*HuaweiyunMessage) Severity

func (h *HuaweiyunMessage) Severity() string

func (*HuaweiyunMessage) Status

func (h *HuaweiyunMessage) Status() string

func (*HuaweiyunMessage) ToCommonAlert

func (h *HuaweiyunMessage) ToCommonAlert(pi *ProjectInfo) *CommonAlert

type HuaweiyunTemplateVar

type HuaweiyunTemplateVar struct {
	Namespace          string            `json:"Namespace"`
	DimensionName      string            `json:"DimensionName"`
	ResourceName       string            `json:"ResourceName"`
	MetricName         string            `json:"MetricName"`
	IsAlarm            bool              `json:"IsAlarm"`
	IsCycleTrigger     bool              `json:"IsCycleTrigger"`
	AlarmLevel         string            `json:"AlarmLevel"`
	Region             string            `json:"Region"`
	ResourceId         string            `json:"ResourceId"`
	PrivateIp          string            `json:"PrivateIp"`
	PublicIp           string            `json:"PublicIp"`
	AlarmRule          string            `json:"AlarmRule"`
	CurrentData        string            `json:"CurrentData"`
	AlarmTime          string            `json:"AlarmTime"`
	DataPoint          map[string]string `json:"DataPoint"`     // {\"2021/09/05 03:10:00 GMT+08:00\":\"91.41%\",\"2021/09/05 03:15:00 GMT+08:00\":\"91.32%\",\"2021/09/05 03:20:00 GMT+08:00\":\"91.46%\"}
	DataPointTime      []string          `json:"DataPointTime"` // [\"2021/09/05 03:20:00 GMT+08:00\",\"2021/09/05 03:15:00 GMT+08:00\",\"2021/09/05 03:10:00 GMT+08:00\"]
	AlarmRuleName      string            `json:"AlarmRuleName"`
	AlarmId            string            `json:"AlarmId"`
	AlarmDesc          string            `json:"AlarmDesc"`
	MonitoringRange    string            `json:"MonitoringRange"`
	IsOriginalValue    bool              `json:"IsOriginalValue"`
	Period             string            `json:"Period"`
	Filter             string            `json:"Filter"`
	ComparisonOperator string            `json:"ComparisonOperator"`
	Value              string            `json:"Value"`
	Unit               string            `json:"Unit"`
	EventContent       string            `json:"EventContent"`
	Count              int               `json:"Count"`
	Link               string            `json:"Link"`
	EpName             string            `json:"EpName"`
	IsIEC              bool              `json:"IsIEC"`
	IsAgentEvent       bool              `json:"IsAgentEvent"`
}

type ParticularAlert

type ParticularAlert interface {
	ToCommonAlert(*ProjectInfo) *CommonAlert
}

type ProjectInfo

type ProjectInfo struct {
	ProjectType string //告警接入类型 Alertmanager,Ucloud,Aliyun,Huaweiyun,Grafana,Callback,Event(自定义事件)
	ProjectId   string //项目ID 用于识别同一告警类型下的不同通道,比如两个不同的prometheus集群,当需要认证时,该值作为认证ID
}

项目信息

func (*ProjectInfo) GetId

func (p *ProjectInfo) GetId() string

func (*ProjectInfo) GetType

func (p *ProjectInfo) GetType() string

func (*ProjectInfo) SetId

func (p *ProjectInfo) SetId(s string)

func (*ProjectInfo) SetType

func (p *ProjectInfo) SetType(s string)

项目相关

type UcloudAlert

type UcloudAlert struct {
	SessionID    string `json:"SessionID"`
	Region       string `json:"Region"`
	ResourceType string `json:"ResourceType"`
	ResourceId   string `json:"ResourceId"`
	MetricName   string `json:"MetricName"`
	AlarmTime    int64  `json:"AlarmTime"`
	Value        int    `json:"value"`
	ValueUnit    string `json:"ValueUnit"`
	RecoveryTime int64  `json:"RecoveryTime"`
	Content      string `json:"content"`
}

func (*UcloudAlert) Status

func (e *UcloudAlert) Status() string

func (*UcloudAlert) ToCommonAlert

func (e *UcloudAlert) ToCommonAlert(pi *ProjectInfo) *CommonAlert

Jump to

Keyboard shortcuts

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