Integrations backend changes

- facade for healthchecks
- integrations config
This commit is contained in:
Henry Whitaker
2020-08-15 14:52:00 +01:00
parent a73e058ab1
commit 92544142a9
6 changed files with 146 additions and 2 deletions

View File

@@ -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 . ' * * *');
}

View File

@@ -0,0 +1,13 @@
<?php
namespace App\Facades;
use Illuminate\Support\Facades\Facade;
class HealthchecksFacade extends Facade
{
protected static function getFacadeAccessor()
{
return 'healthcheck';
}
}

View File

@@ -136,7 +136,7 @@ class SpeedtestController extends Controller
public function run()
{
try {
$data = SpeedtestJob::dispatch(false);
$data = SpeedtestJob::dispatch(false, config('integrations'));
return response()->json([
'method' => 'run speedtest',
'data' => 'a new speedtest has been added to the queue'

View 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());
}
}
}
}

View File

@@ -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,
],
];

59
config/integrations.php Normal file
View 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,
];