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
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
<?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
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
<?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);