定制 kevincobain2000/laravel-alert-notifications 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

kevincobain2000/laravel-alert-notifications

Composer 安装命令:

composer require kevincobain2000/laravel-alert-notifications

包简介

Alert notifications of exceptions from your laravel application

README 文档

README

Laravel Alert Notifcations

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).

All Contributors

Channels Progress
Email Supported
Microsoft Teams Supported
Slack Supported
Pager Duty Supported

Installation

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 (Laravel)

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

Publish (Lumen)

Since Lumen doesn't support auto-discovery, move config and view files to the destination directories manually

cp vendor/kevincobain2000/laravel-alert-notifications/src/config/laravel_alert_notifications.php config/laravel_alert_notifications.php
mkdir -p "resources/views/vendor/laravel_alert_notifications/" && cp vendor/kevincobain2000/laravel-alert-notifications/src/views/* resources/views/vendor/laravel_alert_notifications/

and add the following to bootstrap/app.php:

$app->register(Kevincobain2000\LaravelAlertNotifications\AlertNotificationsServiceProvider::class);

.env

ALERT_NOTIFICATION_MAIL_FROM_ADDRESS=
ALERT_NOTIFICATION_MAIL_TO_ADDRESS=
ALERT_NOTIFICATION_MAIL_NOTICE_TO_ADDRESS=
ALERT_NOTIFICATION_MAIL_WARNING_TO_ADDRESS=
ALERT_NOTIFICATION_MAIL_ERROR_TO_ADDRESS=
ALERT_NOTIFICATION_MAIL_CRITICAL_TO_ADDRESS=
ALERT_NOTIFICATION_MAIL_ALERT_TO_ADDRESS=
ALERT_NOTIFICATION_MAIL_EMERGENCY_TO_ADDRESS=
ALERT_NOTIFICATION_CACHE_DRIVER=file
ALERT_NOTIFICATION_MICROSOFT_TEAMS_WEBHOOK=
ALERT_NOTIFICATION_SLACK_WEBHOOK=
ALERT_NOTIFICATION_PAGER_DUTY_INTEGRATION_KEY=
ALERT_NOTIFICATION_CURL_PROXY=

Usage

new AlertDispatcher(
    Exception $e
    [, array $dontAlertExceptions = []]         // Exceptions that shouldn't trigger notifications
    [, array $notificationLevelsMapping = []]   // [Exception class => Notification level] mapping
    [, array $exceptionContext = []]            // Array of context data
)

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
{
    private $exceptionLogLevels = [
        DebugLevelException::class => LogLevel::DEBUG,
        WarningLevelException::class => LogLevel::WARNING,
        ErrorLevelException::class => LogLevel::ERROR,
    ];

    protected $dontReport = [
        //
    ];

    public function report(Throwable $exception)
    {
        try {
            $dontReport = array_merge($this->dontReport, $this->internalDontReport);
            $alertDispatcher = new AlertDispatcher($exception, $dontReport, $this->exceptionLogLevels);
            $alertDispatcher->notify();
        } catch (Throwable $e) {
            // log any unexpected exceptions or 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
default_notification_level Default notification level
exclude_notification_levels Do not send notification if it is of one of the listed level
mail E-mail config array:
mail.enabled (default true), false will not notify to email
mail.fromAddress (default null), null will not notify to email
mail.toAddress Default recipient e-mail address
mail.subject Default e-mail subject. May contain placeholders replaced afterwards with
correspondent exception data:
%ExceptionMessage% => $e->getMessage()
%ExceptionCode% => $e->getCode()
%ExceptionType% => $e->getType()
%ExceptionLevel% => current notification level
ex. 'subject' => 'Exception [%ExceptionType%] has ocurred'
mail.#level# Configs for each notification level
notification levels refer to those defined in \Psr\Log\LogLevel
mail.#level#.toAddress (default mail.to_address), #level# notification recipient e-mail
mail.#level#.subject #level# notification e-mail subject
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
pager_duty.enabled (default true), false will not notify to pager duty
pager_duty.events_v2_endpoint (default https://events.pagerduty.com/v2/enqueue), should not need to change this
pager_duty.integration_key (default null), null with not notify to pager duty

Samples

Email

Email

Teams

Teams

Slack

Slack

Pager Duty

Pager Duty

References

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

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Aaron Brigham

⚠️ 💻

Alexander Hupe

👀 ⚠️ 💻

Kit Loong

👀 ⚠️ 💻

Andrew Miller

👀 ⚠️ 💻

Pulkit Kathuria

👀 ⚠️ 💻

Masashi

⚠️

This project follows the all-contributors specification. Contributions of any kind welcome!

kevincobain2000/laravel-alert-notifications 适用场景与选型建议

kevincobain2000/laravel-alert-notifications 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 22.14k 次下载、GitHub Stars 达 28, 最近一次更新时间为 2019 年 03 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「email」 「debugging」 「exception」 「laravel」 「exception-handling」 「laravel-package」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 kevincobain2000/laravel-alert-notifications 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 kevincobain2000/laravel-alert-notifications 我们能提供哪些服务?
定制开发 / 二次开发

基于 kevincobain2000/laravel-alert-notifications 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 22.14k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 28
  • 点击次数: 10
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 28
  • Watchers: 3
  • Forks: 9
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-03-09