-
-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Init * Health Page * Admin API Keys * Update API Keys * Database Hosts * Mounts * remove `s` * Users * Webhooks * Server never again... * Fix Server * Settings * Update Mounts * Update Databasehost * Update Server * Oops, Update Server * Nodes * Update User * Dashboard * Update Server * Profile * Egg * Role & Update Egg * Add base Laravel lang files * update apikey * remove html back to settings, remove comment * add `:resource` to create_action * Update Egg * Update Egg v2 * Update 1 * trans cf info label * Update charts * more trans * Update Webhook * update Health * Update Server * Update Role * Fixes * Bulk Update * AnotherOne * Fix relation button label * rename `admin1` to `admin` Leftover from testing... oops * More Translations * Updates * `pint` + Relation Manager Titles
- Loading branch information
1 parent
513117c
commit f8ad720
Showing
594 changed files
with
2,080 additions
and
23,292 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,58 @@ | ||
<?php | ||
|
||
namespace App\Checks; | ||
|
||
use Exception; | ||
use Illuminate\Support\Facades\Cache; | ||
use Illuminate\Support\Str; | ||
use Spatie\Health\Checks\Check; | ||
use Spatie\Health\Checks\Result; | ||
|
||
class CacheCheck extends Check | ||
{ | ||
protected ?string $driver = null; | ||
|
||
public function driver(string $driver): self | ||
{ | ||
$this->driver = $driver; | ||
|
||
return $this; | ||
} | ||
|
||
public function run(): Result | ||
{ | ||
$driver = $this->driver ?? $this->defaultDriver(); | ||
|
||
$result = Result::make()->meta([ | ||
'driver' => $driver, | ||
]); | ||
|
||
try { | ||
return $this->canWriteValuesToCache($driver) | ||
? $result->ok(trans('admin/health.results.cache.ok')) | ||
: $result->failed(trans('admin/health.results.cache.failed_retrieve')); | ||
} catch (Exception $exception) { | ||
return $result->failed(trans('admin/health.results.cache.failed', ['error' => $exception->getMessage()])); | ||
} | ||
} | ||
|
||
protected function defaultDriver(): ?string | ||
{ | ||
return config('cache.default', 'file'); | ||
} | ||
|
||
protected function canWriteValuesToCache(?string $driver): bool | ||
{ | ||
$expectedValue = Str::random(5); | ||
|
||
$cacheName = "laravel-health:check-{$expectedValue}"; | ||
|
||
Cache::driver($driver)->put($cacheName, $expectedValue, 10); | ||
|
||
$actualValue = Cache::driver($driver)->get($cacheName); | ||
|
||
Cache::driver($driver)->forget($cacheName); | ||
|
||
return $actualValue === $expectedValue; | ||
} | ||
} |
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,42 @@ | ||
<?php | ||
|
||
namespace App\Checks; | ||
|
||
use Exception; | ||
use Illuminate\Support\Facades\DB; | ||
use Spatie\Health\Checks\Check; | ||
use Spatie\Health\Checks\Result; | ||
|
||
class DatabaseCheck extends Check | ||
{ | ||
protected ?string $connectionName = null; | ||
|
||
public function connectionName(string $connectionName): self | ||
{ | ||
$this->connectionName = $connectionName; | ||
|
||
return $this; | ||
} | ||
|
||
public function run(): Result | ||
{ | ||
$connectionName = $this->connectionName ?? $this->getDefaultConnectionName(); | ||
|
||
$result = Result::make()->meta([ | ||
'connection_name' => $connectionName, | ||
]); | ||
|
||
try { | ||
DB::connection($connectionName)->getPdo(); | ||
|
||
return $result->ok(trans('admin/health.results.database.ok')); | ||
} catch (Exception $exception) { | ||
return $result->failed(trans('admin/health.results.database.failed', ['error' => $exception->getMessage()])); | ||
} | ||
} | ||
|
||
protected function getDefaultConnectionName(): string | ||
{ | ||
return config('database.default'); | ||
} | ||
} |
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,44 @@ | ||
<?php | ||
|
||
namespace App\Checks; | ||
|
||
use Spatie\Health\Checks\Check; | ||
use Spatie\Health\Checks\Result; | ||
|
||
use function config; | ||
|
||
class DebugModeCheck extends Check | ||
{ | ||
protected bool $expected = false; | ||
|
||
public function expectedToBe(bool $bool): self | ||
{ | ||
$this->expected = $bool; | ||
|
||
return $this; | ||
} | ||
|
||
public function run(): Result | ||
{ | ||
$actual = config('app.debug'); | ||
|
||
$result = Result::make() | ||
->meta([ | ||
'actual' => $actual, | ||
'expected' => $this->expected, | ||
]) | ||
->shortSummary($this->convertToWord($actual)); | ||
|
||
return $this->expected === $actual | ||
? $result->ok() | ||
: $result->failed(trans('admin/health.results.debugmode.failed', [ | ||
'actual' => $this->convertToWord($actual), | ||
'expected' => $this->convertToWord($this->expected), | ||
])); | ||
} | ||
|
||
protected function convertToWord(bool $boolean): string | ||
{ | ||
return $boolean ? 'true' : 'false'; | ||
} | ||
} |
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,38 @@ | ||
<?php | ||
|
||
namespace App\Checks; | ||
|
||
use Illuminate\Support\Facades\App; | ||
use Spatie\Health\Checks\Check; | ||
use Spatie\Health\Checks\Result; | ||
|
||
class EnvironmentCheck extends Check | ||
{ | ||
protected string $expectedEnvironment = 'production'; | ||
|
||
public function expectEnvironment(string $expectedEnvironment): self | ||
{ | ||
$this->expectedEnvironment = $expectedEnvironment; | ||
|
||
return $this; | ||
} | ||
|
||
public function run(): Result | ||
{ | ||
$actualEnvironment = (string) App::environment(); | ||
|
||
$result = Result::make() | ||
->meta([ | ||
'actual' => $actualEnvironment, | ||
'expected' => $this->expectedEnvironment, | ||
]) | ||
->shortSummary($actualEnvironment); | ||
|
||
return $this->expectedEnvironment === $actualEnvironment | ||
? $result->ok(trans('admin/health.results.environment.ok')) | ||
: $result->failed(trans('admin/health.results.environment.failed', [ | ||
'actual' => $actualEnvironment, | ||
'expected' => $this->expectedEnvironment, | ||
])); | ||
} | ||
} |
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
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,78 @@ | ||
<?php | ||
|
||
namespace App\Checks; | ||
|
||
use Carbon\Carbon; | ||
use Composer\InstalledVersions; | ||
use Spatie\Health\Checks\Check; | ||
use Spatie\Health\Checks\Result; | ||
|
||
class ScheduleCheck extends Check | ||
{ | ||
protected string $cacheKey = 'health:checks:schedule:latestHeartbeatAt'; | ||
|
||
protected ?string $cacheStoreName = null; | ||
|
||
protected int $heartbeatMaxAgeInMinutes = 1; | ||
|
||
public function useCacheStore(string $cacheStoreName): self | ||
{ | ||
$this->cacheStoreName = $cacheStoreName; | ||
|
||
return $this; | ||
} | ||
|
||
public function getCacheStoreName(): string | ||
{ | ||
return $this->cacheStoreName ?? config('cache.default'); | ||
} | ||
|
||
public function cacheKey(string $cacheKey): self | ||
{ | ||
$this->cacheKey = $cacheKey; | ||
|
||
return $this; | ||
} | ||
|
||
public function heartbeatMaxAgeInMinutes(int $heartbeatMaxAgeInMinutes): self | ||
{ | ||
$this->heartbeatMaxAgeInMinutes = $heartbeatMaxAgeInMinutes; | ||
|
||
return $this; | ||
} | ||
|
||
public function getCacheKey(): string | ||
{ | ||
return $this->cacheKey; | ||
} | ||
|
||
public function run(): Result | ||
{ | ||
$result = Result::make()->ok(trans('admin/health.results.schedule.ok')); | ||
|
||
$lastHeartbeatTimestamp = cache()->store($this->cacheStoreName)->get($this->cacheKey); | ||
|
||
if (!$lastHeartbeatTimestamp) { | ||
return $result->failed(trans('admin/health.results.schedule.failed_not_ran')); | ||
} | ||
|
||
$latestHeartbeatAt = Carbon::createFromTimestamp($lastHeartbeatTimestamp); | ||
|
||
$carbonVersion = InstalledVersions::getVersion('nesbot/carbon'); | ||
|
||
$minutesAgo = $latestHeartbeatAt->diffInMinutes(); | ||
|
||
if (version_compare($carbonVersion, | ||
'3.0.0', '<')) { | ||
$minutesAgo += 1; | ||
} | ||
|
||
if ($minutesAgo > $this->heartbeatMaxAgeInMinutes) { | ||
return $result->failed(trans('admin/health.results.schedule.failed_last_ran', [ | ||
'time' => $minutesAgo, | ||
])); | ||
} | ||
|
||
return $result; | ||
} | ||
} |
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.