Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
0f27f3b
phase 1
svenvg93 Nov 17, 2025
0caab92
update compose and remove unused service
svenvg93 Nov 17, 2025
ba47f67
add translations
svenvg93 Nov 17, 2025
3d385ce
disable to add new webhooks for depricated ones
svenvg93 Nov 17, 2025
351476d
pint
svenvg93 Nov 17, 2025
3332aa7
update claude.md
svenvg93 Nov 17, 2025
481328d
remove addable(false)
svenvg93 Nov 17, 2025
6c4b8f9
Merge branch 'main' into feat/apprise
svenvg93 Nov 17, 2025
2a90e49
Merge branch 'alexjustesen:main' into feat/apprise
svenvg93 Nov 18, 2025
7e2a2d4
remove command and update db channel
svenvg93 Nov 18, 2025
b75be03
Merge branch 'alexjustesen:main' into feat/apprise
svenvg93 Nov 20, 2025
2c4cf81
Remove commented code in SpeedtestEventSubscriber
svenvg93 Nov 24, 2025
95b69d2
Merge branch 'alexjustesen:main' into feat/apprise
svenvg93 Nov 24, 2025
33679f4
Merge branch 'alexjustesen:main' into feat/apprise
svenvg93 Nov 25, 2025
f3efb81
Merge branch 'main' into feat/apprise
svenvg93 Nov 25, 2025
c4d0a06
update the ui
svenvg93 Nov 25, 2025
a72543b
Merge branch 'alexjustesen:main' into feat/apprise
svenvg93 Nov 26, 2025
18f9e59
Hookup to listeners
svenvg93 Nov 26, 2025
03143fe
lint
svenvg93 Nov 26, 2025
582f128
Merge branch 'main' into feat/apprise
svenvg93 Nov 26, 2025
5c4964a
remove unused service
svenvg93 Nov 26, 2025
0c27309
Merge branch 'feat/apprise' of https://github.com/svenvg93/speedtest-…
svenvg93 Nov 26, 2025
746f8f3
Merge branch 'main' into feat/apprise
svenvg93 Nov 27, 2025
50f2700
Merge branch 'main' into feat/apprise
svenvg93 Nov 29, 2025
82ddfb9
Merge branch 'main' into feat/apprise
svenvg93 Nov 30, 2025
7bdef62
Merge branch 'alexjustesen:main' into feat/apprise
svenvg93 Nov 30, 2025
e1bc360
update translation string and logic
svenvg93 Nov 30, 2025
213b538
add url validation
svenvg93 Nov 30, 2025
7d1fcf1
add documentation hint
svenvg93 Nov 30, 2025
ae72255
Merge branch 'alexjustesen:main' into feat/apprise
svenvg93 Dec 1, 2025
544de5c
Merge branch 'main' into feat/apprise
svenvg93 Dec 2, 2025
c6d9ee0
Merge branch 'main' into feat/apprise
svenvg93 Dec 2, 2025
6401c24
Merge branch 'alexjustesen:main' into feat/apprise
svenvg93 Dec 2, 2025
e100374
Switch url settings
svenvg93 Dec 3, 2025
d3581a9
Merge branch 'main' into feat/apprise
svenvg93 Dec 3, 2025
0dc0bda
Merge branch 'main' into feat/apprise
svenvg93 Dec 4, 2025
6851fdb
Merge branch 'release/v1.12.0' into feat/apprise
alexjustesen Dec 5, 2025
37f3c49
swap sidecar with server
svenvg93 Dec 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions app/Actions/Notifications/SendAppriseTestNotification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace App\Actions\Notifications;

use App\Notifications\Apprise\TestNotification;
use Filament\Notifications\Notification;
use Illuminate\Support\Facades\Notification as FacadesNotification;
use Lorisleiva\Actions\Concerns\AsAction;

class SendAppriseTestNotification
{
use AsAction;

public function handle(array $channel_urls)
{
if (! count($channel_urls)) {
Notification::make()
->title('You need to add Apprise channel URLs!')
->warning()
->send();

return;
}

foreach ($channel_urls as $row) {
$channelUrl = $row['channel_url'] ?? null;
if (! $channelUrl) {
Notification::make()
->title('Skipping missing channel URL!')
->warning()
->send();

continue;
}

FacadesNotification::route('apprise_urls', $channelUrl)
->notify(new TestNotification);
}

Notification::make()
->title('Test Apprise notification sent.')
->success()
->send();
}
}
76 changes: 76 additions & 0 deletions app/Filament/Pages/Settings/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Filament\Pages\Settings;

use App\Actions\Notifications\SendAppriseTestNotification;
use App\Actions\Notifications\SendDatabaseTestNotification;
use App\Actions\Notifications\SendDiscordTestNotification;
use App\Actions\Notifications\SendGotifyTestNotification;
Expand All @@ -12,6 +13,7 @@
use App\Actions\Notifications\SendSlackTestNotification;
use App\Actions\Notifications\SendTelegramTestNotification;
use App\Actions\Notifications\SendWebhookTestNotification;
use App\Rules\AppriseScheme;
use App\Settings\NotificationSettings;
use CodeWithDennis\SimpleAlert\Components\SimpleAlert;
use Filament\Actions\Action;
Expand Down Expand Up @@ -199,6 +201,80 @@ public function form(Schema $schema): Schema

// ...
]),
Tab::make(__('settings/notifications.apprise'))
->icon(Heroicon::CloudArrowUp)
->schema([
SimpleAlert::make('wehbook_info')
->title(__('general.documentation'))
->description(__('settings/notifications.apprise_hint_description'))
->border()
->info()
->actions([
Action::make('webhook_docs')
->label(__('general.view_documentation'))
->icon('heroicon-m-arrow-long-right')
->color('info')
->link()
->url('https://docs.speedtest-tracker.dev/settings/notifications/apprise')
->openUrlInNewTab(),
])
->columnSpanFull(),

Toggle::make('apprise_enabled')
->label(__('settings/notifications.enable_apprise_notifications'))
->reactive()
->columnSpanFull(),
Grid::make([
'default' => 1,
])
->hidden(fn (Get $get) => $get('apprise_enabled') !== true)
->schema([
Fieldset::make(__('settings/notifications.apprise_server'))
->schema([
TextInput::make('apprise_server_url')
->label(__('settings/notifications.apprise_server_url'))
->placeholder('http://localhost:8000')
->maxLength(2000)
->required()
->url()
->columnSpanFull(),
Checkbox::make('apprise_verify_ssl')
->label(__('settings/notifications.apprise_verify_ssl'))
->default(true)
->columnSpanFull(),
]),
Fieldset::make(__('settings.triggers'))
->schema([
Checkbox::make('apprise_on_speedtest_run')
->label(__('settings/notifications.notify_on_every_speedtest_run'))
->columnSpanFull(),
Checkbox::make('apprise_on_threshold_failure')
->label(__('settings/notifications.notify_on_threshold_failures'))
->columnSpanFull(),
]),
Repeater::make('apprise_channel_urls')
->label(__('settings/notifications.apprise_channels'))
->schema([
TextInput::make('channel_url')
->label(__('settings/notifications.apprise_channel_url'))
->placeholder('discord://WebhookID/WebhookToken')
->helperText(__('settings/notifications.apprise_channel_url_helper'))
->maxLength(2000)
->distinct()
->required()
->rule(new AppriseScheme),
])
->columnSpanFull(),
Actions::make([
Action::make('test apprise')
->label(__('settings/notifications.test_apprise_channel'))
->action(fn (Get $get) => SendAppriseTestNotification::run(
channel_urls: $get('apprise_channel_urls'),
))
->hidden(fn (Get $get) => ! count($get('apprise_channel_urls'))),
]),
]),
]),
])
->columnSpanFull(),

Expand Down
55 changes: 49 additions & 6 deletions app/Listeners/ProcessCompletedSpeedtest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
namespace App\Listeners;

use App\Events\SpeedtestCompleted;
use App\Helpers\Number;
use App\Mail\CompletedSpeedtestMail;
use App\Models\Result;
use App\Models\User;
use App\Notifications\Apprise\SpeedtestNotification;
use App\Settings\NotificationSettings;
use Filament\Actions\Action;
use Filament\Notifications\Notification;
use Filament\Notifications\Notification as FilamentNotification;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Notification;
use Illuminate\Support\Str;
use Spatie\WebhookServer\WebhookCall;

class ProcessCompletedSpeedtest
Expand All @@ -29,7 +33,7 @@ public function handle(SpeedtestCompleted $event): void

$result->loadMissing(['dispatchedBy']);

// $this->notifyAppriseChannels($result);
$this->notifyAppriseChannels($result);
$this->notifyDatabaseChannels($result);
$this->notifyDispatchingUser($result);
$this->notifyMailChannels($result);
Expand All @@ -42,11 +46,50 @@ public function handle(SpeedtestCompleted $event): void
private function notifyAppriseChannels(Result $result): void
{
// Don't send Apprise notification if dispatched by a user or test is unhealthy.
if (filled($result->dispatched_by) || ! $result->healthy) {
if (filled($result->dispatched_by) || $result->healthy === false) {
return;
}

//
// Check if Apprise notifications are enabled.
if (! $this->notificationSettings->apprise_enabled || ! $this->notificationSettings->apprise_on_speedtest_run) {
return;
}

if (! count($this->notificationSettings->apprise_channel_urls)) {
Log::warning('Apprise channel URLs not found, check Apprise notification channel settings.');

return;
}

// Build the speedtest data
$body = view('apprise.speedtest-completed', [
'id' => $result->id,
'service' => Str::title($result->service->getLabel()),
'serverName' => $result->server_name,
'serverId' => $result->server_id,
'isp' => $result->isp,
'ping' => round($result->ping).' ms',
'download' => Number::toBitRate(bits: $result->download_bits, precision: 2),
'upload' => Number::toBitRate(bits: $result->upload_bits, precision: 2),
'packetLoss' => $result->packet_loss,
'speedtest_url' => $result->result_url,
'url' => url('/admin/results'),
])->render();

$title = 'Speedtest Completed – #'.$result->id;

// Send notification to each configured channel URL
foreach ($this->notificationSettings->apprise_channel_urls as $row) {
$channelUrl = $row['channel_url'] ?? null;
if (! $channelUrl) {
Log::warning('Skipping entry with missing channel_url.');

continue;
}

Notification::route('apprise_urls', $channelUrl)
->notify(new SpeedtestNotification($title, $body, 'info'));
}
}

/**
Expand All @@ -65,7 +108,7 @@ private function notifyDatabaseChannels(Result $result): void
}

foreach (User::all() as $user) {
Notification::make()
FilamentNotification::make()
->title(__('results.speedtest_completed'))
->actions([
Action::make('view')
Expand All @@ -87,7 +130,7 @@ private function notifyDispatchingUser(Result $result): void
}

$result->dispatchedBy->notify(
Notification::make()
FilamentNotification::make()
->title(__('results.speedtest_completed'))
->actions([
Action::make('view')
Expand Down
88 changes: 82 additions & 6 deletions app/Listeners/ProcessUnhealthySpeedtest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
namespace App\Listeners;

use App\Events\SpeedtestBenchmarkFailed;
use App\Helpers\Number;
use App\Mail\UnhealthySpeedtestMail;
use App\Models\Result;
use App\Models\User;
use App\Notifications\Apprise\SpeedtestNotification;
use App\Settings\NotificationSettings;
use Filament\Actions\Action;
use Filament\Notifications\Notification;
use Filament\Notifications\Notification as FilamentNotification;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Notification;
use Illuminate\Support\Str;
use Spatie\WebhookServer\WebhookCall;

class ProcessUnhealthySpeedtest
Expand All @@ -31,7 +35,7 @@ public function handle(SpeedtestBenchmarkFailed $event): void

$result->loadMissing(['dispatchedBy']);

// $this->notifyAppriseChannels($result);
$this->notifyAppriseChannels($result);
$this->notifyDatabaseChannels($result);
$this->notifyDispatchingUser($result);
$this->notifyMailChannels($result);
Expand All @@ -48,7 +52,79 @@ private function notifyAppriseChannels(Result $result): void
return;
}

//
if (! $this->notificationSettings->apprise_enabled || ! $this->notificationSettings->apprise_on_threshold_failure) {
return;
}

if (! count($this->notificationSettings->apprise_channel_urls)) {
Log::warning('Apprise channel URLs not found, check Apprise notification channel settings.');

return;
}

if (empty($result->benchmarks)) {
Log::warning('Benchmark data not found, won\'t send Apprise notification.');

return;
}

// Build metrics array from failed benchmarks
$failed = [];

foreach ($result->benchmarks as $metric => $benchmark) {
if ($benchmark['passed'] === false) {
$failed[] = [
'name' => ucfirst($metric),
'threshold' => $benchmark['value'].' '.$benchmark['unit'],
'value' => $this->formatMetricValue($metric, $result),
];
}
}

if (! count($failed)) {
Log::warning('No failed thresholds found in benchmarks, won\'t send Apprise notification.');

return;
}

$body = view('apprise.speedtest-threshold', [
'id' => $result->id,
'service' => Str::title($result->service->getLabel()),
'serverName' => $result->server_name,
'serverId' => $result->server_id,
'isp' => $result->isp,
'metrics' => $failed,
'speedtest_url' => $result->result_url,
'url' => url('/admin/results'),
])->render();

$title = 'Speedtest Threshold Breach – #'.$result->id;

// Send notification to each configured channel URL
foreach ($this->notificationSettings->apprise_channel_urls as $row) {
$channelUrl = $row['channel_url'] ?? null;
if (! $channelUrl) {
Log::warning('Skipping entry with missing channel_url.');

continue;
}

Notification::route('apprise_urls', $channelUrl)
->notify(new SpeedtestNotification($title, $body, 'warning'));
}
}

/**
* Format metric value for display in notification.
*/
private function formatMetricValue(string $metric, Result $result): string
{
return match ($metric) {
'download' => Number::toBitRate(bits: $result->download_bits, precision: 2),
'upload' => Number::toBitRate(bits: $result->upload_bits, precision: 2),
'ping' => round($result->ping, 2).' ms',
default => '',
};
}

/**
Expand All @@ -67,7 +143,7 @@ private function notifyDatabaseChannels(Result $result): void
}

foreach (User::all() as $user) {
Notification::make()
FilamentNotification::make()
->title(__('results.speedtest_benchmark_failed'))
->actions([
Action::make('view')
Expand All @@ -89,7 +165,7 @@ private function notifyDispatchingUser(Result $result): void
}

$result->dispatchedBy->notify(
Notification::make()
FilamentNotification::make()
->title(__('results.speedtest_benchmark_failed'))
->actions([
Action::make('view')
Expand All @@ -106,7 +182,7 @@ private function notifyDispatchingUser(Result $result): void
*/
private function notifyMailChannels(Result $result): void
{
// Don't send webhook if dispatched by a user.
// Don't send mail if dispatched by a user.
if (filled($result->dispatched_by)) {
return;
}
Expand Down
Loading