danho/pagerduty

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

0.4.2 2022-06-28 05:35 UTC

This package is auto-updated.

Last update: 2024-09-28 10:32:05 UTC


README

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

本包简化了使用 Laravel 5.5+、6.x 和 7.x 向 PagerDuty 发送通知事件的过程。

内容

安装

您可以通过 composer 安装此包。

composer require danhvo/pagerduty

用法

现在您可以在 Notification 类的 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 方法添加到您的 Notifiable 模型中。

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

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”作为通道引用。

变更日志

有关最近更改的更多信息,请参阅变更日志

测试

$ composer test

安全

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

贡献

有关详细信息,请参阅贡献指南

鸣谢

许可证

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