Via Oh Dear | laravel-health | Spatie

 SPATIE

  Laravel Health
=================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-health](https://spatie.be/docs/laravel-health/v1)  Configuring-notifications  Via Oh Dear

 Version   v1

 Other versions for crawler [v1](https://spatie.be/docs/laravel-health/v1)

- [ Introduction ](https://spatie.be/docs/laravel-health/v1/introduction)
- [ Support us ](https://spatie.be/docs/laravel-health/v1/support-us)
- [ Requirements ](https://spatie.be/docs/laravel-health/v1/requirements)
- [ Installation &amp; setup ](https://spatie.be/docs/laravel-health/v1/installation-setup)
- [ Questions and issues ](https://spatie.be/docs/laravel-health/v1/questions-issues)
- [ Changelog ](https://spatie.be/docs/laravel-health/v1/changelog)
- [ About us ](https://spatie.be/docs/laravel-health/v1/about-us)

Usage
-----

- [ Registering your first check ](https://spatie.be/docs/laravel-health/v1/basic-usage/registering-your-first-check)
- [ Creating custom checks ](https://spatie.be/docs/laravel-health/v1/basic-usage/creating-custom-checks)
- [ Manually running checks ](https://spatie.be/docs/laravel-health/v1/basic-usage/manually-running-checks)
- [ Conditionally running or modifying checks ](https://spatie.be/docs/laravel-health/v1/basic-usage/conditionally-running-or-modifying-checks)
- [ Endpoints ](https://spatie.be/docs/laravel-health/v1/basic-usage/endpoints)
- [ Pausing and resuming checks ](https://spatie.be/docs/laravel-health/v1/basic-usage/pausing-and-resuming-checks)
- [ Registering the same check multiple times ](https://spatie.be/docs/laravel-health/v1/basic-usage/registering-the-same-check-multiple-times)
- [ Testing ](https://spatie.be/docs/laravel-health/v1/basic-usage/testing)

Storing results
---------------

- [ General ](https://spatie.be/docs/laravel-health/v1/storing-results/general)
- [ As JSON ](https://spatie.be/docs/laravel-health/v1/storing-results/in-a-json-file)
- [ In the cache ](https://spatie.be/docs/laravel-health/v1/storing-results/in-cache)
- [ In the database ](https://spatie.be/docs/laravel-health/v1/storing-results/in-the-database)
- [ Not storing results ](https://spatie.be/docs/laravel-health/v1/storing-results/not-storing-results)

Configuring notifications
-------------------------

- [ General ](https://spatie.be/docs/laravel-health/v1/configuring-notifications/general)
- [ Via mail ](https://spatie.be/docs/laravel-health/v1/configuring-notifications/via-mail)
- [ Via Slack ](https://spatie.be/docs/laravel-health/v1/configuring-notifications/via-slack)
- [ Via Oh Dear ](https://spatie.be/docs/laravel-health/v1/configuring-notifications/via-oh-dear)

Viewing check results
---------------------

- [ General ](https://spatie.be/docs/laravel-health/v1/viewing-results/general)
- [ On a webpage ](https://spatie.be/docs/laravel-health/v1/viewing-results/on-a-webpage)
- [ On the CLI ](https://spatie.be/docs/laravel-health/v1/viewing-results/on-the-cli)
- [ As JSON ](https://spatie.be/docs/laravel-health/v1/viewing-results/as-json)

Available checks
----------------

- [ Overview ](https://spatie.be/docs/laravel-health/v1/available-checks/overview)
- [ Backups ](https://spatie.be/docs/laravel-health/v1/available-checks/backups)
- [ Application Cache ](https://spatie.be/docs/laravel-health/v1/available-checks/cache)
- [ Cached config, routes, and events ](https://spatie.be/docs/laravel-health/v1/available-checks/cached-config-routes-and-events)
- [ CPU load ](https://spatie.be/docs/laravel-health/v1/available-checks/cpu-load)
- [ DB connection ](https://spatie.be/docs/laravel-health/v1/available-checks/db-connection)
- [ DB connection count ](https://spatie.be/docs/laravel-health/v1/available-checks/db-connection-count)
- [ DB size ](https://spatie.be/docs/laravel-health/v1/available-checks/db-size-check)
- [ DB table size ](https://spatie.be/docs/laravel-health/v1/available-checks/db-table-size-check)
- [ Debug mode ](https://spatie.be/docs/laravel-health/v1/available-checks/debug-mode)
- [ Environment ](https://spatie.be/docs/laravel-health/v1/available-checks/environment)
- [ Flare error count ](https://spatie.be/docs/laravel-health/v1/available-checks/flare-error-count)
- [ Horizon ](https://spatie.be/docs/laravel-health/v1/available-checks/horizon)
- [ Meilisearch ](https://spatie.be/docs/laravel-health/v1/available-checks/meilisearch)
- [ Ping ](https://spatie.be/docs/laravel-health/v1/available-checks/ping)
- [ Queue ](https://spatie.be/docs/laravel-health/v1/available-checks/queue)
- [ Redis ](https://spatie.be/docs/laravel-health/v1/available-checks/redis)
- [ Redis memory usage ](https://spatie.be/docs/laravel-health/v1/available-checks/redis-memory-usage)
- [ Schedule ](https://spatie.be/docs/laravel-health/v1/available-checks/schedule)
- [ Security advisories ](https://spatie.be/docs/laravel-health/v1/available-checks/security-advisories)
- [ Used disk space ](https://spatie.be/docs/laravel-health/v1/available-checks/used-disk-space)

Security
--------

- [ Using Secret Token ](https://spatie.be/docs/laravel-health/v1/security/using-secret-token)

 Via Oh Dear
===========

###  On this page

1. [ Adding a health check endpoint to your Laravel app ](#content-adding-a-health-check-endpoint-to-your-laravel-app)
2. [ Adding health checks ](#content-adding-health-checks)
3. [ Configuring the health check at Oh Dear ](#content-configuring-the-health-check-at-oh-dear)
4. [ Avoid stored results and sending notifications locally ](#content-avoid-stored-results-and-sending-notifications-locally)

In certain scenario's, your application can be in such a bad state, that it can't send any notifications anymore. A possible solution is to let [Oh Dear](https://ohdear.app) monitor your checks, and let that service send notifications for you.

Using Oh Dear unlocks some more options: you'll be able to snooze notifications, and there are more delivery channels such as Telegram, Discord, MS Teams, Webhooks and more.

Using this package, you can register a protected endpoint where [the application health check of Oh Dear](https://ohdear.app/docs/features/application-health-monitoring) can read the latest results of the health checks.

Adding a health check endpoint to your Laravel app
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Oh Dear will send an HTTP request to your application to a specific endpoint to get health check. Your application should respond with JSON containing the result of health checks.

You can add such an endpoint using the spatie/laravel-health package. To do this, must configure the values within the `oh_dear_endpoint` key in the `health` config file.

You can publish that `health` file with this command:

```
php artisan vendor:publish --tag="health-config"
```

These are some of the default values in the published `health` config file.

```
// in app/config/health.php

/*
 * You can let Oh Dear monitor the results of all health checks. This way, you'll
 * get notified of any problems even if your application goes totally down. Via
 * Oh Dear, you can also have access to more advanced notification options.
 */
'oh_dear_endpoint' => [
    'enabled' => false,

    /*
     * When this option is enabled, the checks will run before sending a response.
     * Otherwise, we'll send the results from the last time the checks have run.
     */
    'always_send_fresh_results' => true,

    /*
     * The secret that is displayed at the Application Health settings at Oh Dear.
     */
    'secret' => env('OH_DEAR_HEALTH_CHECK_SECRET'),

    /*
     * The URL that should be configured in the Application health settings at Oh Dear.
     */
    'url' => '/oh-dear-health-check-results',
],
```

To get started (all options within `oh_dear_endpoint` key):

- set the `enabled` config option to `true`
- add a `secret` (we recommend putting it in the `.env` file, just like you would do for any application secret or password)
- optionally customize the `url` where the health check endpoint will be registered.

Adding health checks
--------------------------------------------------------------------------------------------------------------------

Now that you have registered an endpoint, let's add some checks to your app. To learn how to do this, head over to the [Registering your first check page in the laravel-health docs](https://spatie.be/docs/laravel-health/v1/basic-usage/registering-your-first-check).

Configuring the health check at Oh Dear
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

In the application health check settings screen of a site at Oh Dear, you should fill in the URL and secret that you specified in the `health` config file.

Avoid stored results and sending notifications locally
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Oh Dear will notify you when something goes wrong with one of your health checks, so you can safely disable the notifications sent by the package itself.

You can set the `notifications.enabled` option to `false`.

```
'notifications' => [
    /*
     * Notifications will only get sent if this option is set to `true`.
     */
    'enabled' => false,
```

If you don't want to keep health results in your local application, set the `result_stores` option in the `health` config file to the `InMemoryHealthResultStore`.

```
// in app/config/health.php

'result_stores' => [
     Spatie\Health\ResultStores\InMemoryHealthResultStore::class,
],
```
