require_once "../init.php"; // Usage of the SDK objects use PatrolSdk\Singleton as Patrol; // Helper function to display the outcome in a readable format, you can ignore this. function display($title, $data) { echo "<h1>" . $title . "</h1>"; if (!is_null($data)) { echo '<pre>' . print_r($data, true) . '</pre>'; } echo "\n\n"; } /* * In order to communicate with the PatrolServer API, you must register a key and secret. */ Patrol::setApiKey('ed94f55159c0710972d7da4b97766767'); Patrol::setApiSecret('92df264e875b0cad2f70906341017efa29eb1c5f35c59e3e380d943c6798f45b'); // Get all the servers from the account linked to the key or secret above. $servers = Patrol::servers(); display("Servers", $servers); // Get a single server $first_server = count($servers) ? $servers[0] : null; // Let's not continue if no servers are added, we'll continue with this server. if (!$first_server) { die("Add a server on the dashboard first"); } // Print the first server in the list. display("First server", $first_server); /* * You can also fetch a single server from the API, provide the ID in the "server" function as first parameter. * Optional scopes can also be provided as second parameter. An example:
require_once "../init.php"; // Usage of the SDK objects use PatrolSdk\Singleton as Patrol; /* * The log part is just an example, the SDK provides a testing environment where you can log data. * In this example, we'll use the Log interface to log incoming webhooks to "log.txt". */ Log::setPath(dirname(__FILE__) . '/log.txt'); // Logging is not enabled by default, we'll enable the Log interface manually. Patrol::enableLog(); /* * When the SDK retrieves a webhook event, it only contains an event_id and a webhook_id. It then fetches * the Event through the PatrolServer API (https://api.patrolserver.com). In order to access the API endpoints, a key and * secret is needed. */ Patrol::setApiKey('194786f61ea856b6468c0c41fa0d4bdb'); Patrol::setApiSecret('D6360a34e730ae96d74f545a286bfb01468cd01bb191eed49d9e421c2e56f958'); /* * Event: webhook.test * * This event gets triggered when you hit the "Test Webhook" button in the API page. * It's a great way to check if your webhook is working. If this logs, it works! */ Patrol::webhook('webhook.test', function ($event) { Patrol::log('webhook.test'); Patrol::log($event); }); /* * Event: webhook.new_server_issues * * When new issues are found on your server. Let's say, your PHP software package suddenly becomes outdated,