dropbox

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: LGPL-2.1 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CommAlertToFeishuPostTemplateV1

func CommAlertToFeishuPostTemplateV1(alertComm *CommonAlert) *string

func CopyMap

func CopyMap(oldMap map[string]string) (newMap map[string]string)

func ExceptLabel

func ExceptLabel(labelMap map[string]string, cmdbType string) map[string]string

func GetLevel

func GetLevel(level string) string

func GetNow

func GetNow() string

func GetType

func GetType(cmdbtype string) string

func InitCommonAlertTemplate

func InitCommonAlertTemplate()

func InitKeysMap

func InitKeysMap()

func InitTemplate

func InitTemplate()

func KeysMap

func KeysMap(key string) string

func StampStr2Str

func StampStr2Str(ss string) string

func Time2Str

func Time2Str(alertTime time.Time) string

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

告警信息

func (AlertInfo) GetFlybookGroups

func (ai AlertInfo) GetFlybookGroups() []interface{}

type AlertNocache

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

type AlertPostCommApi

type AlertPostCommApi struct {
	Title  string             `json:"title,omitempty"`
	Msg    string             `json:"msg"`
	StarTs string             `json:"startsTs,omitempty"`
	EndTs  string             `json:"endTs,omitempty"`
	Labels template.KV        `json:"labels,omitempty"`
	Values map[string]float64 `json:"values,omitempty"`
}

// KV is a set of key/value string pairs. type KV map[string]string

// Remove returns a copy of the key/value set without the given keys.

func (kv KV) Remove(keys []string) KV {
	keySet := make(map[string]struct{}, len(keys))
	for _, k := range keys {
		keySet[k] = struct{}{}
	}

	res := KV{}
	for k, v := range kv {
		if _, ok := keySet[k]; !ok {
			res[k] = v
		}
	}
	return res
}
func (kv KV) Add(keys map[string]string) KV {
	res := KV{}
	for k, v := range kv {
		res[k] = v
	}
	for k, v := range keys {
		res[k] = v
	}
	return res
}

func PromeAlertToAlertPostCommApi

func PromeAlertToAlertPostCommApi(alert alertTemplate.Alert, zone string) AlertPostCommApi

func (*AlertPostCommApi) ReportCC

func (api *AlertPostCommApi) ReportCC()

type CommonAlert

type CommonAlert struct {
	ProjectInfo
	AlertInfo
	HashInfo
	AlertNocache
}

通用告警结构体

type EventAlert

type EventAlert struct {
	ProjectInfo
	AlertInfo
}

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

type GrafanaEvalMatch

type GrafanaEvalMatch struct {
	Tags   map[string]string `json:"tags,omitempty"`
	Metric string            `json:"metric"`
	Value  float64           `json:"value"`
}

type GrafanaWebhook

type GrafanaWebhook struct {
	Title       string              `json:"title"`
	State       string              `json:"state"`
	Msg         string              `json:"message"`
	EvalMatches []*GrafanaEvalMatch `json:"evalMatches"`
}

func (*GrafanaWebhook) GrafanaWebhookToAlertPostCommApi

func (alert *GrafanaWebhook) GrafanaWebhookToAlertPostCommApi(zone string) []*AlertPostCommApi

type HandleInfo

type HandleInfo struct {
	AlertNocache
	AlertCache
}

redis状态缓存

type HashInfo

type HashInfo struct {
	AlertId  string //告警唯一ID
	ObjectId string //对象唯一ID
	GlobalId string //全局唯一ID alerttype-projectid-severity-alertId-objectId
}

对象与告警唯一id

type ProjectInfo

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

项目信息

type PromeAlerts

type PromeAlerts alertTemplate.Data

func (*PromeAlerts) Firing

func (p *PromeAlerts) Firing(zone string) []AlertPostCommApi

func (*PromeAlerts) Resolved

func (p *PromeAlerts) Resolved(zone string) []AlertPostCommApi

type Report

type Report struct {
	AlertPostCommApi
	Ts         string `json:"ts,omitempty"`
	Access_key string `json:"access_key,omitempty"`
	Random     string `json:"random,omitempty"`
}

func (*Report) SendReportMsg

func (report *Report) SendReportMsg(url string) (string, error)

func (*Report) SendReportMsgByToken

func (report *Report) SendReportMsgByToken(url, token string) (string, error)

Jump to

Keyboard shortcuts

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