ohdearapp/ohdear-php-sdk
Official PHP SDK for the Oh Dear monitoring API. Built on Saloon v4, it provides typed DTOs and convenient methods to manage monitors and more. Supports API token auth, configurable timeouts, and clear exceptions for validation and API errors.
Monitor, CheckSummary) simplify parsing API responses into structured PHP objects, reducing manual JSON handling.OhDear instance to App\Services\OhDearService for dependency injection).requestCheckRun() or createStatusPageUpdate() can be wrapped in Laravel queues for async processing (e.g., delaying maintenance windows).config/services.php or environment variables). Risk: Hardcoded tokens in code.Illuminate\Support\Facades\Cache for monitor lists).ValidationException, OhDearException), but custom error mapping may be needed for Laravel’s App\Exceptions\Handler.Monitor DTO), the SDK may lag. Fork and maintain if critical.AppServiceProvider.OhDear facade for cleaner syntax (e.g., OhDear::monitors()).php artisan ohdear:create-monitor).createStatusPageUpdate) should use Laravel Queues with OhDearJob.deploying) to trigger maintenance windows:
public function handle(Deploying $event) {
OhDear::startMaintenancePeriod($monitorId, 3600, 'Deployment');
}
OhDear::monitors(), OhDear::checkSummary()) to validate API responses.monitors table) for offline access.createMonitor, updateStatusPage).OhDear::monitors() every 5 mins).guzzlehttp/guzzle (Saloon’s dependency) aligns with Laravel’s version.OhDear\PhpSdk).composer require ohdearapp/ohdear-php-sdk..env:
OHDEAR_API_TOKEN=your_token_here
AppServiceProvider:
$this->app->singleton(OhDear::class, function ($app) {
return new OhDear(config('services.ohdear.token'));
});
require scripts to auto-update:
"scripts": {
"post-update-cmd": "php artisan vendor:publish --provider=\"OhDear\\PhpSdk\\OhDearServiceProvider\" --tag=\"config\""
}
config/services.php:
'ohdear' => [
'token' => env('OHDEAR_API_TOKEN'),
'timeout' => env('OHDEAR_TIMEOUT', 10),
],
$ohDear = new OhDear(config('services.ohdear.token'), debug: true);
Log facade to track errors:
try {
$ohDear->createMonitor([...]);
} catch (OhDearException $e) {
Log::error('Oh Dear API error', ['exception' => $e]);
}
429 Too Many Requests).OhDear::monitors()) with Cache::remember.async helper for non-critical SDK calls:
OhDear::requestCheckRun($checkId)->onQueue('ohdear');
| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Oh Dear API downtime | Monitoring/data unavailability | Local cache + fallback to custom checks |
| API token revoked | All SDK calls fail | Rotate tokens via Laravel’s env + CI/CD |
| Rate limiting | Throttled requests | Implement retry logic + caching |
| SDK version lag | Broken API calls | Fork SDK or use API directly via Guzzle |
| Data desync (e.g., deleted monitor) | Stale local data | Implement reconciliation jobs |
laravel-ohdear-starter template with:
How can I help you explore Laravel packages today?