ohdearapp/laravel-ohdear-webhooks
Laravel package to receive and verify Oh Dear webhooks. Easily register routes, validate signatures, and handle downtime, Uptime, broken links, and other monitoring events with customizable jobs/listeners so your app can react automatically to incidents.
Install the Package
composer require ohdearapp/laravel-ohdear-webhooks
Publish the config file:
php artisan vendor:publish --provider="OhDear\LaravelOhDearWebhooks\ServiceProvider" --tag="config"
Configure .env
Add your Oh Dear API key and webhook secret:
OHDEAR_API_KEY=your_api_key_here
OHDEAR_WEBHOOK_SECRET=your_webhook_secret_here
Verify Webhook Endpoint
Ensure your Laravel app’s routes/web.php includes:
use OhDear\LaravelOhDearWebhooks\Facades\OhDearWebhook;
Route::post('/ohdear-webhook', [OhDearWebhook::class, 'handle']);
First Use Case: Log Alerts
Define a listener in app/Listeners/OhDearAlertListener.php:
namespace App\Listeners;
use OhDear\LaravelOhDearWebhooks\Events\AlertReceived;
class OhDearAlertListener
{
public function handle(AlertReceived $event)
{
\Log::info('Oh Dear Alert:', [
'id' => $event->alert->id,
'type' => $event->alert->type,
'message' => $event->alert->message,
]);
}
}
Register the listener in EventServiceProvider:
protected $listen = [
AlertReceived::class => [
OhDearAlertListener::class,
],
];
Signature Verification
The package automatically verifies the X-OhDear-Signature header against your OHDEAR_WEBHOOK_SECRET. No manual validation needed.
Event-Driven Architecture
AlertReceived for monitoring alerts (e.g., downtime, SSL expiry).CheckUpdated for check status changes (e.g., "back online").OhDear\LaravelOhDearWebhooks\Contracts\WebhookEvent.Integration with Laravel Queues Offload processing by dispatching events to queues:
public function handle(AlertReceived $event)
{
dispatch(new ProcessOhDearAlert($event->alert))->onQueue('ohdear');
}
Dynamic Routing Override the default route by binding a custom controller:
Route::post('/custom-webhook', [CustomOhDearController::class, 'handle']);
| Use Case | Implementation Pattern |
|---|---|
| Slack Notifications | Listen to AlertReceived, post to Slack API. |
| Database Logging | Store alerts in alerts table via Eloquent. |
| Multi-Tenant Apps | Filter events by check->domain in listeners. |
| Retry Failed Checks | Use CheckUpdated to trigger cron jobs. |
Secret Mismatch
403 Forbidden.OHDEAR_WEBHOOK_SECRET in .env and Oh Dear dashboard.OHDEAR_DEBUG=true to log signature verification steps.Missing Events
auth or verified). Use:
Route::post('/ohdear-webhook')->middleware('webhook:ohdear')->name('ohdear.webhook');
Rate Limiting
use Symfony\Component\RateLimiter\RateLimiter;
$limiter = app(RateLimiter::class);
if (!$limiter->consume('ohdear_alerts', 10, now()->addMinute())) {
return; // Skip processing
}
Custom Payload Handling
Extend the OhDearWebhook facade to parse raw payloads:
namespace OhDear\LaravelOhDearWebhooks\Facades;
class OhDearWebhook extends \Illuminate\Support\Facades\Facade
{
public static function customPayload()
{
return request()->ohdear_payload ?? null;
}
}
Testing Webhooks
Use Laravel’s Http test client to simulate webhooks:
$response = $this->post('/ohdear-webhook', [], [
'HTTP_X_OHDEAR_SIGNATURE' => 'valid_signature',
'Accept' => 'application/json',
]);
$response->assertOk();
Performance
public function handle(AlertReceived $event)
{
AlertBatch::dispatch($event->alert)->onQueue('batch');
}
check->last_checked) to avoid redundant DB writes.Extension Points
OhDear\LaravelOhDearWebhooks\Contracts\WebhookValidator to add pre-processing logic.maintenance) by extending the WebhookEvent class.Configuration Quirks
OHDEAR_DEBUG=true to log raw payloads and signatures (useful for troubleshooting).env() helper or config() to load secrets dynamically:
config(['ohdear.secret' => env('OHDEAR_WEBHOOK_SECRET_' . app()->environment)]);
How can I help you explore Laravel packages today?