Skip to content

Commit abab2f9

Browse files
authored
[Bug] Don't try to send empty threshold notifications (alexjustesen#1291)
1 parent 2112519 commit abab2f9

File tree

6 files changed

+34
-26
lines changed

6 files changed

+34
-26
lines changed

app/Listeners/Discord/SendSpeedtestThresholdNotification.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ public function handle(SpeedtestCompleted $event): void
5353
array_push($failed, $this->absolutePingThreshold(event: $event, thresholdSettings: $thresholdSettings));
5454
}
5555

56+
$failed = array_filter($failed);
57+
5658
if (! count($failed)) {
5759
Log::warning('Failed Discord thresholds not found, won\'t send notification.');
5860

@@ -81,10 +83,10 @@ public function handle(SpeedtestCompleted $event): void
8183
/**
8284
* Build Discord notification if absolute download threshold is breached.
8385
*/
84-
protected function absoluteDownloadThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): array
86+
protected function absoluteDownloadThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): bool|array
8587
{
8688
if (! absoluteDownloadThresholdFailed($thresholdSettings->absolute_download, $event->result->download)) {
87-
return [];
89+
return false;
8890
}
8991

9092
return [
@@ -97,10 +99,10 @@ protected function absoluteDownloadThreshold(SpeedtestCompleted $event, Threshol
9799
/**
98100
* Build Discord notification if absolute upload threshold is breached.
99101
*/
100-
protected function absoluteUploadThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): array
102+
protected function absoluteUploadThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): bool|array
101103
{
102104
if (! absoluteUploadThresholdFailed($thresholdSettings->absolute_upload, $event->result->upload)) {
103-
return [];
105+
return false;
104106
}
105107

106108
return [
@@ -113,10 +115,10 @@ protected function absoluteUploadThreshold(SpeedtestCompleted $event, ThresholdS
113115
/**
114116
* Build Discord notification if absolute ping threshold is breached.
115117
*/
116-
protected function absolutePingThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): array
118+
protected function absolutePingThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): bool|array
117119
{
118120
if (! absolutePingThresholdFailed($thresholdSettings->absolute_ping, $event->result->ping)) {
119-
return [];
121+
return false;
120122
}
121123

122124
return [

app/Listeners/Mail/SendSpeedtestThresholdNotification.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ public function handle(SpeedtestCompleted $event): void
5353
array_push($failed, $this->absolutePingThreshold(event: $event, thresholdSettings: $thresholdSettings));
5454
}
5555

56+
$failed = array_filter($failed);
57+
5658
if (! count($failed)) {
5759
Log::warning('Failed mail thresholds not found, won\'t send notification.');
5860

@@ -68,10 +70,10 @@ public function handle(SpeedtestCompleted $event): void
6870
/**
6971
* Build mail notification if absolute download threshold is breached.
7072
*/
71-
protected function absoluteDownloadThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): array
73+
protected function absoluteDownloadThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): bool|array
7274
{
7375
if (! absoluteDownloadThresholdFailed($thresholdSettings->absolute_download, $event->result->download)) {
74-
return [];
76+
return false;
7577
}
7678

7779
return [
@@ -84,10 +86,10 @@ protected function absoluteDownloadThreshold(SpeedtestCompleted $event, Threshol
8486
/**
8587
* Build mail notification if absolute upload threshold is breached.
8688
*/
87-
protected function absoluteUploadThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): array
89+
protected function absoluteUploadThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): bool|array
8890
{
8991
if (! absoluteUploadThresholdFailed($thresholdSettings->absolute_upload, $event->result->upload)) {
90-
return [];
92+
return false;
9193
}
9294

9395
return [
@@ -100,10 +102,10 @@ protected function absoluteUploadThreshold(SpeedtestCompleted $event, ThresholdS
100102
/**
101103
* Build mail notification if absolute ping threshold is breached.
102104
*/
103-
protected function absolutePingThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): array
105+
protected function absolutePingThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): bool|array
104106
{
105107
if (! absolutePingThresholdFailed($thresholdSettings->absolute_ping, $event->result->ping)) {
106-
return [];
108+
return false;
107109
}
108110

109111
return [

app/Listeners/Telegram/SendSpeedtestThresholdNotification.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public function handle(SpeedtestCompleted $event): void
5454
array_push($failed, $this->absolutePingThreshold(event: $event, thresholdSettings: $thresholdSettings));
5555
}
5656

57+
$failed = array_filter($failed);
58+
5759
if (! count($failed)) {
5860
Log::warning('Failed Telegram thresholds not found, won\'t send notification.');
5961

@@ -77,10 +79,10 @@ public function handle(SpeedtestCompleted $event): void
7779
/**
7880
* Build Telegram notification if absolute download threshold is breached.
7981
*/
80-
protected function absoluteDownloadThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): array
82+
protected function absoluteDownloadThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): bool|array
8183
{
8284
if (! absoluteDownloadThresholdFailed($thresholdSettings->absolute_download, $event->result->download)) {
83-
return [];
85+
return false;
8486
}
8587

8688
return [
@@ -93,10 +95,10 @@ protected function absoluteDownloadThreshold(SpeedtestCompleted $event, Threshol
9395
/**
9496
* Build Telegram notification if absolute upload threshold is breached.
9597
*/
96-
protected function absoluteUploadThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): array
98+
protected function absoluteUploadThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): bool|array
9799
{
98100
if (! absoluteUploadThresholdFailed($thresholdSettings->absolute_upload, $event->result->upload)) {
99-
return [];
101+
return false;
100102
}
101103

102104
return [
@@ -109,10 +111,10 @@ protected function absoluteUploadThreshold(SpeedtestCompleted $event, ThresholdS
109111
/**
110112
* Build Telegram notification if absolute ping threshold is breached.
111113
*/
112-
protected function absolutePingThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): array
114+
protected function absolutePingThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): bool|array
113115
{
114116
if (! absolutePingThresholdFailed($thresholdSettings->absolute_ping, $event->result->ping)) {
115-
return [];
117+
return false;
116118
}
117119

118120
return [

app/Listeners/Webhook/SendSpeedtestThresholdNotification.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ public function handle(SpeedtestCompleted $event): void
5555
array_push($failed, $this->absolutePingThreshold(event: $event, thresholdSettings: $thresholdSettings));
5656
}
5757

58+
$failed = array_filter($failed);
59+
5860
if (! count($failed)) {
5961
Log::warning('Failed webhook thresholds not found, won\'t send notification.');
6062

@@ -77,10 +79,10 @@ public function handle(SpeedtestCompleted $event): void
7779
/**
7880
* Build webhook notification if absolute download threshold is breached.
7981
*/
80-
protected function absoluteDownloadThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): array
82+
protected function absoluteDownloadThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): bool|array
8183
{
8284
if (! absoluteDownloadThresholdFailed($thresholdSettings->absolute_download, $event->result->download)) {
83-
return [];
85+
return false;
8486
}
8587

8688
return [
@@ -93,10 +95,10 @@ protected function absoluteDownloadThreshold(SpeedtestCompleted $event, Threshol
9395
/**
9496
* Build webhook notification if absolute upload threshold is breached.
9597
*/
96-
protected function absoluteUploadThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): array
98+
protected function absoluteUploadThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): bool|array
9799
{
98100
if (! absoluteUploadThresholdFailed($thresholdSettings->absolute_upload, $event->result->upload)) {
99-
return [];
101+
return false;
100102
}
101103

102104
return [
@@ -109,10 +111,10 @@ protected function absoluteUploadThreshold(SpeedtestCompleted $event, ThresholdS
109111
/**
110112
* Build webhook notification if absolute ping threshold is breached.
111113
*/
112-
protected function absolutePingThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): array
114+
protected function absolutePingThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): bool|array
113115
{
114116
if (! absolutePingThresholdFailed($thresholdSettings->absolute_ping, $event->result->ping)) {
115-
return [];
117+
return false;
116118
}
117119

118120
return [

resources/views/emails/speedtest-completed.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<x-mail::table>
77
| **Metric** | **Value** |
8-
|-------------|------------------:|
8+
|:------------|------------------:|
99
| Server name | {{ $serverName }} |
1010
| Server ID | {{ $serverId }} |
1111
| Ping | {{ $ping }} |

resources/views/emails/speedtest-threshold.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<x-mail::table>
77
| **Metric** | **Threshold** | **Value** |
8-
|------------|--------------:|----------:|
8+
|:-----------|:--------------|----------:|
99
@foreach ($metrics as $item)
1010
| {{ $item['name'] }} | {{ $item['threshold'] }} | {{ $item['value'] }} |
1111
@endforeach

0 commit comments

Comments
 (0)