adilbaig/pagerduty
Composer 安装命令:
composer require adilbaig/pagerduty
包简介
PHP wrapper to PagerDuty Events API.
关键字:
README 文档
README
PHP implementation of the PagerDuty Events API V2
New Maintainer
7th January 2026 ownership of this package has been transfered to me, @cheesegrits.
Many thanks to @adilbaig for authoring and maintaining this package and for making the effort to find and transfer to a new owner, rather than just abandoning it.
I doubt I will be making any major changes or adding new features, I simply needed the package as-is to support some long-term projects I work on. But if you need any changes or features, feel free to raise an issue.
Request for Maintainer
8th June 2025 If you're interested in taking over the maintenance of this plugin, let me know.
A bit of background. I started this plugin many years ago while working at a fintech startup. Our Ops team relied on PagerDuty and we wanted to hook up our internal alerting systems to PD. I didn't quite like what was available. I wanted something that was simple and flexible, but nothing more. This plugin has long since fulfilled that purpose. Over time people have come to use, contribute and rely on it. It is PD's recommended community plugin and the most downloaded PD plugin on Packagist. I've long since moved on; from the startup, from PHP and from PagerDuty. It's time someone else took over the maintenance here.
Your mission, should you choose to accept it, is to upgrade this plugin to PHP 8.4. Fork this repo, make the changes and send me a PR. Once committed, I will transfer ownership of the repo over.
Update (2025-12-10): @cheesegrits will be taking over maintenance of this project.
Compatibility
- v4.*: Requires
"php": ">=8.0". PagerDuty Events API V2. - v3.*: Requires
"php": ">=5.4.0". PagerDuty Events API V2. If you are upgrading from a 2.* release, make sure you pay attention to the contructor of theTriggerEvent - v2.*: Requires
"php": ">=5.4.0". PagerDuty Events API V1.
Features
- Compatible with PagerDuty Events API V2.
- Trigger, Acknowledge and Resolve incidents.
- Attach Links and Images to your incident reports.
- Unit Tests
Installation
For PHP 8.* projects, add this line to your project's composer.json
{
...
"require": {
"adilbaig/pagerduty": "4.*"
}
...
}
For PHP versions < 8, add this line to your project's composer.json
{
...
"require": {
"adilbaig/pagerduty": "3.*"
}
...
}
The packagist URL is https://packagist.org/packages/adilbaig/pagerduty
Usage
Trigger an event
use \PagerDuty\TriggerEvent; use \PagerDuty\Exceptions\PagerDutyException; $routingKey = "1d334a4819fc4b67a795b1c54f9a"; //Replace this with the integration key of your service. // In this example, we're triggering a "Service is down" message from a web server. try { $event = new TriggerEvent( $routingKey, "Service is down", // A high-level, text summary message of the event. Will be used to construct an alert's description. "web-server-01", // human-readable unique identifier, such as a hostname, for the system having the problem. TriggerEvent::ERROR,// How impacted the affected system is? Influences the priority of any created incidents. true // Generate the dedup_key from the driver. If false, the dedup_key will be generated on PD ); $responseCode = $event->send(); if($responseCode == 200) echo "Success"; elseif($responseCode == 429) echo "Rate Limited"; //You're being throttled. Slow down. else // An error occured. Try again later echo "Some error has occured. Try again later"; } catch(PagerDutyException $exception) { //This doesn't happen unless you've broken their guidelines. The API tries to minimize user mistakes var_dump($exception->getErrors()); }
Trigger event with custom connection, for example: using proxies and/or setting verbosity for debugging, etc.
use \PagerDuty\TriggerEvent; use \PagerDuty\Exceptions\PagerDutyException; use \PagerDuty\Http\PagerDutyHttpConnection; try { $routingKey = '1d334a4819fc4b67a795b1c54f9a'; //Replace this with the integration key of your service. $event = new TriggerEvent( $routingKey, "Service is down", // A high-level, text summary message of the event. Will be used to construct an alert's description. "web-server-01", // human-readable unique identifier, such as a hostname, for the system having the problem. TriggerEvent::ERROR,// How impacted the affected system is? Influences the priority of any created incidents. true // Generate the dedup_key from the driver. If false, the dedup_key will be generated on PD ); // create a custom proxy connection $connection = new PagerDutyHttpConnection(); // .. and set the proxy $connection->setProxy('https://user:password@your-proxy-ip-address:port'); // set custom CURL options. Here we set verbosity for debugging $connection->addCurlOption('CURLOPT_VERBOSE', 1); // send event through proxy $connection->send($event); } catch(PagerDutyException $exception) { //This doesn't happen unless you've broken their guidelines. The API tries to minimize user mistakes var_dump($exception->getErrors()); } catch (\Exception $e) { // A configuration exception }
Automatically send only one PagerDuty incident for repeated errors
//You will only see one incident on PD (TriggerEvent($routingKey, "Service is down", "web-server-01", TriggerEvent::ERROR, true))->send(); (TriggerEvent($routingKey, "Service is down", "web-server-01", TriggerEvent::ERROR, true))->send(); (TriggerEvent($routingKey, "Service is down", "web-server-01", TriggerEvent::ERROR, true))->send();
Create a detailed 'trigger' event, add optional data. Dump the event and inspect response from PD
use \PagerDuty\TriggerEvent; //Taken from the `trigger` example @ https://v2.developer.pagerduty.com/docs/send-an-event-events-api-v2 //Send a detailed event, and store the `dedup_key` generated on the server $event = new TriggerEvent( $routingKey, "Example alert on host1.example.com", "monitoringtool:cloudvendor:central-region-dc-01:852559987:cluster/api-stats-prod-003", TriggerEvent::INFO ); $event ->setPayloadTimestamp("2015-07-17T08:42:58.315+0000") ->setPayloadComponent("postgres") ->setPayloadGroup("prod-datapipe") ->setPayloadClass("deploy") ->setPayloadCustomDetails(["ping_time" => "1500ms", "load_avg" => 0.75]) ->addLink("https://example.com/", "Link text") ->addImage("https://www.pagerduty.com/wp-content/uploads/2016/05/pagerduty-logo-green.png", "https://example.com/", "Example text")) ; // Pass in the '$response' variable by reference if you want to inspect PD's response. This is optional, and you probably don't need this in production. $response = null; $responseCode = $event->send($response); // In this case, we will save the `dedup_key` generated by the PD server var_dump($response['dedup_key']);
Acknowledge an event
(new AcknowledgeEvent($routingKey, "dedup key"))->send();
Resolve an event
(new ResolveEvent($routingKey, "dedup key"))->send();
UnitTests
> ./vendor/bin/phpunit test/
..... 5 / 5 (100%)
Time: 37 ms, Memory: 4.00MB
OK (5 tests, 6 assertions)
Questions
Q. How do i get the service key from PagerDuty?
A. In your PagerDuty console, click 'Configuration' > 'Services'. Click the link under 'Integrations' column. It's the 'Integration Key'
Read more here : https://v2.developer.pagerduty.com/v2/docs/events-api#getting-started
Requirements
This library needs the curl pecl extension.
In Ubuntu 16.04, install it like so :
sudo apt install php-curl
In Ubuntu 18.04, install it like so :
sudo apt install php8.3-curl
adilbaig/pagerduty 适用场景与选型建议
adilbaig/pagerduty 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 793.62k 次下载、GitHub Stars 达 17, 最近一次更新时间为 2014 年 03 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「rest」 「PagerDuty」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 adilbaig/pagerduty 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 adilbaig/pagerduty 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 adilbaig/pagerduty 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Library for interacting with PagerDuty REST API
Fork of adilbaig/pagerduty - PHP wrapper to PagerDuty Events API.
A Laravel notification channel for sending PagerDuty events.
A PSR-7 compatible library for making CRUD API endpoints
Symfony PagerDuty Notifier Bridge
Api bundle
统计信息
- 总下载量: 793.62k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 18
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-03-13