未验证 提交 f1cdd2fa 编写于 作者: S shardingHe 提交者: GitHub

refactor: modify the alert_subscribe to make the datasource optional (#1679)


* subscribe change 'pord','datasource_ids' to optional item

---------
Co-authored-by: NshardingHe <wangzihe@flashcat.cloud>
上级 3d5ad022
...@@ -96,8 +96,8 @@ func (s *AlertSubscribe) Verify() error { ...@@ -96,8 +96,8 @@ func (s *AlertSubscribe) Verify() error {
if err := s.Parse(); err != nil { if err := s.Parse(); err != nil {
return err return err
} }
if len(s.IBusiGroups) == 0 && len(s.ITags) == 0 && s.RuleId == 0 { if len(s.DatasourceIdsJson) == 0 && len(s.IBusiGroups) == 0 && len(s.ITags) == 0 && s.RuleId == 0 {
return errors.New("none of busi_groups, rule_id, and tags have been assigned any values.") return errors.New("none of datasource_ids, busi_groups, rule_id, and tags have been assigned any values.")
} }
ugids := strings.Fields(s.UserGroupIds) ugids := strings.Fields(s.UserGroupIds)
...@@ -111,11 +111,10 @@ func (s *AlertSubscribe) Verify() error { ...@@ -111,11 +111,10 @@ func (s *AlertSubscribe) Verify() error {
} }
func (s *AlertSubscribe) FE2DB() error { func (s *AlertSubscribe) FE2DB() error {
idsByte, err := json.Marshal(s.DatasourceIdsJson) if len(s.DatasourceIdsJson) > 0 {
if err != nil { idsByte, _ := json.Marshal(s.DatasourceIdsJson)
return err s.DatasourceIds = string(idsByte)
} }
s.DatasourceIds = string(idsByte)
if len(s.WebhooksJson) > 0 { if len(s.WebhooksJson) > 0 {
b, _ := json.Marshal(s.WebhooksJson) b, _ := json.Marshal(s.WebhooksJson)
...@@ -323,6 +322,10 @@ func AlertSubscribeGetsAll(ctx *ctx.Context) ([]*AlertSubscribe, error) { ...@@ -323,6 +322,10 @@ func AlertSubscribeGetsAll(ctx *ctx.Context) ([]*AlertSubscribe, error) {
} }
func (s *AlertSubscribe) MatchProd(prod string) bool { func (s *AlertSubscribe) MatchProd(prod string) bool {
//Replace 'prod' with optional item
if s.Prod == "" {
return true
}
return s.Prod == prod return s.Prod == prod
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册