MCPcopy
hub / github.com/ccfos/nightingale / Send

Method Send

alert/dispatch/dispatch.go:718–762  ·  view source on GitHub ↗
(rule *models.AlertRule, event *models.AlertCurEvent, notifyTarget *NotifyTarget, isSubscribe bool)

Source from the content-addressed store, hash-verified

716}
717
718func (e *Dispatch) Send(rule *models.AlertRule, event *models.AlertCurEvent, notifyTarget *NotifyTarget, isSubscribe bool) {
719 needSend := e.BeforeSenderHook(event)
720 if needSend {
721 for channel, uids := range notifyTarget.ToChannelUserMap() {
722 msgCtx := sender.BuildMessageContext(e.ctx, rule, []*models.AlertCurEvent{event},
723 uids, e.userCache, e.Astats)
724 e.RwLock.RLock()
725 s := e.Senders[channel]
726 e.RwLock.RUnlock()
727 if s == nil {
728 logger.Debugf("no sender for channel: %s", channel)
729 continue
730 }
731
732 var event *models.AlertCurEvent
733 if len(msgCtx.Events) > 0 {
734 event = msgCtx.Events[0]
735 }
736
737 logger.Debugf("send to channel:%s event:%+v users:%+v", channel, event, msgCtx.Users)
738 s.Send(msgCtx)
739 }
740 }
741
742 // handle event callbacks
743 e.SendCallbacks(rule, notifyTarget, event)
744
745 // handle global webhooks
746 if !event.OverrideGlobalWebhook() {
747 if e.alerting.WebhookBatchSend {
748 sender.BatchSendWebhooks(e.ctx, notifyTarget.ToWebhookMap(), event, e.Astats)
749 } else {
750 sender.SingleSendWebhooks(e.ctx, notifyTarget.ToWebhookMap(), event, e.Astats)
751 }
752 }
753
754 // handle plugin call
755 go sender.MayPluginNotify(e.ctx, e.genNoticeBytes(event), e.notifyConfigCache.
756 GetNotifyScript(), e.Astats, event)
757
758 if !isSubscribe {
759 // handle ibex callbacks
760 e.HandleIbex(rule, event)
761 }
762}
763
764func (e *Dispatch) SendCallbacks(rule *models.AlertRule, notifyTarget *NotifyTarget, event *models.AlertCurEvent) {
765 uids := notifyTarget.ToUidList()

Callers 1

HandleEventNotifyMethod · 0.95

Calls 11

SendCallbacksMethod · 0.95
OverrideGlobalWebhookMethod · 0.95
genNoticeBytesMethod · 0.95
HandleIbexMethod · 0.95
BuildMessageContextFunction · 0.92
BatchSendWebhooksFunction · 0.92
SingleSendWebhooksFunction · 0.92
MayPluginNotifyFunction · 0.92
ToChannelUserMapMethod · 0.80
ToWebhookMapMethod · 0.80
GetNotifyScriptMethod · 0.80

Tested by

no test coverage detected