Skip to content

Commit

Permalink
fix 时间
Browse files Browse the repository at this point in the history
Signed-off-by: sdvdxl杜龙少 <[email protected]>
  • Loading branch information
sdvdxl committed Jul 26, 2019
1 parent 0e942d6 commit fbb920a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
20 changes: 10 additions & 10 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ type Weixin struct {
}

type AlarmMessage struct {
Level string // 告警等级 P1
Type string // 类型 PROBLEM,OK
Endpoint string // 主机host或者ip
Desc string // 告警描述
Counter string // 告警指标
Tags string // tags
GroupInterval int // 间隔
Count int // 当前告警次数
Time string
Expression string
Level string // 告警等级 P1
Type string // 类型 PROBLEM,OK
Endpoint string // 主机host或者ip
Desc string // 告警描述
Counter string // 告警指标
Tags string // tags
TriggerCount int // 间隔
Count int // 当前告警次数
Time string
Expression string
// 告警时间
}

Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ var (
func main() {

cfg = config.Read()
funcMap := template.FuncMap{"elapse": func(count, reportInterval, postpone int) int {
funcMap := template.FuncMap{"elapse": func(count, reportInterval, triggerCount, postpone int) int {
// 都使用 秒计算
// 超过1次,要计算推迟时间
if count > 1 {
return reportInterval*(count-1) + postpone
return reportInterval*triggerCount + postpone*(count-1)
}

// 第一次,直接返回上报间隔
return reportInterval
return reportInterval * triggerCount
}, "divide": func(a, b int) int { return a / b },
"timeFormat": func(t time.Time, format string) string { return t.Format(format) }}

Expand Down
2 changes: 1 addition & 1 deletion message-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
- 告警主机: {{.Endpoint}}
- 告警时间: {{.Time}}
- 当前次数: {{.Count}}
- 告警说明: {{.Desc}}
- 告警说明: {{.Desc}},已持续 {{with elapse .Count 60 .TriggerCount 300}}{{divide . 60}}{{end}}分钟
6 changes: 3 additions & 3 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func HandleContent(content string) (*config.AlarmMessage, error) {
desc := argStr[:pos-1] // 去掉最后一个空格

// 提取表达式内的时间间隔
groupInterval, err := strconv.Atoi(p.FindStringSubmatch(expression)[1])
triggerCount, err := strconv.Atoi(p.FindStringSubmatch(expression)[1])
if err != nil {
return nil, err
}
Expand All @@ -73,6 +73,6 @@ func HandleContent(content string) (*config.AlarmMessage, error) {
return nil, err
}
time := strings.Join(subArgs[1:], " ")
return &config.AlarmMessage{Level: args[0], Type: args[1], Endpoint: args[2],Expression:expression,
Desc: desc, Counter: counter, Tags: tags, GroupInterval: groupInterval, Count: count, Time: time}, nil
return &config.AlarmMessage{Level: args[0], Type: args[1], Endpoint: args[2], Expression: expression,
Desc: desc, Counter: counter, Tags: tags, TriggerCount: triggerCount, Count: count, Time: time}, nil
}

0 comments on commit fbb920a

Please sign in to comment.