diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 13867382..97ad8c2b 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -28,7 +28,7 @@ class Kernel extends ConsoleKernel */ 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 . ' * * *'); } diff --git a/app/Facades/HealthchecksFacade.php b/app/Facades/HealthchecksFacade.php new file mode 100644 index 00000000..25f6403d --- /dev/null +++ b/app/Facades/HealthchecksFacade.php @@ -0,0 +1,13 @@ +json([ 'method' => 'run speedtest', 'data' => 'a new speedtest has been added to the queue' diff --git a/app/Providers/IntegrationsServiceProvider.php b/app/Providers/IntegrationsServiceProvider.php new file mode 100644 index 00000000..baca4d59 --- /dev/null +++ b/app/Providers/IntegrationsServiceProvider.php @@ -0,0 +1,66 @@ + (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()); + } + } + } +} diff --git a/config/app.php b/config/app.php index a1c2c0ba..8c3685ce 100644 --- a/config/app.php +++ b/config/app.php @@ -178,6 +178,11 @@ return [ App\Providers\RouteServiceProvider::class, App\Providers\UpdaterServiceProvider::class, + /* + * Custom providers... + */ + App\Providers\IntegrationsServiceProvider::class, + ], /* @@ -230,6 +235,7 @@ return [ 'Validator' => Illuminate\Support\Facades\Validator::class, 'View' => Illuminate\Support\Facades\View::class, 'Updater' => App\Facades\UpdaterFacade::class, + 'Healthcheck' => App\Facades\HealthchecksFacade::class, ], ]; diff --git a/config/integrations.php b/config/integrations.php new file mode 100644 index 00000000..139f82f6 --- /dev/null +++ b/config/integrations.php @@ -0,0 +1,59 @@ + 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, +];