danho / pagerduty
用于发送 PagerDuty 事件的 Laravel 通知通道。
0.4.2
2022-06-28 05:35 UTC
Requires
- php: >=7.1
- guzzlehttp/guzzle: ~6.0|^7.0
- illuminate/notifications: ~5.5 || ~6.0 || ~7.0 || ^8.0 || ^9.0
- illuminate/support: ~5.5 || ~6.0 || ~7.0 || ^8.0 || ^9.0
Requires (Dev)
- illuminate/queue: ~5.5 || ~6.0 || ~7.0 || ^8.0
- mockery/mockery: ^1.2
- phpunit/phpunit: ^8.5|^9.0
README
本包简化了使用 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
创建一个新的集成。
您新集成中列出的 Integration Key
是您需要在 routeNotificationForPagerDuty()
方法中设置的。
可用的消息方法
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)。有关更多信息,请参阅许可证文件。