Merge pull request #14644 from zexi/automated-cherry-pick-of-#14642-upstream-master

Automated cherry pick of #14642: fix(monitor): onecloud notifiers role_ids validation
This commit is contained in:
Zexi Li
2022-07-14 21:27:17 +08:00
committed by GitHub
3 changed files with 8 additions and 6 deletions
+2 -2
View File
@@ -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 {
+2 -2
View File
@@ -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"`
}
+4 -2
View File
@@ -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 {