mirror of
https://github.com/henrywhitaker3/Speedtest-Tracker.git
synced 2025-12-24 06:28:27 +01:00
Integrations backend changes
- facade for healthchecks - integrations config
This commit is contained in:
@@ -28,7 +28,7 @@ class Kernel extends ConsoleKernel
|
|||||||
*/
|
*/
|
||||||
protected function schedule(Schedule $schedule)
|
protected function schedule(Schedule $schedule)
|
||||||
{
|
{
|
||||||
$schedule->job(new SpeedtestJob)->cron(SettingsHelper::get('schedule')['value']);
|
$schedule->job(new SpeedtestJob(true, config('integrations')))->cron(SettingsHelper::get('schedule')['value']);
|
||||||
$schedule->command('speedtest:overview')->cron('0 ' . SettingsHelper::get('speedtest_overview_time')->value . ' * * *');
|
$schedule->command('speedtest:overview')->cron('0 ' . SettingsHelper::get('speedtest_overview_time')->value . ' * * *');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
13
app/Facades/HealthchecksFacade.php
Normal file
13
app/Facades/HealthchecksFacade.php
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Facades;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Facade;
|
||||||
|
|
||||||
|
class HealthchecksFacade extends Facade
|
||||||
|
{
|
||||||
|
protected static function getFacadeAccessor()
|
||||||
|
{
|
||||||
|
return 'healthcheck';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -136,7 +136,7 @@ class SpeedtestController extends Controller
|
|||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$data = SpeedtestJob::dispatch(false);
|
$data = SpeedtestJob::dispatch(false, config('integrations'));
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'method' => 'run speedtest',
|
'method' => 'run speedtest',
|
||||||
'data' => 'a new speedtest has been added to the queue'
|
'data' => 'a new speedtest has been added to the queue'
|
||||||
|
|||||||
66
app/Providers/IntegrationsServiceProvider.php
Normal file
66
app/Providers/IntegrationsServiceProvider.php
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Providers;
|
||||||
|
|
||||||
|
use App\Helpers\SettingsHelper;
|
||||||
|
use Exception;
|
||||||
|
use Henrywhitaker3\Healthchecks\Healthchecks;
|
||||||
|
use Illuminate\Support\Facades\App;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
use Ramsey\Uuid\Exception\InvalidUuidStringException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class updates the integrations.php config with the relevant values
|
||||||
|
* from the databse.
|
||||||
|
*/
|
||||||
|
class IntegrationsServiceProvider extends ServiceProvider
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Register services.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function register()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bootstrap services.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function boot()
|
||||||
|
{
|
||||||
|
$settings = [
|
||||||
|
'healthchecks_enabled' => (bool)SettingsHelper::get('healthchecks_enabled')->value,
|
||||||
|
'healthchecks_uuid' => SettingsHelper::get('healthchecks_uuid')->value,
|
||||||
|
'slack_webhook' => SettingsHelper::get('slack_webhook')->value,
|
||||||
|
'telegram_bot_token' => SettingsHelper::get('telegram_bot_token')->value,
|
||||||
|
'telegram_chat_id' => SettingsHelper::get('telegram_chat_id')->value,
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach($settings as $key => $value) {
|
||||||
|
$key = 'integrations.' . $key;
|
||||||
|
|
||||||
|
if($value === "") {
|
||||||
|
$value = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
config()->set([ $key => $value ]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if($settings['healthchecks_enabled']) {
|
||||||
|
try {
|
||||||
|
App::bind('healthcheck', function() use ($settings) {
|
||||||
|
return new Healthchecks($settings['healthchecks_uuid']);
|
||||||
|
});
|
||||||
|
} catch(InvalidUuidStringException $e) {
|
||||||
|
Log::error('Invalid healthchecks UUID');
|
||||||
|
} catch(Exception $e) {
|
||||||
|
Log::error($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -178,6 +178,11 @@ return [
|
|||||||
App\Providers\RouteServiceProvider::class,
|
App\Providers\RouteServiceProvider::class,
|
||||||
App\Providers\UpdaterServiceProvider::class,
|
App\Providers\UpdaterServiceProvider::class,
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Custom providers...
|
||||||
|
*/
|
||||||
|
App\Providers\IntegrationsServiceProvider::class,
|
||||||
|
|
||||||
],
|
],
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -230,6 +235,7 @@ return [
|
|||||||
'Validator' => Illuminate\Support\Facades\Validator::class,
|
'Validator' => Illuminate\Support\Facades\Validator::class,
|
||||||
'View' => Illuminate\Support\Facades\View::class,
|
'View' => Illuminate\Support\Facades\View::class,
|
||||||
'Updater' => App\Facades\UpdaterFacade::class,
|
'Updater' => App\Facades\UpdaterFacade::class,
|
||||||
|
'Healthcheck' => App\Facades\HealthchecksFacade::class,
|
||||||
],
|
],
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|||||||
59
config/integrations.php
Normal file
59
config/integrations.php
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Healthchecks enabled
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| This option defines whether healthchecks integrations are enabled
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'healthchecks_enabled' => false,
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Healthchecks UUID
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| This option defines the UUID for healthchecks
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'healthchecks_uuid' => null,
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Slack webhook
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| This option defines the slack webhook url
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'slack_webhook' => null,
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Telegram bot token
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| This option defines the telegram bot token
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'telegram_bot_token' => null,
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Telegram chat id
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| This option defines the telegram chat id
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'telegram_chat_id' => null,
|
||||||
|
];
|
||||||
Reference in New Issue
Block a user