Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bobimicroweber committed Dec 6, 2024
1 parent 887dbc2 commit 3fbd582
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
22 changes: 22 additions & 0 deletions web/Modules/Email/App/Enums/ServiceStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Modules\Email\App\Enums;

enum ServiceStatus: string
{
case ACTIVE = 'Active';
case RUNNING = 'Running';
case NOT_RUNNING = 'NotRunning';

case INACTIVE = 'Inactive';

public function color(): string
{
return match ($this) {
self::ACTIVE => 'success',
self::INACTIVE => 'danger',
self::RUNNING => 'success',
self::NOT_RUNNING => 'danger',
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Pages\Page;
use Filament\Tables\Columns\BadgeColumn;
use Filament\Tables\Columns\TextColumn;
use Modules\Email\App\Enums\ServiceStatus;
use Filament\Tables\Concerns\InteractsWithTable;
use Filament\Tables\Contracts\HasTable;
use Filament\Tables\Table;
Expand Down
17 changes: 12 additions & 5 deletions web/Modules/Email/App/Models/EmailHealthStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Modules\Email\App\Models;

use Illuminate\Database\Eloquent\Model;
use Modules\Email\App\Enums\ServiceStatus;
use Modules\Email\App\Services\EmailHealthService;
use Sushi\Sushi;

Expand All @@ -15,27 +16,33 @@ class EmailHealthStatus extends Model
'status' => 'string',
];

protected $casts = [
'status' => ServiceStatus::class,
];

public function getRows()
{
$service = new EmailHealthService();

return [
$rows = [
[
'service' => 'Dovecot',
'status' => $service->checkDovecotStatus(),
'status' => ServiceStatus::from($service->checkDovecotStatus()),
],
[
'service' => 'Postfix',
'status' => $service->checkPostfixStatus(),
'status' => ServiceStatus::from($service->checkPostfixStatus()),
],
[
'service' => 'OpenDKIM',
'status' => $service->checkOpenDkimStatus(),
'status' => ServiceStatus::from($service->checkOpenDkimStatus()),
],
[
'service' => 'Firewall',
'status' => $service->checkFirewallStatus(),
'status' => ServiceStatus::from($service->checkFirewallStatus()),
],
];

return $rows;
}
}
4 changes: 2 additions & 2 deletions web/Modules/Email/App/Services/EmailHealthService.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ public function checkOpenDkimStatus(): string

public function checkFirewallStatus(): string
{
return shell_exec('sudo ufw status');
return $this->checkServiceStatus('firewalld');
}

private function checkServiceStatus(string $serviceName): string
{
$status = shell_exec("systemctl is-active $serviceName");
return trim($status) === 'active' ? 'Running' : 'Not Running';
return trim($status) === 'active' ? 'Running' : 'NotRunning';
}
}

0 comments on commit 3fbd582

Please sign in to comment.