Skip to content

Commit e47768a

Browse files
authored
Update mail transports to generate a single event log if no e-mail addresses are found (librenms#18722)
* Allow mail transports to be configured to not generate event logs if no e-mail addresses are found * StyleCI * Add check to make sure emails is an array * Changed to just generating a nice notice alert when no e-mail recipients are found
1 parent a8a07ca commit e47768a

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

LibreNMS/Alert/Transport/Mail.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@
2424

2525
namespace LibreNMS\Alert\Transport;
2626

27+
use App\Facades\DeviceCache;
2728
use App\Facades\LibrenmsConfig;
29+
use App\Models\Eventlog;
2830
use Exception;
2931
use Illuminate\Support\Str;
3032
use LibreNMS\Alert\AlertUtil;
3133
use LibreNMS\Alert\Transport;
34+
use LibreNMS\Enum\Severity;
3235
use LibreNMS\Exceptions\AlertTransportDeliveryException;
3336
use Spatie\Permission\Models\Role;
3437

@@ -43,6 +46,13 @@ public function deliverAlert(array $alert_data): bool
4346
default => $this->config['email'] ?? $alert_data['contacts'] ?? [], // contacts is only used by legacy synthetic transport
4447
};
4548

49+
if (is_array($emails) && count($emails) == 0) {
50+
$device = DeviceCache::get($alert_data['device_id']);
51+
Eventlog::log('No e-mail recipients found for transport ' . $alert_data['transport_name'], $device, 'alert', Severity::Notice);
52+
53+
return true;
54+
}
55+
4656
$html = LibrenmsConfig::get('email_html');
4757

4858
if ($html && ! $this->isHtmlContent($alert_data['msg'])) {

0 commit comments

Comments
 (0)