fix(monitor): onecloud notifiers role_ids validation

This commit is contained in:
lzx
2022-07-14 16:53:17 +08:00
committed by Zexi Li
parent 93ea09c967
commit 1122aeaa16
3 changed files with 8 additions and 6 deletions

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 {

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"`
}

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 {