Skip to content

Commit

Permalink
feat: add ExtraSenders (#1536)
Browse files Browse the repository at this point in the history
* refactor-sender

* update  upgrade.sql
  • Loading branch information
710leo authored May 16, 2023
1 parent a77dc15 commit ad3cf58
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
16 changes: 12 additions & 4 deletions alert/dispatch/dispatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ type Dispatch struct {

alerting aconf.Alerting

senders map[string]sender.Sender
tpls map[string]*template.Template
senders map[string]sender.Sender
tpls map[string]*template.Template
ExtraSenders map[string]sender.Sender

ctx *ctx.Context

Expand All @@ -50,8 +51,9 @@ func NewDispatch(alertRuleCache *memsto.AlertRuleCacheType, userCache *memsto.Us

alerting: alerting,

senders: make(map[string]sender.Sender),
tpls: make(map[string]*template.Template),
senders: make(map[string]sender.Sender),
tpls: make(map[string]*template.Template),
ExtraSenders: make(map[string]sender.Sender),

ctx: ctx,
}
Expand Down Expand Up @@ -89,6 +91,12 @@ func (e *Dispatch) relaodTpls() error {
models.Telegram: sender.NewSender(models.Telegram, tmpTpls, smtp),
}

e.RwLock.RLock()
for channel, sender := range e.ExtraSenders {
senders[channel] = sender
}
e.RwLock.RUnlock()

e.RwLock.Lock()
e.tpls = tmpTpls
e.senders = senders
Expand Down
1 change: 0 additions & 1 deletion cli/upgrade/upgrade.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ alter table `board` add built_in tinyint(1) not null default 0 comment '0:false
alter table `board` add hide tinyint(1) not null default 0 comment '0:false 1:true';

alter table `chart_share` add datasource_id bigint unsigned not null default 0;
alter table `chart_share` drop dashboard_id;

alter table `alert_rule` add datasource_ids varchar(255) not null default '';
alter table `alert_rule` add rule_config text not null comment 'rule_config';
Expand Down

0 comments on commit ad3cf58

Please sign in to comment.