项目作者: 20steps

项目描述 :
Symfony bundle for service-oriented client for UptimeRobot API v2.0
高级语言: PHP
项目地址: git://github.com/20steps/uptime-robot-bundle.git
创建时间: 2017-07-12T16:14:55Z
项目社区:https://github.com/20steps/uptime-robot-bundle

开源协议:GNU Lesser General Public License v3.0

下载


20steps/uptime-robot-bundle (twentystepsCommonsUptimeRobotBundle)

About

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.

Installation

Prerequisites:

  • Install Composer, the dependency manager used by modern PHP applications.
  • Setup your Symfony 3 based application
  • Use PHP >= 7.0 as a runtime
  1. Add the bundle to your composer.json and download a matching version by calling
  1. composer require 20steps/commons-uptime-robot-bundle
  1. Configure the API key of your account at UptimeRobot.com in your config.yml
    1. twentysteps_commons_uptime_robot:
    2. api_key: "Your API Key"

Usage

The following code shows how to create a monitor with the client.

  1. <?php
  2. use twentysteps\Commons\UptimeRobotBundle\API;
  3. use twentysteps\Commons\UptimeRobotBundle\Model;
  4. class MyService {
  5. /**
  6. * @var UptimeRobotAPI
  7. */
  8. private $uptimeRobotAPI;
  9. /**
  10. * inject dependency to uptimeRobotAPI via your services.yml
  11. * the uptimeRobotAPI is a service itself with the id "twentysteps_commons.uptime_robot.api"
  12. */
  13. public function __construct(UptimeRobotAPI $uptimeRobotAPI) {
  14. $this->uptimeRobotAPI = $uptimeRobotAPI;
  15. }
  16. /**
  17. * create a monitor
  18. * @return \Psr\Http\Message\ResponseInterface|Error|Monitor
  19. */
  20. public function createMonitorForMyResource() {
  21. $parameters = [
  22. 'friendly_name' => 'My Monitor,
  23. 'url' => 'https://my-host.com/my-path'
  24. ];
  25. $response = $this->uptimeRobotAPI->monitor()->create($parameters);
  26. if ($response instanceof MonitorResponse) {
  27. /**
  28. * @var $response MonitorResponse
  29. */
  30. if ($response->getStat()=='ok') {
  31. return $response->getMonitor();
  32. } else {
  33. return $response->getError();
  34. }
  35. }
  36. return $response;
  37. }
  38. }

The bundle provides some useful commands below the twentysteps:commons:uptime-robot namespace.

Eg. to list all monitors and their stati simply call

  1. bin/console twentysteps:commons:uptime-robot:monitor:list

Hints

  • In case your application uses multiple accounts at UptimeRobot you can dynamically change
    the api key as follows
  1. <?php
  2. $this->uptimeRobotAPI->setApiKey($myApiKey);
  • Cp. section “parameters” of UptimeRobot API Documentation for an explanation of parameters.
  • The UptimeRobot API has been enhanced by some extra utility methods such as api->monitor()->findOneByUrl(..), api->monitor->createOrUpdate(..), api->monitor->pauseByUrl(), api->monitor->resumeByUrl() etc.

Authors

Sponsored by

20steps - Digital Full Service Boutique