PHP code example of nmcquay / pagerduty

1. Go to this page and download the library: Download nmcquay/pagerduty 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/ */

    

nmcquay / pagerduty example snippets


$evt = new \PagerDuty\Event();
// service key found at https://<your subdomain>.pagerduty.com/services
$evt->setServiceKey('32 char GUID') 
    ->setDescription('an example description')
    //incident key will get set automatically by pagerduty response if not set here
    //->setIncidentKey('example001') //optional
    ->setClient('Example Client') //optional
    ->setClientUrl('http://www.example.com') //optional
    ->setDetails( array('test' => 1) ) //optional
    //setDetail will add/alter a key to the details object
    ->setDetail( 'appended Detail key', 'with a value' ); //optional
$resp = $evt->trigger();

var_dump( $resp, $evt->toArray(), $evt->getIncidentKey() );

//now assuming everything worked, you should have triggered a pagerduty event
//we can acknowledge the event:
$resp = $evt->acknowledge();
var_dump( $resp );

//and we can resolve the event:
$resp = $evt->resolve();
var_dump( $resp );

// acknowledge() and resolve()