Skip to content

Commit

Permalink
[Bug] Don't try to send empty threshold notifications (#1291)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjustesen authored Mar 3, 2024
1 parent 2112519 commit abab2f9
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 26 deletions.
14 changes: 8 additions & 6 deletions app/Listeners/Discord/SendSpeedtestThresholdNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public function handle(SpeedtestCompleted $event): void
array_push($failed, $this->absolutePingThreshold(event: $event, thresholdSettings: $thresholdSettings));
}

$failed = array_filter($failed);

if (! count($failed)) {
Log::warning('Failed Discord thresholds not found, won\'t send notification.');

Expand Down Expand Up @@ -81,10 +83,10 @@ public function handle(SpeedtestCompleted $event): void
/**
* Build Discord notification if absolute download threshold is breached.
*/
protected function absoluteDownloadThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): array
protected function absoluteDownloadThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): bool|array
{
if (! absoluteDownloadThresholdFailed($thresholdSettings->absolute_download, $event->result->download)) {
return [];
return false;
}

return [
Expand All @@ -97,10 +99,10 @@ protected function absoluteDownloadThreshold(SpeedtestCompleted $event, Threshol
/**
* Build Discord notification if absolute upload threshold is breached.
*/
protected function absoluteUploadThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): array
protected function absoluteUploadThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): bool|array
{
if (! absoluteUploadThresholdFailed($thresholdSettings->absolute_upload, $event->result->upload)) {
return [];
return false;
}

return [
Expand All @@ -113,10 +115,10 @@ protected function absoluteUploadThreshold(SpeedtestCompleted $event, ThresholdS
/**
* Build Discord notification if absolute ping threshold is breached.
*/
protected function absolutePingThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): array
protected function absolutePingThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): bool|array
{
if (! absolutePingThresholdFailed($thresholdSettings->absolute_ping, $event->result->ping)) {
return [];
return false;
}

return [
Expand Down
14 changes: 8 additions & 6 deletions app/Listeners/Mail/SendSpeedtestThresholdNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public function handle(SpeedtestCompleted $event): void
array_push($failed, $this->absolutePingThreshold(event: $event, thresholdSettings: $thresholdSettings));
}

$failed = array_filter($failed);

if (! count($failed)) {
Log::warning('Failed mail thresholds not found, won\'t send notification.');

Expand All @@ -68,10 +70,10 @@ public function handle(SpeedtestCompleted $event): void
/**
* Build mail notification if absolute download threshold is breached.
*/
protected function absoluteDownloadThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): array
protected function absoluteDownloadThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): bool|array
{
if (! absoluteDownloadThresholdFailed($thresholdSettings->absolute_download, $event->result->download)) {
return [];
return false;
}

return [
Expand All @@ -84,10 +86,10 @@ protected function absoluteDownloadThreshold(SpeedtestCompleted $event, Threshol
/**
* Build mail notification if absolute upload threshold is breached.
*/
protected function absoluteUploadThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): array
protected function absoluteUploadThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): bool|array
{
if (! absoluteUploadThresholdFailed($thresholdSettings->absolute_upload, $event->result->upload)) {
return [];
return false;
}

return [
Expand All @@ -100,10 +102,10 @@ protected function absoluteUploadThreshold(SpeedtestCompleted $event, ThresholdS
/**
* Build mail notification if absolute ping threshold is breached.
*/
protected function absolutePingThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): array
protected function absolutePingThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): bool|array
{
if (! absolutePingThresholdFailed($thresholdSettings->absolute_ping, $event->result->ping)) {
return [];
return false;
}

return [
Expand Down
14 changes: 8 additions & 6 deletions app/Listeners/Telegram/SendSpeedtestThresholdNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public function handle(SpeedtestCompleted $event): void
array_push($failed, $this->absolutePingThreshold(event: $event, thresholdSettings: $thresholdSettings));
}

$failed = array_filter($failed);

if (! count($failed)) {
Log::warning('Failed Telegram thresholds not found, won\'t send notification.');

Expand All @@ -77,10 +79,10 @@ public function handle(SpeedtestCompleted $event): void
/**
* Build Telegram notification if absolute download threshold is breached.
*/
protected function absoluteDownloadThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): array
protected function absoluteDownloadThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): bool|array
{
if (! absoluteDownloadThresholdFailed($thresholdSettings->absolute_download, $event->result->download)) {
return [];
return false;
}

return [
Expand All @@ -93,10 +95,10 @@ protected function absoluteDownloadThreshold(SpeedtestCompleted $event, Threshol
/**
* Build Telegram notification if absolute upload threshold is breached.
*/
protected function absoluteUploadThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): array
protected function absoluteUploadThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): bool|array
{
if (! absoluteUploadThresholdFailed($thresholdSettings->absolute_upload, $event->result->upload)) {
return [];
return false;
}

return [
Expand All @@ -109,10 +111,10 @@ protected function absoluteUploadThreshold(SpeedtestCompleted $event, ThresholdS
/**
* Build Telegram notification if absolute ping threshold is breached.
*/
protected function absolutePingThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): array
protected function absolutePingThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): bool|array
{
if (! absolutePingThresholdFailed($thresholdSettings->absolute_ping, $event->result->ping)) {
return [];
return false;
}

return [
Expand Down
14 changes: 8 additions & 6 deletions app/Listeners/Webhook/SendSpeedtestThresholdNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public function handle(SpeedtestCompleted $event): void
array_push($failed, $this->absolutePingThreshold(event: $event, thresholdSettings: $thresholdSettings));
}

$failed = array_filter($failed);

if (! count($failed)) {
Log::warning('Failed webhook thresholds not found, won\'t send notification.');

Expand All @@ -77,10 +79,10 @@ public function handle(SpeedtestCompleted $event): void
/**
* Build webhook notification if absolute download threshold is breached.
*/
protected function absoluteDownloadThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): array
protected function absoluteDownloadThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): bool|array
{
if (! absoluteDownloadThresholdFailed($thresholdSettings->absolute_download, $event->result->download)) {
return [];
return false;
}

return [
Expand All @@ -93,10 +95,10 @@ protected function absoluteDownloadThreshold(SpeedtestCompleted $event, Threshol
/**
* Build webhook notification if absolute upload threshold is breached.
*/
protected function absoluteUploadThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): array
protected function absoluteUploadThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): bool|array
{
if (! absoluteUploadThresholdFailed($thresholdSettings->absolute_upload, $event->result->upload)) {
return [];
return false;
}

return [
Expand All @@ -109,10 +111,10 @@ protected function absoluteUploadThreshold(SpeedtestCompleted $event, ThresholdS
/**
* Build webhook notification if absolute ping threshold is breached.
*/
protected function absolutePingThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): array
protected function absolutePingThreshold(SpeedtestCompleted $event, ThresholdSettings $thresholdSettings): bool|array
{
if (! absolutePingThresholdFailed($thresholdSettings->absolute_ping, $event->result->ping)) {
return [];
return false;
}

return [
Expand Down
2 changes: 1 addition & 1 deletion resources/views/emails/speedtest-completed.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<x-mail::table>
| **Metric** | **Value** |
|-------------|------------------:|
|:------------|------------------:|
| Server name | {{ $serverName }} |
| Server ID | {{ $serverId }} |
| Ping | {{ $ping }} |
Expand Down
2 changes: 1 addition & 1 deletion resources/views/emails/speedtest-threshold.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<x-mail::table>
| **Metric** | **Threshold** | **Value** |
|------------|--------------:|----------:|
|:-----------|:--------------|----------:|
@foreach ($metrics as $item)
| {{ $item['name'] }} | {{ $item['threshold'] }} | {{ $item['value'] }} |
@endforeach
Expand Down

0 comments on commit abab2f9

Please sign in to comment.