fix: and conditions alert recovery
This commit is contained in:
parent
428ce391f9
commit
d39b4af421
|
@ -58,10 +58,10 @@ func ToJudge(historyMap *cache.JudgeItemMap, key string, val *dataobj.JudgeItem,
|
||||||
}
|
}
|
||||||
history := []dataobj.History{}
|
history := []dataobj.History{}
|
||||||
|
|
||||||
Judge(stra, stra.Exprs, historyData, val, now, history, "", "")
|
Judge(stra, stra.Exprs, historyData, val, now, history, "", "", []bool{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func Judge(stra *model.Stra, exps []model.Exp, historyData []*dataobj.RRDData, firstItem *dataobj.JudgeItem, now int64, history []dataobj.History, info string, value string) {
|
func Judge(stra *model.Stra, exps []model.Exp, historyData []*dataobj.RRDData, firstItem *dataobj.JudgeItem, now int64, history []dataobj.History, info string, value string, status []bool) {
|
||||||
stats.Counter.Set("running", 1)
|
stats.Counter.Set("running", 1)
|
||||||
|
|
||||||
if len(exps) < 1 {
|
if len(exps) < 1 {
|
||||||
|
@ -105,7 +105,7 @@ func Judge(stra *model.Stra, exps []model.Exp, historyData []*dataobj.RRDData, f
|
||||||
Hashid: getHashId(stra.Id, firstItem),
|
Hashid: getHashId(stra.Id, firstItem),
|
||||||
}
|
}
|
||||||
|
|
||||||
sendEventIfNeed(historyData, isTriggered, event)
|
sendEventIfNeed(historyData, status, event)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
@ -115,10 +115,7 @@ func Judge(stra *model.Stra, exps []model.Exp, historyData []*dataobj.RRDData, f
|
||||||
} else {
|
} else {
|
||||||
value += fmt.Sprintf("; %s: %v", exp.Metric, leftValue)
|
value += fmt.Sprintf("; %s: %v", exp.Metric, leftValue)
|
||||||
}
|
}
|
||||||
|
status = append(status, isTriggered)
|
||||||
if !isTriggered {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
//与条件情况下执行
|
//与条件情况下执行
|
||||||
if len(exps) > 1 {
|
if len(exps) > 1 {
|
||||||
|
@ -133,7 +130,7 @@ func Judge(stra *model.Stra, exps []model.Exp, historyData []*dataobj.RRDData, f
|
||||||
Tags: "",
|
Tags: "",
|
||||||
DsType: "GAUGE",
|
DsType: "GAUGE",
|
||||||
}
|
}
|
||||||
Judge(stra, exps[1:], []*dataobj.RRDData{}, judgeItem, now, history, info, value)
|
Judge(stra, exps[1:], []*dataobj.RRDData{}, judgeItem, now, history, info, value, status)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,7 +138,7 @@ func Judge(stra *model.Stra, exps []model.Exp, historyData []*dataobj.RRDData, f
|
||||||
firstItem.Endpoint = respData[i].Endpoint
|
firstItem.Endpoint = respData[i].Endpoint
|
||||||
firstItem.Tags = getTags(respData[i].Counter)
|
firstItem.Tags = getTags(respData[i].Counter)
|
||||||
firstItem.Step = respData[i].Step
|
firstItem.Step = respData[i].Step
|
||||||
Judge(stra, exps[1:], respData[i].Values, firstItem, now, history, info, value)
|
Judge(stra, exps[1:], respData[i].Values, firstItem, now, history, info, value, status)
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -160,7 +157,7 @@ func Judge(stra *model.Stra, exps []model.Exp, historyData []*dataobj.RRDData, f
|
||||||
firstItem.Endpoint = respData[i].Endpoint
|
firstItem.Endpoint = respData[i].Endpoint
|
||||||
firstItem.Tags = getTags(respData[i].Counter)
|
firstItem.Tags = getTags(respData[i].Counter)
|
||||||
firstItem.Step = respData[i].Step
|
firstItem.Step = respData[i].Step
|
||||||
Judge(stra, exps[1:], respData[i].Values, firstItem, now, history, info, value)
|
Judge(stra, exps[1:], respData[i].Values, firstItem, now, history, info, value, status)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -387,7 +384,12 @@ func GetReqs(stra *model.Stra, metric string, endpoints []string, now int64) ([]
|
||||||
return reqs, nil
|
return reqs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendEventIfNeed(historyData []*dataobj.RRDData, isTriggered bool, event *dataobj.Event) {
|
func sendEventIfNeed(historyData []*dataobj.RRDData, status []bool, event *dataobj.Event) {
|
||||||
|
isTriggered := true
|
||||||
|
for _, s := range status {
|
||||||
|
isTriggered = isTriggered && s
|
||||||
|
}
|
||||||
|
|
||||||
lastEvent, exists := cache.LastEvents.Get(event.ID)
|
lastEvent, exists := cache.LastEvents.Get(event.ID)
|
||||||
if isTriggered {
|
if isTriggered {
|
||||||
event.EventType = EVENT_ALERT
|
event.EventType = EVENT_ALERT
|
||||||
|
|
|
@ -49,10 +49,10 @@ func nodataJudge() {
|
||||||
}
|
}
|
||||||
|
|
||||||
nodataJob.Acquire()
|
nodataJob.Acquire()
|
||||||
go func(stra *model.Stra, exps []model.Exp, historyData []*dataobj.RRDData, firstItem *dataobj.JudgeItem, now int64, history []dataobj.History, info string, value string) {
|
go func(stra *model.Stra, exps []model.Exp, historyData []*dataobj.RRDData, firstItem *dataobj.JudgeItem, now int64, history []dataobj.History, info string, value string, status []bool) {
|
||||||
defer nodataJob.Release()
|
defer nodataJob.Release()
|
||||||
Judge(stra, exps, historyData, firstItem, now, history, info, value)
|
Judge(stra, exps, historyData, firstItem, now, history, info, value, status)
|
||||||
}(stra, stra.Exprs, []*dataobj.RRDData{}, judgeItem, now, []dataobj.History{}, "", "")
|
}(stra, stra.Exprs, []*dataobj.RRDData{}, judgeItem, now, []dataobj.History{}, "", "", []bool{})
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -79,10 +79,10 @@ func nodataJudge() {
|
||||||
}
|
}
|
||||||
|
|
||||||
nodataJob.Acquire()
|
nodataJob.Acquire()
|
||||||
go func(stra *model.Stra, exps []model.Exp, historyData []*dataobj.RRDData, firstItem *dataobj.JudgeItem, now int64, history []dataobj.History, info string, value string) {
|
go func(stra *model.Stra, exps []model.Exp, historyData []*dataobj.RRDData, firstItem *dataobj.JudgeItem, now int64, history []dataobj.History, info string, value string, status []bool) {
|
||||||
defer nodataJob.Release()
|
defer nodataJob.Release()
|
||||||
Judge(stra, exps, historyData, firstItem, now, history, info, value)
|
Judge(stra, exps, historyData, firstItem, now, history, info, value, status)
|
||||||
}(stra, stra.Exprs, data.Values, judgeItem, now, []dataobj.History{}, "", "")
|
}(stra, stra.Exprs, data.Values, judgeItem, now, []dataobj.History{}, "", "", []bool{})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue