Application health
The application health check reads a health endpoint in the Oh Dear format and shows each reported component. With the spatie security advisories check, it also lists the site’s open security advisories.
Report security advisories from a Laravel site
Section titled “Report security advisories from a Laravel site”Run these steps in the site’s Laravel project.
-
Install the packages:
Terminal window composer require spatie/laravel-health spatie/security-advisories-health-checkphp artisan vendor:publish --tag="health-config"php artisan vendor:publish --tag="health-migrations"php artisan migrate -
In
config/health.php, set'enabled' => trueunderoh_dear_endpoint. -
Add a long random secret to the site’s
.env:OH_DEAR_HEALTH_CHECK_SECRET=replace-with-a-long-random-secret -
In
app/Providers/AppServiceProvider.php, add the two imports and callHealth::checks()in thebootmethod:use Spatie\Health\Facades\Health;use Spatie\SecurityAdvisoriesHealthCheck\SecurityAdvisoriesCheck;Health::checks([SecurityAdvisoriesCheck::new()->cacheResultsForMinutes(60),]); -
Deploy the site.
Result: https://example.com/oh-dear-health-check-results answers with JSON when the request sends the secret in the oh-dear-health-check-secret header. Without the header it answers 403.
The cache keeps the site from asking Packagist for advisories on every check run. On PHP 8.2, Composer installs version 1.2 of the check, which has no cacheResultsForMinutes(): use SecurityAdvisoriesCheck::new() without it. Keep the default check name SecurityAdvisories: Heptapod lists advisories only for a component with that name.
Connect the endpoint
Section titled “Connect the endpoint”- Open the site and select Settings.
- Turn on Application health. The Check settings sheet opens.
- Enter the endpoint URL in URL, for example
https://example.com/oh-dear-health-check-results. - Enter the secret from the site’s
.envin Shared secret. - Select Apply, then Save.
Result: after the first run, the Application health tab lists the reported components.
Security advisories
Section titled “Security advisories”An open advisory makes the Security advisories component Failed. The check then follows the usual failure alerts.
- The component shows one row per package with its highest severity and the advisory count. The most severe package is open first.
- An open package lists each advisory: severity when known, title with a link to the advisory, CVE when known, affected versions and report date.
- Sites affected opens the Sites list filtered to that package.
- On the Sites list, the advisories filter set to With advisories shows every site with at least one open advisory.
- A run that reports no advisories clears the list and removes the site from the filter.
- A Check error or a skipped advisories result keeps the last reported advisories.
Results
Section titled “Results”The worst component sets the check result.
| Result | When |
|---|---|
| Failed | At least one component reports failed or crashed. |
| Warning | At least one component reports warning, and none failed. |
| Check error | The endpoint is unreachable, redirects, returns an error status or invalid JSON, or is stale. |
- A
skippedcomponent is unverified and never counts as healthy. - A redirect is a Check error: enter the final address as URL.
Settings
Section titled “Settings”| Setting | API key | Default | Values |
|---|---|---|---|
| URL | result_url |
none | An http or https URL |
| Shared secret | secret |
none | Sent in the oh-dear-health-check-secret header |
| Request headers | headers |
none | Extra headers as name and value pairs; values stay encrypted |