Explorar o código

don't try to send/don't notify if plugin chan is nil (#923)

Thibault "bui" Koechlin %!s(int64=3) %!d(string=hai) anos
pai
achega
68c11dd827
Modificáronse 1 ficheiros con 8 adicións e 6 borrados
  1. 8 6
      pkg/apiserver/controllers/v1/alerts.go

+ 8 - 6
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")