Symfony bundle for service-oriented client for UptimeRobot API v2.0
The 20steps UptimeRobot Bundle contains a service-oriented client for UptimeRobot API v2.0.
Use the bundle in scenarios where you want to automatically create monitors, alert contacts etc. at UptimeRobot.com for your given application or services or as part of your deployment process to automatically manage maintenance windows.
The Bundle is licensed under the LGPL license version 3.0.
Prerequisites:
composer require 20steps/commons-uptime-robot-bundle
twentysteps_commons_uptime_robot:
api_key: "Your API Key"
The following code shows how to create a monitor with the client.
<?php
use twentysteps\Commons\UptimeRobotBundle\API;
use twentysteps\Commons\UptimeRobotBundle\Model;
class MyService {
/**
* @var UptimeRobotAPI
*/
private $uptimeRobotAPI;
/**
* inject dependency to uptimeRobotAPI via your services.yml
* the uptimeRobotAPI is a service itself with the id "twentysteps_commons.uptime_robot.api"
*/
public function __construct(UptimeRobotAPI $uptimeRobotAPI) {
$this->uptimeRobotAPI = $uptimeRobotAPI;
}
/**
* create a monitor
* @return \Psr\Http\Message\ResponseInterface|Error|Monitor
*/
public function createMonitorForMyResource() {
$parameters = [
'friendly_name' => 'My Monitor,
'url' => 'https://my-host.com/my-path'
];
$response = $this->uptimeRobotAPI->monitor()->create($parameters);
if ($response instanceof MonitorResponse) {
/**
* @var $response MonitorResponse
*/
if ($response->getStat()=='ok') {
return $response->getMonitor();
} else {
return $response->getError();
}
}
return $response;
}
}
The bundle provides some useful commands below the twentystepsuptime-robot namespace.
Eg. to list all monitors and their stati simply call
bin/console twentysteps:commons:uptime-robot:monitor:list
<?php
$this->uptimeRobotAPI->setApiKey($myApiKey);