From 68c11dd827c25146622f61548bf211ff5e8e34f2 Mon Sep 17 00:00:00 2001 From: "Thibault \"bui\" Koechlin" Date: Tue, 31 Aug 2021 14:39:32 +0200 Subject: [PATCH] don't try to send/don't notify if plugin chan is nil (#923) --- pkg/apiserver/controllers/v1/alerts.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/pkg/apiserver/controllers/v1/alerts.go b/pkg/apiserver/controllers/v1/alerts.go index 8f129ac09..8e21cb482 100644 --- a/pkg/apiserver/controllers/v1/alerts.go +++ b/pkg/apiserver/controllers/v1/alerts.go @@ -98,11 +98,13 @@ func FormatAlerts(result []*ent.Alert) models.AddAlertsRequest { } func (c *Controller) sendAlertToPluginChannel(alert *models.Alert, profileID uint) { - select { - case c.PluginChannel <- csplugin.ProfileAlert{ProfileID: uint(profileID), Alert: alert}: - log.Debugf("alert sent to Plugin channel") - default: - log.Warningf("Cannot send alert to Plugin channel") + if c.PluginChannel != nil { + select { + case c.PluginChannel <- csplugin.ProfileAlert{ProfileID: uint(profileID), Alert: alert}: + log.Debugf("alert sent to Plugin channel") + default: + log.Warningf("Cannot send alert to Plugin channel") + } } } @@ -167,7 +169,7 @@ func (c *Controller) CreateAlert(gctx *gin.Context) { alert.MachineID = machineID } - if c.CAPIChan != nil { + if c.CAPIChan != nil { select { case c.CAPIChan <- input: log.Debug("alert sent to CAPI channel")