PHP code example of tonicforhealth / pagerduty-client
1. Go to this page and download the library: Download tonicforhealth/pagerduty-client library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tonicforhealth / pagerduty-client example snippets
onicForHealth\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);
ttp\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);
bash
$ composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.