fix(monitor): modify nodata feishu notifyinfo; fix send email err

1.修改nodata报警消息内容
2.修复发送邮件数量异常的bug
This commit is contained in:
zhaoxiangchun
2021-01-29 13:05:24 +08:00
parent b2e00a8adb
commit e2a5addc2f
3 changed files with 19 additions and 19 deletions
@@ -209,11 +209,10 @@ func (c *NoDataQueryCondition) NewNoDataEvalMatch(context *alerting.EvalContext,
queryKeyInfo = evalMatch.Metric
}
evalMatch.Unit = alertDetails.FieldDescription.Unit
msg := fmt.Sprintf("%s.%s %s %s", alertDetails.Measurement, alertDetails.Field,
alertDetails.Comparator, alerting.RationalizeValueFromUnit(alertDetails.Threshold, evalMatch.Unit, ""))
if len(context.Rule.Message) == 0 {
context.Rule.Message = msg
}
msg := fmt.Sprintf("%s.%s %s ", alertDetails.Measurement, alertDetails.Field,
alertDetails.Comparator)
context.Rule.Message = msg
//evalMatch.Condition = c.GenerateFormatCond(meta, queryKeyInfo).String()
evalMatch.ValueStr = NO_DATA
return evalMatch, nil
+2 -2
View File
@@ -336,7 +336,7 @@ type sendnotifyBase struct {
}
func (s *sendnotifyBase) send() error {
notifyclient.RawNotifyWithCtx(s.Ctx, s.Setting.UserIds, false, notify.TNotifyChannel(s.Setting.Channel),
notifyclient.RawNotifyWithCtx(s.Ctx, s.msg.Uid, false, notify.TNotifyChannel(s.Setting.Channel),
notify.TNotifyPriority(s.msg.Priority),
"DEFAULT",
jsonutils.Marshal(&s.config))
@@ -349,7 +349,7 @@ type sendUserImpl struct {
}
func (s *sendUserImpl) send() error {
return notifyclient.NotifyAllWithoutRobotWithCtx(s.Ctx, s.Setting.UserIds, false, notify.TNotifyPriority(s.msg.Priority),
return notifyclient.NotifyAllWithoutRobotWithCtx(s.Ctx, s.msg.Uid, false, notify.TNotifyPriority(s.msg.Priority),
"DEFAULT", jsonutils.Marshal(&s.config))
}
+13 -12
View File
@@ -103,9 +103,10 @@ func (man *SCommonAlertManager) ValidateCreateData(
}
if len(data.Channel) == 0 {
data.Channel = []string{monitor.DEFAULT_SEND_NOTIFY_CHANNEL}
} else {
data.Channel = append(data.Channel, monitor.DEFAULT_SEND_NOTIFY_CHANNEL)
}
//else {
// data.Channel = append(data.Channel, monitor.DEFAULT_SEND_NOTIFY_CHANNEL)
//}
if !utils.IsInStringArray(data.Level, monitor.CommonAlertLevels) {
return data, httperrors.NewInputParameterError("Invalid level format: %s", data.Level)
}
@@ -738,16 +739,16 @@ func (alert *SCommonAlert) ValidateUpdateData(
data.Set("frequency", jsonutils.NewInt(freqSpec))
}
}
if recipients, _ := data.GetArray("recipients"); len(recipients) > 0 {
channelStr, _ := data.GetString("channel")
channel, _ := data.GetArray("channel")
if !strings.Contains(channelStr, monitor.DEFAULT_SEND_NOTIFY_CHANNEL) {
channels := jsonutils.NewArray()
channels.Add(channel...)
channels.Add(jsonutils.NewString(monitor.DEFAULT_SEND_NOTIFY_CHANNEL))
data.Set("channel", channels)
}
}
//if recipients, _ := data.GetArray("recipients"); len(recipients) > 0 {
// channelStr, _ := data.GetString("channel")
// channel, _ := data.GetArray("channel")
// if !strings.Contains(channelStr, monitor.DEFAULT_SEND_NOTIFY_CHANNEL) {
// channels := jsonutils.NewArray()
// channels.Add(channel...)
// channels.Add(jsonutils.NewString(monitor.DEFAULT_SEND_NOTIFY_CHANNEL))
// data.Set("channel", channels)
// }
//}
tmp := jsonutils.NewArray()
if metric_query, _ := data.GetArray("metric_query"); len(metric_query) > 0 {
for i := range metric_query {