tonicforhealth / pagerduty-client
This is the client for creating events and sending them to PagerDuty by API
v0.1.0
2016-07-27 21:54 UTC
Requires
- php-http/client-common: ~1.0
- php-http/discovery: ~0.6
- php-http/message: ~1.2
- puli/composer-plugin: ^1.0@beta
Requires (Dev)
- guzzlehttp/psr7: ^1.3
- php-http/mock-client: ^0.3
- phpunit/phpunit: ~4.8|~5.3
Suggests
- guzzlehttp/guzzle: ~6.1
- php-http/guzzle6-adapter: ~1.1
This package is not auto-updated.
Last update: 2024-11-18 15:03:26 UTC
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);