Page MenuHomePhorge

D4214.1775423050.diff
No OneTemporary

Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None

D4214.1775423050.diff

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 @@
+<?php
+
+namespace App\Http\Controllers\API\V4;
+
+use App\Http\Controllers\Controller;
+
+class HealthController extends Controller
+{
+ /**
+ * Run a health status check
+ *
+ * @return \Illuminate\Http\JsonResponse The response
+ */
+ public function status()
+ {
+ $code = \Artisan::call("status:health --check=DB --check=Redis");
+ if ($code != 0) {
+ \Log::info("Healthcheck failed");
+
+ $result = [
+ 'status' => '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 @@
+<?php
+
+namespace Tests\Feature\Controller;
+
+use Tests\TestCase;
+
+/**
+ * @group files
+ */
+class HealthTest extends TestCase
+{
+ /**
+ * {@inheritDoc}
+ */
+ public function setUp(): void
+ {
+ parent::setUp();
+ $this->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));
+ }
+}

File Metadata

Mime Type
text/plain
Expires
Sun, Apr 5, 9:04 PM (2 m, 36 s ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18832560
Default Alt Text
D4214.1775423050.diff (3 KB)

Event Timeline