Skip to content

Commit a098d5d

Browse files
committed
refactor: update subscribe api
1 parent 05c3f1e commit a098d5d

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

center/router/router_alert_subscribe.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ func (rt *Router) alertSubscribeTryRun(c *gin.Context) {
175175

176176
// 新版本通知规则
177177
if f.SubscribeConfig.NotifyVersion == 1 {
178+
if len(f.SubscribeConfig.NotifyRuleIds) == 0 {
179+
ginx.Bomb(http.StatusBadRequest, i18n.Sprintf(lang, "no notify rules selected"))
180+
}
181+
178182
for _, id := range f.SubscribeConfig.NotifyRuleIds {
179183
notifyRule, err := models.GetNotifyRule(rt.Ctx, id)
180184
if err != nil {

models/alert_subscribe.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ func (s *AlertSubscribe) Verify() error {
132132
}
133133
}
134134

135+
if s.NotifyVersion == 1 && len(s.NotifyRuleIds) == 0 {
136+
return errors.New("no notify rules selected")
137+
}
138+
135139
return nil
136140
}
137141

pkg/i18nx/var.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ var I18N = `{
6666
"subscribe notify rule not found: %v": "订阅通知规则未找到: %v",
6767
"notify rule send error: %v": "通知规则发送错误: %v",
6868
"event match subscribe and notification test ok": "事件匹配订阅规则,通知测试成功",
69+
"no notify rules selected": "未选择通知规则",
6970
"no notify channels selected": "未选择通知渠道",
7071
"no notify groups selected": "未选择通知组",
7172
"all users missing notify channel configurations: %v": "所有用户缺少通知渠道配置: %v",
@@ -249,6 +250,7 @@ var I18N = `{
249250
"subscribe notify rule not found: %v": "訂閱通知規則未找到: %v",
250251
"notify rule send error: %v": "通知規則發送錯誤: %v",
251252
"event match subscribe and notification test ok": "事件匹配訂閱規則,通知測試成功",
253+
"no notify rules selected": "未選擇通知規則",
252254
"no notify channels selected": "未選擇通知渠道",
253255
"no notify groups selected": "未選擇通知組",
254256
"all users missing notify channel configurations: %v": "所有用戶缺少通知渠道配置: %v",
@@ -429,6 +431,7 @@ var I18N = `{
429431
"subscribe notify rule not found: %v": "サブスクライブ通知ルールが見つかりません: %v",
430432
"notify rule send error: %v": "通知ルール送信エラー: %v",
431433
"event match subscribe and notification test ok": "イベントがサブスクライブルールに一致し、通知テストが成功しました",
434+
"no notify rules selected": "通知ルールが選択されていません",
432435
"no notify channels selected": "通知チャンネルが選択されていません",
433436
"no notify groups selected": "通知グループが選択されていません",
434437
"all users missing notify channel configurations: %v": "すべてのユーザーに通知チャンネル設定がありません: %v",
@@ -609,6 +612,7 @@ var I18N = `{
609612
"subscribe notify rule not found: %v": "Правило уведомления подписки не найдено: %v",
610613
"notify rule send error: %v": "Ошибка отправки правила уведомления: %v",
611614
"event match subscribe and notification test ok": "Событие соответствует правилу подписки, тест уведомления успешен",
615+
"no notify rules selected": "Правила уведомлений не выбраны",
612616
"no notify channels selected": "Каналы уведомлений не выбраны",
613617
"no notify groups selected": "Группы уведомлений не выбраны",
614618
"all users missing notify channel configurations: %v": "У всех пользователей отсутствуют настройки каналов уведомлений: %v",

0 commit comments

Comments
 (0)