ohdearapp/health-check-results
booted, scheduled:run) for periodic health checks.CheckResult objects, enabling granular monitoring.meta field in CheckResult could lead to runtime type inconsistencies if not validated.Artisan::call('down')) or augment them?php artisan health:check)./health endpoint).scheduler:run).CheckResults assertions.CheckResults.DB, Cache) without conflicts.composer require ohdearapp/health-check-results
app/Services/HealthCheckService) to aggregate CheckResult objects.use OhDearApp\HealthCheckResults\CheckResults;
use OhDearApp\HealthCheckResults\CheckResult;
public function runChecks(): CheckResults {
$results = new CheckResults(now());
$results->addCheckResult(new CheckResult(
name: 'DatabaseConnection',
label: 'Database Connectivity',
status: DB::connection()->getPdo() ? CheckResult::STATUS_OK : CheckResult::STATUS_FAILED,
notificationMessage: 'Database is unreachable!',
));
return $results;
}
GET /oh-dear-health) to return JSON:
Route::get('/oh-dear-health', function () {
return response()->json((new HealthCheckService())->runChecks());
});
$schedule->command('health:check')->hourly();
Log::error($checkResult->notificationMessage)).dd($results) to inspect payloads during development.| Failure Scenario | Mitigation |
|---|---|
| Oh Dear API downtime | Cache results locally (e.g., Redis) and retry. |
| Laravel app crashes | Use a separate process (e.g., supervisor) to run health checks. |
| Malformed JSON payload | Validate output with json_last_error() before sending. |
| High check frequency | Implement exponential backoff in Oh Dear webhook retries. |
| Missing critical checks | Add a requiredChecks array to validate all checks pass before STATUS_OK. |
How can I help you explore Laravel packages today?