一个用于发送 PagerDuty 事件的 Laravel 通知通道。

0.4.0 2021-01-14 23:08 UTC

This package is auto-updated.

Last update: 2024-09-16 21:10:10 UTC


README

Latest Version on Packagist Software License Build Status StyleCI SensioLabsInsight Quality Score Code Coverage Total Downloads

此包使您能够轻松地将通知事件发送到 PagerDuty,适用于 Laravel 5.5+、6.x 和 7.x

内容

安装

您可以通过 composer 安装此包

composer require laravel-notification-channels/pagerduty

使用方法

现在您可以在通知类的 via() 方法中使用此通道。

use NotificationChannels\PagerDuty\PagerDutyChannel;
use NotificationChannels\PagerDuty\PagerDutyMessage;
use Illuminate\Notifications\Notification;

class SiteProblem extends Notification
{
    public function via($notifiable)
    {
        return [PagerDutyChannel::class];
    }

    public function toPagerDuty($notifiable)
    {
        return PagerDutyMessage::create()
            ->setSummary('There was an error with your site in the {$notifiable->service} component.');
    }
}

为了使通知知道哪个集成应该接收事件,请将 routeNotificationForPagerDuty 方法添加到您的可通知模型中。

此方法需要返回您希望发送事件的服务的集成密钥。

public function routeNotificationForPagerDuty()
{
    return '99dc10c97a6e43c387bbc4f877c794ef';
}

PagerDuty 设置

在您选择的 PagerDuty 服务中,使用 Events API v2 创建一个新的集成。

Creating a new integration

为您的新的集成列出的 Integration Key 是您需要在 routeNotificationForPagerDuty() 方法中设置的。

List of Integrations with Keys

可用的消息方法

  • resolve():将事件类型设置为 resolve 以解决问题。
  • setDedupKey(''):设置 dedup_key(在解决时必需)。
  • setSummary(''):在事件上设置摘要消息。
  • setSource(''):设置事件源;默认为 hostname
  • setSeverity(''):设置事件严重性;默认为 critical
  • setTimestamp(''):设置事件的 timestamp
  • setComponent(''):设置事件的 component
  • setGroup(''):设置事件的 group
  • setClass(''):设置 class
  • addCustomDetail('', ''):向事件的 custom_detail 添加键值对。

有关这些选项将执行什么操作的更多信息,请参阅 PagerDuty v2 事件 API 文档

使用方法

Notification::route('PagerDuty', '[my integration key]')->notify(new BasicNotification);

当使用 Notification::route 时,请确保将 'PagerDuty' 作为通道引用。

变更日志

有关最近更改的更多信息,请参阅 CHANGELOG

测试

$ composer test

安全

如果您发现任何安全相关的问题,请通过电子邮件 lwaite@gmail.com 反馈,而不是使用问题跟踪器。

贡献

有关详细信息,请参阅 CONTRIBUTING

鸣谢

许可证

MIT 许可证(MIT)。有关更多信息,请参阅 许可证文件