forked from pelican-dev/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'pelican-dev:main' into main
- Loading branch information
Showing
10 changed files
with
669 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace App\Checks; | ||
|
||
use App\Models\Node; | ||
use App\Services\Helpers\SoftwareVersionService; | ||
use Spatie\Health\Checks\Check; | ||
use Spatie\Health\Checks\Result; | ||
use Spatie\Health\Enums\Status; | ||
|
||
class NodeVersionsCheck extends Check | ||
{ | ||
public function __construct(private SoftwareVersionService $versionService) {} | ||
|
||
public function run(): Result | ||
{ | ||
$all = Node::query()->count(); | ||
|
||
if ($all === 0) { | ||
$result = Result::make()->notificationMessage('No Nodes created')->shortSummary('No Nodes'); | ||
$result->status = Status::skipped(); | ||
|
||
return $result; | ||
} | ||
|
||
$latestVersion = $this->versionService->latestWingsVersion(); | ||
|
||
$outdated = Node::query()->get() | ||
->filter(fn (Node $node) => !isset($node->systemInformation()['exception']) && $node->systemInformation()['version'] !== $latestVersion) | ||
->count(); | ||
|
||
$result = Result::make() | ||
->meta([ | ||
'all' => $all, | ||
'outdated' => $outdated, | ||
]) | ||
->shortSummary($outdated === 0 ? 'All up-to-date' : "{$outdated}/{$all} outdated"); | ||
|
||
return $outdated === 0 | ||
? $result->ok('All Nodes are up-to-date.') | ||
: $result->failed(':outdated/:all Nodes are outdated.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace App\Checks; | ||
|
||
use App\Services\Helpers\SoftwareVersionService; | ||
use Spatie\Health\Checks\Check; | ||
use Spatie\Health\Checks\Result; | ||
|
||
class PanelVersionCheck extends Check | ||
{ | ||
public function __construct(private SoftwareVersionService $versionService) {} | ||
|
||
public function run(): Result | ||
{ | ||
$isLatest = $this->versionService->isLatestPanel(); | ||
$currentVersion = $this->versionService->currentPanelVersion(); | ||
$latestVersion = $this->versionService->latestPanelVersion(); | ||
|
||
$result = Result::make() | ||
->meta([ | ||
'isLatest' => $isLatest, | ||
'currentVersion' => $currentVersion, | ||
'latestVersion' => $latestVersion, | ||
]) | ||
->shortSummary($isLatest ? 'up-to-date' : 'outdated'); | ||
|
||
return $isLatest | ||
? $result->ok('Panel is up-to-date.') | ||
: $result->failed('Installed version is `:currentVersion` but latest is `:latestVersion`.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace App\Checks; | ||
|
||
use Spatie\Health\Checks\Checks\UsedDiskSpaceCheck as BaseCheck; | ||
|
||
class UsedDiskSpaceCheck extends BaseCheck | ||
{ | ||
protected function getDiskUsagePercentage(): int | ||
{ | ||
$freeSpace = disk_free_space($this->filesystemName ?? '/'); | ||
$totalSpace = disk_total_space($this->filesystemName ?? '/'); | ||
|
||
return 100 - ($freeSpace * 100 / $totalSpace); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<?php | ||
|
||
namespace App\Filament\Admin\Pages; | ||
|
||
use Carbon\Carbon; | ||
use Filament\Actions\Action; | ||
use Filament\Notifications\Notification; | ||
use Filament\Pages\Page; | ||
use Illuminate\Support\Facades\Artisan; | ||
use Spatie\Health\Commands\RunHealthChecksCommand; | ||
use Spatie\Health\ResultStores\ResultStore; | ||
|
||
class Health extends Page | ||
{ | ||
protected static ?string $navigationIcon = 'tabler-heart'; | ||
|
||
protected static ?string $navigationGroup = 'Advanced'; | ||
|
||
protected static string $view = 'filament.pages.health'; | ||
|
||
// @phpstan-ignore-next-line | ||
protected $listeners = [ | ||
'refresh-component' => '$refresh', | ||
]; | ||
|
||
protected function getActions(): array | ||
{ | ||
return [ | ||
Action::make('refresh') | ||
->button() | ||
->action('refresh'), | ||
]; | ||
} | ||
|
||
protected function getViewData(): array | ||
{ | ||
// @phpstan-ignore-next-line | ||
$checkResults = app(ResultStore::class)->latestResults(); | ||
|
||
if ($checkResults === null) { | ||
Artisan::call(RunHealthChecksCommand::class); | ||
|
||
$this->dispatch('refresh-component'); | ||
} | ||
|
||
return [ | ||
'lastRanAt' => new Carbon($checkResults?->finishedAt), | ||
'checkResults' => $checkResults, | ||
]; | ||
} | ||
|
||
public function refresh(): void | ||
{ | ||
Artisan::call(RunHealthChecksCommand::class); | ||
|
||
$this->dispatch('refresh-component'); | ||
|
||
Notification::make() | ||
->title('Health check results refreshed') | ||
->success() | ||
->send(); | ||
} | ||
|
||
public static function getNavigationBadge(): ?string | ||
{ | ||
// @phpstan-ignore-next-line | ||
$results = app(ResultStore::class)->latestResults(); | ||
|
||
if ($results === null) { | ||
return null; | ||
} | ||
|
||
$results = json_decode($results->toJson(), true); | ||
|
||
$failed = array_reduce($results['checkResults'], function ($numFailed, $result) { | ||
return $numFailed + ($result['status'] === 'failed' ? 1 : 0); | ||
}, 0); | ||
|
||
return $failed === 0 ? null : (string) $failed; | ||
} | ||
|
||
public static function getNavigationBadgeColor(): string | ||
{ | ||
return self::getNavigationBadge() > null ? 'danger' : ''; | ||
} | ||
|
||
public static function getNavigationBadgeTooltip(): ?string | ||
{ | ||
// @phpstan-ignore-next-line | ||
$results = app(ResultStore::class)->latestResults(); | ||
|
||
if ($results === null) { | ||
return null; | ||
} | ||
|
||
$results = json_decode($results->toJson(), true); | ||
|
||
$failedNames = array_reduce($results['checkResults'], function ($carry, $result) { | ||
if ($result['status'] === 'failed') { | ||
$carry[] = $result['name']; | ||
} | ||
|
||
return $carry; | ||
}, []); | ||
|
||
return 'Failed: ' . implode(', ', $failedNames); | ||
} | ||
|
||
public static function getNavigationIcon(): string | ||
{ | ||
// @phpstan-ignore-next-line | ||
$results = app(ResultStore::class)->latestResults(); | ||
|
||
if ($results === null) { | ||
return 'tabler-heart-question'; | ||
} | ||
|
||
return $results->containsFailingCheck() ? 'tabler-heart-exclamation' : 'tabler-heart-check'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.