From 1122aeaa16825386dbd2f8ee6512aeebf3318fd1 Mon Sep 17 00:00:00 2001 From: lzx Date: Thu, 14 Jul 2022 16:53:17 +0800 Subject: [PATCH] fix(monitor): onecloud notifiers role_ids validation --- pkg/monitor/alerting/notifiers/onecloud.go | 4 ++-- pkg/monitor/models/alertrecord.go | 4 ++-- pkg/monitor/models/commonalert.go | 6 ++++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pkg/monitor/alerting/notifiers/onecloud.go b/pkg/monitor/alerting/notifiers/onecloud.go index a1a0ded9e5..08e4443a2d 100644 --- a/pkg/monitor/alerting/notifiers/onecloud.go +++ b/pkg/monitor/alerting/notifiers/onecloud.go @@ -71,8 +71,8 @@ func init() { if err := input.Settings.Unmarshal(settings); err != nil { return input, errors.Wrap(err, "unmarshal setting") } - if settings.Channel == "" && len(settings.RobotIds) == 0 { - return input, httperrors.NewInputParameterError("channel is empty") + if settings.Channel == "" && len(settings.RobotIds) == 0 && len(settings.RoleIds) == 0 { + return input, httperrors.NewInputParameterError("channel, robot_ids or role_ids is empty") } ids := make([]string, 0) for _, uid := range settings.UserIds { diff --git a/pkg/monitor/models/alertrecord.go b/pkg/monitor/models/alertrecord.go index 8b365eddb7..773541954f 100644 --- a/pkg/monitor/models/alertrecord.go +++ b/pkg/monitor/models/alertrecord.go @@ -55,8 +55,8 @@ type SAlertRecord struct { Level string `charset:"ascii" width:"36" nullable:"false" default:"normal" list:"user" update:"user"` State string `width:"36" charset:"ascii" nullable:"false" default:"unknown" list:"user" update:"user"` SendState string `width:"36" charset:"ascii" default:"ok" list:"user" update:"user"` - EvalData jsonutils.JSONObject `list:"user" update:"user"` - AlertRule jsonutils.JSONObject `list:"user" update:"user"` + EvalData jsonutils.JSONObject `list:"user" update:"user" length:""` + AlertRule jsonutils.JSONObject `list:"user" update:"user" length:""` ResType string `width:"36" list:"user" update:"user"` } diff --git a/pkg/monitor/models/commonalert.go b/pkg/monitor/models/commonalert.go index 61dabd39aa..4d81edb07d 100644 --- a/pkg/monitor/models/commonalert.go +++ b/pkg/monitor/models/commonalert.go @@ -194,8 +194,10 @@ func (man *SCommonAlertManager) ValidateCreateData( } } // 默认的系统配置Recipients=commonalert-default - if data.AlertType != monitor.CommonAlertSystemAlertType && len(data.Recipients) == 0 { - return data, merrors.NewArgIsEmptyErr("recipients") + if data.AlertType != monitor.CommonAlertSystemAlertType { + if len(data.Recipients) == 0 && len(data.RobotIds) == 0 && len(data.Roles) == 0 { + return data, merrors.NewArgIsEmptyErr("recipients, robot_ids or roles") + } } if len(data.CommonMetricInputQuery.MetricQuery) == 0 {