do not send more than group_threshold alerts at once to a notification plugin

This commit is contained in:
Sebastien Blot 2023-04-14 11:13:52 +02:00
parent 9a5a937695
commit 1aa6f4014f
No known key found for this signature in database
GPG key ID: DFC2902F40449F6A

View file

@ -115,8 +115,19 @@ loop:
pb.alertsByPluginName[pluginName] = make([]*models.Alert, 0)
pluginMutex.Unlock()
go func() {
if err := pb.pushNotificationsToPlugin(pluginName, tmpAlerts); err != nil {
log.WithField("plugin:", pluginName).Error(err)
//Chunk alerts to respect group_threshold
threshold := pb.pluginConfigByName[pluginName].GroupThreshold
if threshold == 0 {
threshold = 1
}
for i := 0; i < len(tmpAlerts); i += threshold {
end := i + threshold
if end > len(tmpAlerts) {
end = len(tmpAlerts)
}
if err := pb.pushNotificationsToPlugin(pluginName, tmpAlerts[i:end]); err != nil {
log.WithField("plugin:", pluginName).Error(err)
}
}
}()