devolicious/oh-dear-app-health-bundle
Install the package via Composer:
composer require devolicious/oh-dear-app-health-bundle
Publish the configuration file to customize thresholds and behavior:
php artisan vendor:publish --provider="Devolicious\OhDearBundle\OhDearServiceProvider" --tag="config"
The package integrates with Oh Dear to monitor Laravel application health. After configuration, register the service provider in config/app.php under providers:
Devolicious\OhDearBundle\OhDearServiceProvider::class,
The first use case is monitoring uptime and critical errors. Configure your Oh Dear API key in .env:
OH_DEAR_API_KEY=your_api_key_here
Then define health checks in config/oh-dear.php:
'checks' => [
'uptime' => [
'enabled' => true,
'threshold' => 99.9, // New in 1.0.1: Configurable expiration threshold
],
'database' => [
'enabled' => true,
],
],
Run the health check manually:
php artisan oh-dear:check
app/Console/Kernel.php):
protected function schedule(Schedule $schedule)
{
$schedule->command('oh-dear:check')->everyFiveMinutes();
}
namespace App\Checks;
use Devolicious\OhDearBundle\Contracts\HealthCheck;
class CustomCheck implements HealthCheck
{
public function check(): bool
{
// Custom logic
return true;
}
}
Register it in config/oh-dear.php:
'custom_checks' => [
App\Checks\CustomCheck::class,
],
Use the Oh Dear API to dynamically fetch or update thresholds:
$threshold = config('oh-dear.checks.uptime.threshold');
$response = Http::post('https://api.ohdear.app/thresholds', [
'threshold' => $threshold,
]);
threshold setting in 1.0.1 applies to expiration logic (e.g., marking checks as failed if uptime drops below the threshold). Ensure it aligns with Oh Dear's API expectations (default: 99.9).config/oh-dear-local.php) to override thresholds per environment.Http::fake([
'api.ohdear.app/*' => Http::response([], 200),
]);
config/oh-dear.php:
'log_checks' => true,
Logs will appear in storage/logs/laravel.log.OhDearEventService to handle webhook payloads from Oh Dear:
namespace App\Listeners;
use Devolicious\OhDearBundle\Events\OhDearWebhookReceived;
class HandleOhDearWebhook
{
public function handle(OhDearWebhookReceived $event)
{
// Custom logic (e.g., Slack notifications)
}
}
Register the listener in EventServiceProvider:
protected $listen = [
OhDearWebhookReceived::class => [
HandleOhDearWebhook::class,
],
];
.env and validate the key exists:
if (empty(config('services.oh-dear.api_key'))) {
throw new \RuntimeException('Oh Dear API key not configured.');
}
How can I help you explore Laravel packages today?