-
-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2bb13fa
commit 67132b3
Showing
13 changed files
with
331 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace App\Events; | ||
|
||
use App\Models\Result; | ||
use App\Models\User; | ||
use Illuminate\Foundation\Events\Dispatchable; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class ResultCreated | ||
{ | ||
use Dispatchable, SerializesModels; | ||
|
||
public $result; | ||
|
||
public $user; | ||
|
||
/** | ||
* Create a new event instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct(Result $result) | ||
{ | ||
$this->result = $result; | ||
|
||
$this->user = User::find(1); // find the admin user, this isn't ideal but oh well | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace App\Listeners\Data; | ||
|
||
use App\Events\ResultCreated; | ||
use App\Jobs\SendDataToInfluxDbV2; | ||
use App\Settings\InfluxDbSettings; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
|
||
class InfluxDb2Listener implements ShouldQueue | ||
{ | ||
public $influxDbSettings; | ||
|
||
/** | ||
* Create the event listener. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->influxDbSettings = new (InfluxDbSettings::class); | ||
} | ||
|
||
/** | ||
* Handle the event. | ||
* | ||
* @param \App\Events\ResultCreated $event | ||
* @return void | ||
*/ | ||
public function handle(ResultCreated $event) | ||
{ | ||
if ($this->influxDbSettings->v2_enabled) { | ||
SendDataToInfluxDbV2::dispatch($event->result, $this->influxDbSettings); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace App\Listeners; | ||
|
||
use App\Events\ResultCreated; | ||
use App\Settings\NotificationSettings; | ||
use Filament\Notifications\Notification; | ||
|
||
class SpeedtestCompletedListener | ||
{ | ||
public $notificationSettings; | ||
|
||
/** | ||
* Create the event listener. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->notificationSettings = new (NotificationSettings::class); | ||
} | ||
|
||
/** | ||
* Handle the event. | ||
* | ||
* @param \App\Events\ResultCreated $event | ||
* @return void | ||
*/ | ||
public function handle(ResultCreated $event) | ||
{ | ||
if (! $this->notificationSettings->database_enabled) { | ||
return; | ||
} | ||
|
||
if ($this->notificationSettings->database_on_speedtest_run) { | ||
Notification::make() | ||
->title('Speedtest completed') | ||
->success() | ||
->sendToDatabase($event->user); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace App\Listeners\Threshold; | ||
|
||
use App\Events\ResultCreated; | ||
use App\Settings\NotificationSettings; | ||
use App\Settings\ThresholdSettings; | ||
use Filament\Notifications\Notification; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
|
||
class AbsoluteDownloadListener implements ShouldQueue | ||
{ | ||
public $notificationSettings; | ||
|
||
public $thresholdSettings; | ||
|
||
/** | ||
* Create the event listener. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->notificationSettings = new (NotificationSettings::class); | ||
|
||
$this->thresholdSettings = new (ThresholdSettings::class); | ||
} | ||
|
||
/** | ||
* Handle the event. | ||
* | ||
* @param \App\Events\ResultCreated $event | ||
* @return void | ||
*/ | ||
public function handle(ResultCreated $event) | ||
{ | ||
if (! $this->thresholdSettings->absolute_enabled && ! $this->thresholdSettings->absolute_download) { | ||
return; | ||
} | ||
|
||
if (formatBits(formatBytesToBits($event->result->download), 2, false) < $this->thresholdSettings->absolute_download) { | ||
Notification::make() | ||
->title('Threshold breached') | ||
->body('Speedtest #'.$event->result->id.' breached the download threshold of '.$this->thresholdSettings->absolute_download.'Mbps at '.formatBits(formatBytesToBits($event->result->download), 2, false).'Mbps.') | ||
->warning() | ||
->sendToDatabase($event->user); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace App\Listeners\Threshold; | ||
|
||
use App\Events\ResultCreated; | ||
use App\Settings\NotificationSettings; | ||
use App\Settings\ThresholdSettings; | ||
use Filament\Notifications\Notification; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
|
||
class AbsolutePingListener implements ShouldQueue | ||
{ | ||
public $notificationSettings; | ||
|
||
public $thresholdSettings; | ||
|
||
/** | ||
* Create the event listener. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->notificationSettings = new (NotificationSettings::class); | ||
|
||
$this->thresholdSettings = new (ThresholdSettings::class); | ||
} | ||
|
||
/** | ||
* Handle the event. | ||
* | ||
* @param \App\Events\ResultCreated $event | ||
* @return void | ||
*/ | ||
public function handle(ResultCreated $event) | ||
{ | ||
if (! $this->thresholdSettings->absolute_enabled && ! $this->thresholdSettings->absolute_ping) { | ||
return; | ||
} | ||
|
||
if ($event->result->ping > $this->thresholdSettings->absolute_ping) { | ||
Notification::make() | ||
->title('Threshold breached') | ||
->body('Speedtest #'.$event->result->id.' breached the ping threshold of '.$this->thresholdSettings->absolute_ping.'ms at '.$event->result->ping.'ms.') | ||
->warning() | ||
->sendToDatabase($event->user); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace App\Listeners\Threshold; | ||
|
||
use App\Events\ResultCreated; | ||
use App\Settings\NotificationSettings; | ||
use App\Settings\ThresholdSettings; | ||
use Filament\Notifications\Notification; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
|
||
class AbsoluteUploadListener implements ShouldQueue | ||
{ | ||
public $notificationSettings; | ||
|
||
public $thresholdSettings; | ||
|
||
/** | ||
* Create the event listener. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->notificationSettings = new (NotificationSettings::class); | ||
|
||
$this->thresholdSettings = new (ThresholdSettings::class); | ||
} | ||
|
||
/** | ||
* Handle the event. | ||
* | ||
* @param \App\Events\ResultCreated $event | ||
* @return void | ||
*/ | ||
public function handle(ResultCreated $event) | ||
{ | ||
if (! $this->thresholdSettings->absolute_enabled && ! $this->thresholdSettings->absolute_upload) { | ||
return; | ||
} | ||
|
||
if (formatBits(formatBytesToBits($event->result->upload), 2, false) < $this->thresholdSettings->absolute_upload) { | ||
Notification::make() | ||
->title('Threshold breached') | ||
->body('Speedtest #'.$event->result->id.' breached the upload threshold of '.$this->thresholdSettings->absolute_upload.'Mbps at '.formatBits(formatBytesToBits($event->result->upload), 2, false).'Mbps.') | ||
->warning() | ||
->sendToDatabase($event->user); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.