diff --git a/src/app/Console/Commands/Status/Health.php b/src/app/Console/Commands/Status/Health.php --- a/src/app/Console/Commands/Status/Health.php +++ b/src/app/Console/Commands/Status/Health.php @@ -22,7 +22,7 @@ * * @var string */ - protected $signature = 'status:health'; + protected $signature = 'status:health {--check=*: Valid checks are DB, Redis, IMAP, LDAP, Roundcube, Meet, DAV, Mollie, OpenExchangeRates}'; /** * The console command description. @@ -170,14 +170,17 @@ public function handle() { $result = 0; - $steps = [ - 'DB', 'Redis', 'IMAP', 'Roundcube', 'Meet', 'DAV', 'Mollie', 'OpenExchangeRates', - ]; - - if (\config('app.with_ldap')) { - array_unshift($steps, 'LDAP'); + $steps = $this->option('check'); + if (empty($steps)) { + $steps = [ + 'DB', 'Redis', 'IMAP', 'Roundcube', 'Meet', 'DAV', 'Mollie', 'OpenExchangeRates', + ]; + if (\config('app.with_ldap')) { + array_unshift($steps, 'LDAP'); + } } + foreach ($steps as $step) { $func = "check{$step}"; diff --git a/src/app/Http/Controllers/API/V4/HealthController.php b/src/app/Http/Controllers/API/V4/HealthController.php new file mode 100644 --- /dev/null +++ b/src/app/Http/Controllers/API/V4/HealthController.php @@ -0,0 +1,35 @@ + 'error', + 'output' => \Artisan::output() + ]; + + return response()->json($result, 500); + } + + $result = [ + 'status' => 'ok', + 'output' => \Artisan::output() + ]; + + return response()->json($result, 200); + } +} diff --git a/src/routes/api.php b/src/routes/api.php --- a/src/routes/api.php +++ b/src/routes/api.php @@ -219,6 +219,7 @@ Route::post('policy/greylist', [API\V4\PolicyController::class, 'greylist']); Route::post('policy/ratelimit', [API\V4\PolicyController::class, 'ratelimit']); Route::post('policy/spf', [API\V4\PolicyController::class, 'senderPolicyFramework']); + Route::get('health/status', [API\V4\HealthController::class, 'status']); } ); } diff --git a/src/tests/Feature/Controller/HealthTest.php b/src/tests/Feature/Controller/HealthTest.php new file mode 100644 --- /dev/null +++ b/src/tests/Feature/Controller/HealthTest.php @@ -0,0 +1,42 @@ +useServicesUrl(); + } + + /** + * {@inheritDoc} + */ + public function tearDown(): void + { + parent::tearDown(); + } + + /** + * Test webhook + */ + public function testStatus(): void + { + $response = $this->get("api/webhooks/health/status"); + $response->assertStatus(200); + + $json = $response->json(); + + $this->assertSame('ok', $json['status']); + $this->assertTrue(array_key_exists('output', $json)); + } +}