Skip to content

Send alert to email, microsoft teams from laravel app, when an exception occurs. Throttle is enabled by default.

License

Notifications You must be signed in to change notification settings

trafficgate/laravel-alert-notifications

 
 

Repository files navigation

Laravel Alert Notifications

Travis Build Status Quality Score Build Status Coverage Status

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
Email Supported
Microsoft Teams Supported
Slack Supported
Pager Duty Open to pull requests

Installation Laravel

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
]

Tests

composer install
composer run test

Publish

php artisan vendor:publish --provider="Kevincobain2000\LaravelAlertNotifications\AlertNotificationsServiceProvider"
php aritsan config:cache

Env

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=

Usage

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

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

Samples

Email

Teams

Slack

References

  1. https://qiita.com/kidatti/items/8732114ec4d1727844b8
  2. https://laravel-news.com/email-on-error-exceptions

About

Send alert to email, microsoft teams from laravel app, when an exception occurs. Throttle is enabled by default.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 81.8%
  • HTML 18.2%