mirror of
https://github.com/henrywhitaker3/Speedtest-Tracker.git
synced 2025-12-21 21:33:08 +01:00
Added controller endpoints for testing healthchecks settings
This commit is contained in:
77
app/Http/Controllers/IntegrationsController.php
Normal file
77
app/Http/Controllers/IntegrationsController.php
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Helpers\SettingsHelper;
|
||||||
|
use Exception;
|
||||||
|
use Healthcheck;
|
||||||
|
use Henrywhitaker3\Healthchecks\Exceptions\HealthchecksUuidNotFoundException;
|
||||||
|
use Henrywhitaker3\Healthchecks\Healthchecks;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Ramsey\Uuid\Exception\InvalidUuidStringException;
|
||||||
|
|
||||||
|
class IntegrationsController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Test the healthchecks config
|
||||||
|
*
|
||||||
|
* @return JsonResponse
|
||||||
|
*/
|
||||||
|
public function testHealthchecks(String $method)
|
||||||
|
{
|
||||||
|
$methodResp = 'test healthchecks \'' . $method . '\' endpoint';
|
||||||
|
|
||||||
|
try {
|
||||||
|
$hc = new Healthchecks(config('integrations.healthchecks_uuid'));
|
||||||
|
if($method == 'success') {
|
||||||
|
$hc->success();
|
||||||
|
}
|
||||||
|
|
||||||
|
if($method == 'fail') {
|
||||||
|
$hc->fail();
|
||||||
|
}
|
||||||
|
|
||||||
|
if($method == 'start') {
|
||||||
|
$hc->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'method' => $methodResp,
|
||||||
|
'success' => true
|
||||||
|
], 200);
|
||||||
|
} catch(InvalidUuidStringException $e) {
|
||||||
|
return response()->json([
|
||||||
|
'method' => $methodResp,
|
||||||
|
'success' => false,
|
||||||
|
'error' => 'Invalid UUID'
|
||||||
|
], 422);
|
||||||
|
} catch(HealthchecksUuidNotFoundException $e) {
|
||||||
|
return response()->json([
|
||||||
|
'method' => $methodResp,
|
||||||
|
'success' => false,
|
||||||
|
'error' => 'UUID not found'
|
||||||
|
], 404);
|
||||||
|
} catch(Exception $e) {
|
||||||
|
return response()->json([
|
||||||
|
'method' => $methodResp,
|
||||||
|
'success' => false,
|
||||||
|
'error' => $e->getMessage()
|
||||||
|
], 422);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trigger a test of all notification agents
|
||||||
|
*
|
||||||
|
* @return JsonResponse
|
||||||
|
*/
|
||||||
|
public function testNotification()
|
||||||
|
{
|
||||||
|
SettingsHelper::testNotification();
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'method' => 'test notificaiton agents'
|
||||||
|
], 200);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -70,7 +70,9 @@ Route::group([
|
|||||||
], function () {
|
], function () {
|
||||||
Route::get('/config', 'SettingsController@config')
|
Route::get('/config', 'SettingsController@config')
|
||||||
->name('settings.config');
|
->name('settings.config');
|
||||||
Route::get('/test-notification', 'SettingsController@testNotification')
|
Route::get('/test-notification', 'IntegrationsController@testNotification')
|
||||||
|
->name('settings.test_notification');
|
||||||
|
Route::get('/test-healthchecks/{method}', 'IntegrationsController@testHealthchecks')
|
||||||
->name('settings.test_notification');
|
->name('settings.test_notification');
|
||||||
Route::get('/', 'SettingsController@index')
|
Route::get('/', 'SettingsController@index')
|
||||||
->name('settings.index');
|
->name('settings.index');
|
||||||
|
|||||||
Reference in New Issue
Block a user