common

package
v0.0.0-...-b9dc9a6 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2020 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AlertMethodSms      = "SMS"
	AlertMethodLanxin   = "LANXIN"
	AlertMethodCall     = "CALL"
	AlertMethodHook     = "HOOK"
	AlertMethodDingTalk = "DINGTALK"
)

Variables

View Source
var ErrHttpRequest = errors.New("create HTTP request failed")
View Source
var Maintain map[string]bool
View Source
var Recover2Send = map[string]map[[2]int64]*Ready2Send{
	AlertMethodLanxin: {},
}
View Source
var RuleCount map[[2]int64]int64

Functions

func CalculateReversePolishNotation

func CalculateReversePolishNotation(labelmap map[string]string, expression string) bool

func Converse2ReversePolishNotation

func Converse2ReversePolishNotation(root *Node) string

func GenerateJsonHeader

func GenerateJsonHeader() map[string]string

func HttpGet

func HttpGet(url string, params map[string]string, headers map[string]string) (*http.Response, error)

func HttpPost

func HttpPost(url string, params map[string]string, headers map[string]string, body []byte) (*http.Response, error)

func IsValid

func IsValid(s string) bool

func PostorderTraversal

func PostorderTraversal(root *Node, list *[]string)

func UpdateRecovery2Send

func UpdateRecovery2Send(ug UserGroup, alert Alert, users []string, alertId int64, alertCount int, hostname string)

Types

type Alert

type Alert struct {
	ActiveAt    time.Time `json:"active_at"`
	Annotations struct {
		Description string `json:"description"`
		Summary     string `json:"summary"`
		RuleId      string `json:"rule_id"`
	} `json:"annotations"`
	FiredAt    time.Time         `json:"fired_at"`
	Labels     map[string]string `json:"labels"`
	LastSentAt time.Time         `json:"last_sent_at"`
	ResolvedAt time.Time         `json:"resolved_at"`
	State      int               `json:"state"`
	ValidUntil time.Time         `json:"valid_until"`
	Value      float64           `json:"value"`
}

type AlertForShow

type AlertForShow struct {
	Id              int64             `json:"id,omitempty"`
	RuleId          int64             `json:"rule_id"`
	Labels          map[string]string `json:"labels"`
	Value           float64           `json:"value"`
	Count           int               `json:"count"`
	Status          int8              `json:"status"`
	Summary         string            `json:"summary"`
	Description     string            `json:"description"`
	ConfirmedBy     string            `json:"confirmed_by"`
	FiredAt         *time.Time        `json:"fired_at"`
	ConfirmedAt     *time.Time        `json:"confirmed_at"`
	ConfirmedBefore *time.Time        `json:"confirmed_before"`
	ResolvedAt      *time.Time        `json:"resolved_at"`
}

type Alerts

type Alerts []Alert

type AuthModel

type AuthModel struct {
	Username string
	Password string
}

AuthModel holds information used to authenticate.

type BrokenList

type BrokenList struct {
	Hosts []struct {
		Hostname string `json:"hostname"`
	} `json:"hosts"`
	Error interface{} `json:"error"`
}

type Confirm

type Confirm struct {
	Duration int
	User     string
	Ids      []int
}

type Msg

type Msg struct {
	Content string   `json:"content"`
	From    string   `json:"from"`
	Title   string   `json:"title"`
	To      []string `json:"to"`
}

type Node

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

func BuildTree

func BuildTree(expression string) (n *Node, e error)

type Ready2Send

type Ready2Send struct {
	RuleId int64    //告警id
	Start  int64    //
	User   []string // 告警人员列表
	Alerts []SingleAlert
}

type Res

type Res struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data,omitempty"`
}

type SingleAlert

type SingleAlert struct {
	Id       int64             `json:"id"`    //告警id
	Count    int               `json:"count"` //告警异常分钟数
	Value    float64           `json:"value"` // 当前告警值
	Summary  string            `json:"summary"`
	Hostname string            `json:"hostname"` // 故障主机名,如果有设置的话。
	Labels   map[string]string `json:"labels"`
}

type UserGroup

type UserGroup struct {
	Id                    int64
	StartTime             string
	EndTime               string
	Start                 int
	Period                int
	ReversePolishNotation string
	User                  string
	Group                 string
	DutyGroup             string
	Method                string
}

func (UserGroup) IsOnDuty

func (u UserGroup) IsOnDuty() bool

IsOnDuty return if current UserGroup is on duty or not by StartTime & EndTime. If the UserGroup is not on duty, alerts should not be sent to them.

func (UserGroup) IsValid

func (u UserGroup) IsValid() bool

Check if UserGroup is valid.

type ValidUserGroup

type ValidUserGroup struct {
	User      string
	Group     string
	DutyGroup string
}

Jump to

Keyboard shortcuts

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