PHP code example of roundly-consulting / alerts-for-laravel
1. Go to this page and download the library: Download roundly-consulting/alerts-for-laravel library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
roundly-consulting / alerts-for-laravel example snippets
use RoundlyConsulting\Alerts\Checks\DatabaseCheck;
use RoundlyConsulting\Alerts\Checks\HttpPingCheck;
use RoundlyConsulting\Alerts\Facades\Health;
Health::check(DatabaseCheck::make());
Health::check(HttpPingCheck::make('https://api.example.com')->timeout(5)->slowerThan(800));
use Closure;
use RoundlyConsulting\Alerts\Interfaces\HasNotifiablesForAlerts;
use RoundlyConsulting\Alerts\Traits\UsesHealthChecks;
final class Team extends Model implements HasNotifiablesForAlerts
{
use UsesHealthChecks;
public function forEachNotifiableForAlerts(Closure $callback): void
{
$this->members->each(fn (User $member) => $callback($member));
}
}
Health::for($team)->monitor(HttpPingCheck::class)
->everyFiveMinutes()
->failAfter(3) // open an alert only after 3 failures in a row
->save();
Health::for($team)->run(HttpPingCheck::class); // or run it now: a CheckResult
Health::report()->isHealthy(); // bool, across every scheduled check