Giter Club home page Giter Club logo

uptime-robot-bundle's Introduction

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
composer require 20steps/commons-uptime-robot-bundle
  1. Configure the API key of your account at UptimeRobot.com in your config.yml
twentysteps_commons_uptime_robot:
    api_key: "Your API Key"

Usage

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 twentysteps:commons:uptime-robot namespace.

Eg. to list all monitors and their stati simply call

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
<?php
    

$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

uptime-robot-bundle's People

Contributors

helmut-hoffer-von-ankershoffen avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

reyostallenberg

uptime-robot-bundle's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.