Installation
composer require bitbirddev/oh-dear-bundle
Add to config/app.php under providers:
BitbirdDev\OhDearBundle\OhDearBundle::class,
Publish Config
php artisan vendor:publish --provider="BitbirdDev\OhDearBundle\OhDearBundle" --tag="config"
This generates config/oh-dear.php. Configure your Oh Dear API key and project ID.
First Use Case: Health Check
Create a health check endpoint in routes/web.php:
use BitbirdDev\OhDearBundle\Http\Controllers\HealthCheckController;
Route::get('/health', [HealthCheckController::class, 'index']);
Visit /health to verify the endpoint works. Oh Dear will now monitor this URL.
Health Check Customization Extend the default health check by creating a custom check class:
namespace App\Checks;
use BitbirdDev\OhDearBundle\Checks\CheckInterface;
class DatabaseCheck implements CheckInterface
{
public function check(): bool
{
return DB::connection()->getPdo();
}
public function description(): string
{
return 'Database connection';
}
}
Register it in config/oh-dear.php:
'checks' => [
\App\Checks\DatabaseCheck::class,
],
Monitoring Multiple Environments
Use environment-specific configurations via .env:
OH_DEAR_PROJECT_ID=prod_123
OH_DEAR_API_KEY=prod_key
For staging:
OH_DEAR_PROJECT_ID=staging_456
OH_DEAR_API_KEY=staging_key
Integrating with Laravel Scheduler Automate health checks via cron:
// app/Console/Kernel.php
protected function schedule(Schedule $schedule)
{
$schedule->command('oh-dear:check')->hourly();
}
use BitbirdDev\OhDearBundle\Facades\OhDear;
if (!OhDear::check('database')) {
Notification::route('mail', 'admin@example.com')
->notify(new HealthCheckFailed('Database'));
}
// app/Console/Kernel.php
$schedule->command('oh-dear:check')->onOneServer()->everyMinute();
API Key Misconfiguration
php artisan oh-dear:validate
storage/logs/laravel.log for OhDearException.Caching Headaches
/health or use Cache::forget() before checks:
Cache::forget('health_check_cache');
Environment-Specific Checks
public function check(): bool
{
return app()->environment('production') ? $this->prodCheck() : true;
}
Enable Verbose Logging
Add to config/oh-dear.php:
'debug' => env('APP_DEBUG', false),
Logs detailed check results to storage/logs/oh-dear.log.
Manual Check Trigger Run checks manually for testing:
php artisan oh-dear:check --force
Custom Check Metrics
Extend CheckInterface to return metrics:
public function metrics(): array
{
return [
'database_latency' => DB::select('SELECT NOW()')[0]->NOW(),
];
}
Webhook Integration Listen to Oh Dear webhooks for real-time alerts:
// routes/web.php
Route::post('/oh-dear/webhook', [OhDearWebhookController::class, 'handle']);
Slack/Teams Notifications
Use Laravel’s via() method in notifications:
public function via($notifiable)
{
return ['SlackMessage'];
}
How can I help you explore Laravel packages today?