Send php exceptions to email, microsoft teams, slack. Notifications are throttle enabled so devs don't get a lot of emails from one host (or all hosts if cache driver is shared) Please check config for more details on throttling.
Channels | Progress |
---|---|
Supported | |
Microsoft Teams | Supported |
Slack | Supported |
Pager Duty | Open to pull requests |
composer require kevincobain2000/laravel-alert-notifications
If you're using Laravel 5.5+ let the package auto discovery make this for you.
'providers' => [
\Kevincobain2000\LaravelAlertNotifications\AlertNotificationsServiceProvider::class
]
composer install
composer run test
php artisan vendor:publish --provider="Kevincobain2000\LaravelAlertNotifications\AlertNotificationsServiceProvider"
php aritsan config:cache
ALERT_NOTIFICATION_MAIL_FROM_ADDRESS=
ALERT_NOTIFICATION_MAIL_TO_ADDRESS=
ALERT_NOTIFICATION_CACHE_DRIVER=file
ALERT_NOTIFICATION_MICROSOFT_TEAMS_WEBHOOK=https://outlook.office.com/webhook/.........
ALERT_NOTIFICATION_SLACK_WEBHOOK=https://hooks.slack.com/...
ALERT_NOTIFICATION_CURL_PROXY=
In app/Exceptions/Handler.php. It is better to use a try catch to prevent loop
use Kevincobain2000\LaravelAlertNotifications\Dispatcher\AlertDispatcher;
class Handler extends ExceptionHandler
{
protected $dontReport = [
//
];
public function report(Exception $exception)
{
try {
$dontReport = array_merge($this->dontReport, $this->internalDontReport);
$alertDispatcher = new AlertDispatcher($exception, $dontReport);
$alertDispatcher->notify();
} catch (Exception $e) {
// do nothing
}
parent::report($exception);
}
}
config/env key | purpose |
---|---|
throttle_enabled | (default true) If false then library will send alerts without any throttling |
throttle_duration_minutes | (default 5 mins) If an exception has been notified |
This will next notify after 5 mins when same exception occurs | |
cache_prefix | This is a prefix for cache key. Your cache key will look like |
laravel-alert-notifications-ExceptionClass-ExceptionCode |
|
ALERT_NOTIFICATION_CURL_PROXY | If your slack/MS teams require proxy, then set it up accordingly |
email.enabled | (default true), false will not notify to email |
email.toAddress | (default null), null will not notify to email |
email.fromAddress | (default null), null will not notify to email |
microsoft_teams.enabled | (default true), false will not notify to teams |
microsoft_teams.webhook | (default null), null will not notify to teams |
slack.enabled | (default true), false will not notify to slack |
slack.webhook | (default null), null will not notify to slack |