tonicforhealth/pagerduty-client
Composer 安装命令:
composer require tonicforhealth/pagerduty-client
包简介
This is the client for creating events and sending them to PagerDuty by API
README 文档
README
PagerDuty is a client lib that provides us with the object interface to use PagerDuty events-api and allows us to extend this lib to use with PagerDuty rest-api v2
Simple way to try it with Composer
Installation
if you want to try it
mkdir pagerduty-client-app && cd pagerduty-client-app && composer init --stability=dev -n && composer require tonicforhealth/pagerduty-client php-http/guzzle6-adapter guzzlehttp/guzzle:~6.1
Usage example
<?php require __DIR__.'/vendor/autoload.php'; use TonicForHealth\PagerDutyClient\Client\EventClientFactory; use TonicForHealth\PagerDutyClient\Client\Exception\EventClientTransportException; use TonicForHealth\PagerDutyClient\Client\Exception\ResponseDataValidationException; use TonicForHealth\PagerDutyClient\Entity\Event\Event; $eventClient = EventClientFactory::createEventClient( 'https://events.pagerduty.com/generic/2010-04-15' ); $event = new Event(); $event->serviceKey = 'change it to your "Integration Key"'; $event->description = 'FAILURE for production/HTTP on machine srv01.acme.com'; try { $response = $eventClient->post($event); } catch (EventClientTransportException $exception) { printf('HTTP Transport problem:%s'."\n", $exception->getMessage()); exit(1); } catch (ResponseDataValidationException $exception) { printf('Validation response problem:%s'."\n", $exception->getMessage()); exit(2); } var_dump($response);
For existing projects with Composer
Installation
if you already have a project with composer.json check minimum-stability, and if it is higher than dev, change it to dev
$ composer config minimum-stability dev
then add tonicforhealth/pagerduty-client
$ composer require tonicforhealth/pagerduty-client
also you need to add an http-client with an adapter, or if you have one, you need to find a php-http-padapter for it
$ composer require php-http/guzzle6-adapter guzzlehttp/guzzle:~6.1
Advance Usage example
<?php require __DIR__.'/vendor/autoload.php'; use Http\Client\Common\HttpMethodsClient; use Http\Discovery\HttpClientDiscovery; use Http\Discovery\MessageFactoryDiscovery; use TonicForHealth\PagerDutyClient\Client\EventClient; use TonicForHealth\PagerDutyClient\Client\Exception\EventClientTransportException; use TonicForHealth\PagerDutyClient\Client\Exception\ResponseDataValidationException; use TonicForHealth\PagerDutyClient\Entity\Event\Event; use TonicForHealth\PagerDutyClient\Entity\Event\EventRepresentation; use TonicForHealth\PagerDutyClient\RepresentProcessor\RepresentProcessor; use TonicForHealth\PagerDutyClient\Validation\ValidationResponseFactory; $representProcessor = new RepresentProcessor(); $eventRepresentation = new EventRepresentation(); $representProcessor->addRepresentation($eventRepresentation); $validationResponse = ValidationResponseFactory::createValidation('Event'); $httpMethodsClient = new HttpMethodsClient( HttpClientDiscovery::find(), MessageFactoryDiscovery::find() ); $eventClient = new EventClient( 'https://events.pagerduty.com/generic/2010-04-15', $httpMethodsClient, $representProcessor, $validationResponse ); $event = new Event(); $event->serviceKey = 'change it to your "Integration Key"'; $event->description = 'FAILURE for production/HTTP on machine srv01.acme.com'; try { $response = $eventClient->post($event); } catch (EventClientTransportException $exception) { printf('HTTP Transport problem:%s'."\n", $exception->getMessage()); exit(1); } catch (ResponseDataValidationException $exception) { printf('Validation response problem:%s'."\n", $exception->getMessage()); exit(2); } var_dump($response);
统计信息
- 总下载量: 154
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-07-27