From 532837621fde3e9c63c37cf86c6020208a7bfea7 Mon Sep 17 00:00:00 2001 From: Henry Whitaker Date: Sat, 15 Aug 2020 15:36:02 +0100 Subject: [PATCH] Added controller endpoints for testing healthchecks settings --- .../Controllers/IntegrationsController.php | 77 +++++++++++++++++++ routes/api.php | 4 +- 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 app/Http/Controllers/IntegrationsController.php diff --git a/app/Http/Controllers/IntegrationsController.php b/app/Http/Controllers/IntegrationsController.php new file mode 100644 index 00000000..810a79b8 --- /dev/null +++ b/app/Http/Controllers/IntegrationsController.php @@ -0,0 +1,77 @@ +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); + } +} diff --git a/routes/api.php b/routes/api.php index 2bbe7f1f..a254328b 100644 --- a/routes/api.php +++ b/routes/api.php @@ -70,7 +70,9 @@ Route::group([ ], function () { Route::get('/config', 'SettingsController@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'); Route::get('/', 'SettingsController@index') ->name('settings.index');