├── LICENSE.txt ├── README.md ├── UptimeRobotPlugin.php ├── composer.json ├── controllers └── UptimeRobotController.php ├── releases.json ├── resources ├── css │ ├── UptimeRobot_Style.css │ └── widgets │ │ └── UptimeRobotWidget.css ├── icon-mask.svg ├── icon.svg ├── js │ ├── UptimeRobot_Script.js │ └── widgets │ │ └── UptimeRobotWidget.js └── screenshots │ ├── plugin_logo.png │ └── widget.png ├── services └── UptimeRobotService.php ├── templates ├── UptimeRobot_Settings.twig └── widgets │ ├── UptimeRobotWidget_Body.twig │ └── UptimeRobotWidget_Settings.twig └── widgets └── UptimeRobotWidget.php /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2016 Fred Carlsen 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 5 | 6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Uptime Robot plugin for Craft CMS 2 | 3 | Integrates with Uptime Robot to monitor the health of your Craft site. 4 | 5 |  6 | 7 | ## Installation 8 | 9 | To install Uptime Robot, follow these steps: 10 | 11 | 1. Download & unzip the file and place the `uptimerobot` directory into your `craft/plugins` directory 12 | 2. -OR- do a `git clone https://github.com/sjelfull/uptimerobot.git` directly into your `craft/plugins` folder. You can then update it with `git pull` 13 | 3. -OR- install with Composer via `composer require sjelfull/uptimerobot` 14 | 4. Install plugin in the Craft Control Panel under Settings > Plugins 15 | 5. The plugin folder should be named `uptimerobot` for Craft to see it. GitHub recently started appending `-master` (the branch name) to the name of the folder for zip file downloads. 16 | 17 | Uptime Robot works on Craft 2.4.x and Craft 2.5.x. 18 | 19 | ## Uptime Robot Overview 20 | 21 | Makes a widget available that shows average uptime and event log. 22 | 23 | ## Configuring Uptime Robot 24 | 25 | Follow the instructions in the settings screen 26 | 27 | ## Using Uptime Robot 28 | 29 | The widget will cache the results for 5 minutes. 30 | 31 | ## Uptime Robot Changelog 32 | 33 | ### 1.0.1 -- 2016.07.19 34 | 35 | * [Fixed] Removed the CP trigger part of the uptime check URL 36 | 37 | ### 1.0.0 -- 2016.07.19 38 | 39 | * Initial release 40 | 41 | Brought to you by [Fred Carlsen](http://sjelfull.no) 42 | -------------------------------------------------------------------------------- /UptimeRobotPlugin.php: -------------------------------------------------------------------------------- 1 | setSettings([ 95 | 'accessKey' => StringHelper::randomString() 96 | ]); 97 | 98 | craft()->plugins->savePluginSettings($this, $this->getSettings()); 99 | } 100 | 101 | 102 | /** 103 | * @return array 104 | */ 105 | protected function defineSettings () 106 | { 107 | return array( 108 | 'apiKey' => array( AttributeType::String, 'label' => 'Monitor Specific API Key', 'default' => '' ), 109 | 'accessKey' => array( AttributeType::String, 'label' => 'Access key', 'default' => '' ), 110 | ); 111 | } 112 | 113 | /** 114 | * @return mixed 115 | */ 116 | public function getSettingsHtml () 117 | { 118 | return craft()->templates->render('uptimerobot/UptimeRobot_Settings', array( 119 | 'settings' => $this->getSettings(), 120 | 'checkUrl' => craft()->uptimeRobot->getCheckUrl(), 121 | )); 122 | } 123 | 124 | /** 125 | * @param mixed $settings The Widget's settings 126 | * 127 | * @return mixed 128 | */ 129 | public function prepSettings ($settings) 130 | { 131 | // Modify $settings here... 132 | 133 | return $settings; 134 | } 135 | 136 | } 137 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sjelfull/Craft-UptimeRobot", 3 | "description": "Integrates with Uptime Robot to monitor the health of your Craft site.", 4 | "type": "craft-plugin", 5 | "authors": [ 6 | { 7 | "name": "Fred Carlsen", 8 | "homepage": "http://sjelfull.no" 9 | } 10 | ], 11 | "require": { 12 | "composer/installers": "~1.0" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /controllers/UptimeRobotController.php: -------------------------------------------------------------------------------- 1 | cache->get('uptimeRobotStats') ) { 33 | $this->returnJson($stats); 34 | } 35 | 36 | $apiKey = craft()->uptimeRobot->getApiKey(); 37 | 38 | // Make request to API if not cached 39 | $client = new \Guzzle\Http\Client(); 40 | 41 | $options = array( 42 | 'timeout' => 30, 43 | 'connect_timeout' => 10, 44 | 'query' => array( 45 | 'apiKey' => $apiKey, 46 | 'logs' => 1, 47 | 'responseTimes' => 1, 48 | 'responseTimesAverage' => 1440, // Average response time for the last 24 hours 49 | 'format' => 'json', 50 | ), 51 | ); 52 | 53 | $request = $client->post($this->_endpoint, null, null, $options); 54 | 55 | // Potentially long-running request, so close session to prevent session blocking on subsequent requests. 56 | // craft()->session->close(); 57 | 58 | $response = $request->send(); 59 | 60 | if ( $response->isSuccessful() ) { 61 | $body = $response->getBody(true); 62 | 63 | // Parse json to remove callback 64 | $match = preg_match("/(jsonUptimeRobotApi\\()(.+)(\\))/uim", $body, $matches); 65 | 66 | if ( !$match ) { 67 | throw new Exception(Craft::t('Problem with parsing JSON from Uptime Robot API: “{json}”', array( 'json' => $body ))); 68 | } 69 | 70 | // Cast to json 71 | $data = json_decode($matches[2], true); 72 | 73 | if ( count($data['monitors']) === 0 ) { 74 | throw new Exception(Craft::t('No monitors returned from Uptime Robot API')); 75 | } 76 | 77 | $data = $data['monitors']['monitor'][0]; 78 | 79 | craft()->cache->set('uptimeRobotStats', $data, $this->_cacheDuration); 80 | 81 | $this->returnJson($data); 82 | } 83 | 84 | } 85 | 86 | /** 87 | */ 88 | public 89 | function actionCheck () 90 | { 91 | $plugin = craft()->plugins->getPlugin('uptimerobot'); 92 | if ( !$plugin ) { 93 | throw new Exception(Craft::t('No plugin exists with the class “{class}”', array( 'class' => 'uptimerobot' ))); 94 | } 95 | $accessKey = craft()->uptimeRobot->getAccessKey(); 96 | $key = craft()->request->getParam('key'); 97 | 98 | if ( $accessKey !== $key ) { 99 | throw new Exception(Craft::t('Access key “{key}” was not valid.', array( 'key' => $key ))); 100 | } 101 | 102 | echo 'UP!'; 103 | 104 | craft()->end(); 105 | } 106 | } -------------------------------------------------------------------------------- /releases.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "version": "1.0.2", 4 | "downloadUrl": "https://github.com/sjelfull/Craft-UptimeRobot/archive/master.zip", 5 | "date": "2017-07-21T21:19:46.342Z", 6 | "notes": [ 7 | "[Fixed] Fixed syntax error in older PHP versions" 8 | ] 9 | }, 10 | { 11 | "version": "1.0.1", 12 | "downloadUrl": "https://github.com/sjelfull/Craft-UptimeRobot/archive/master.zip", 13 | "date": "2016-07-19T21:19:46.342Z", 14 | "notes": [ 15 | "[Fixed] Removed the CP trigger part of the uptime check URL" 16 | ] 17 | }, 18 | { 19 | "version": "1.0.0", 20 | "downloadUrl": "https://github.com/sjelfull/Craft-UptimeRobot/archive/master.zip", 21 | "date": "2016-07-19T11:19:46.342Z", 22 | "notes": [ 23 | "[Added] Initial release" 24 | ] 25 | } 26 | ] 27 | -------------------------------------------------------------------------------- /resources/css/UptimeRobot_Style.css: -------------------------------------------------------------------------------- 1 | /** 2 | * Uptime Robot plugin for Craft CMS 3 | * 4 | * Uptime Robot CSS 5 | * 6 | * @author Fred Carlsen 7 | * @copyright Copyright (c) 2016 Fred Carlsen 8 | * @link http://sjelfull.no 9 | * @package UptimeRobot 10 | * @since 1.0.0 11 | */ 12 | 13 | .uptimerobot-input { 14 | width: 80%; 15 | display: inline-block; 16 | padding: 5px 10px; 17 | } -------------------------------------------------------------------------------- /resources/css/widgets/UptimeRobotWidget.css: -------------------------------------------------------------------------------- 1 | /** 2 | * Uptime Robot plugin for Craft CMS 3 | * 4 | * Uptime RobotWidget CSS 5 | * 6 | * @author Fred Carlsen 7 | * @copyright Copyright (c) 2016 Fred Carlsen 8 | * @link http://sjelfull.no 9 | * @package UptimeRobot 10 | * @since 1.0.0 11 | */ 12 | 13 | .uptimerobot-widget-uptime { 14 | padding-top: 5px; 15 | } 16 | 17 | .uptimerobot-widget-uptime-number { 18 | color: #4DA74D; 19 | font-size: 35px; 20 | } 21 | 22 | .uptimerobot-widget-uptime-description { 23 | font-size: 14px; 24 | display: block; 25 | margin-top: 4px; 26 | } 27 | 28 | .uptimerobot-widget-log { 29 | padding-top: 10px; 30 | } 31 | 32 | .uptimerobot-widget-log li { 33 | transition: opacity 0.25s ease-in-out; 34 | clear: both; 35 | opacity: 0.5; 36 | } 37 | .uptimerobot-widget-log li:after { 38 | content:" "; 39 | display:block; 40 | clear:both; 41 | } 42 | 43 | .uptimerobot-widget-log li:hover { 44 | opacity: 1; 45 | } 46 | 47 | .uptimerobot-widget-log li + li { 48 | padding-top: 5px; 49 | } 50 | 51 | .uptimerobot-widget-logtype { 52 | background-color: #cecece; 53 | color: #fff; 54 | font-size: 11px; 55 | text-transform: uppercase; 56 | letter-spacing: 1px; 57 | 58 | float: left; 59 | display: inline-block; 60 | padding: 2px 10px; 61 | } 62 | 63 | .uptimerobot-widget-logtype.is-Down { 64 | background-color: #DB6464; 65 | } 66 | 67 | .uptimerobot-widget-logtype.is-Up { 68 | background-color: #57A957; 69 | } 70 | 71 | .uptimerobot-widget-logtype.is-Started { 72 | background-color: #006DCC; 73 | } 74 | 75 | .uptimerobot-widget-logtype.is-Paused { 76 | background-color: #000; 77 | } 78 | 79 | .uptimerobot-widget-logdate { 80 | color: #b9bfc6; 81 | float: right; 82 | padding-top: 3px; 83 | } -------------------------------------------------------------------------------- /resources/icon-mask.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/icon.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/js/UptimeRobot_Script.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Uptime Robot plugin for Craft CMS 3 | * 4 | * Uptime Robot JS 5 | * 6 | * @author Fred Carlsen 7 | * @copyright Copyright (c) 2016 Fred Carlsen 8 | * @link http://sjelfull.no 9 | * @package UptimeRobot 10 | * @since 1.0.0 11 | */ 12 | -------------------------------------------------------------------------------- /resources/js/widgets/UptimeRobotWidget.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Uptime Robot plugin for Craft CMS 3 | * 4 | * Uptime RobotWidget JS 5 | * 6 | * @author Fred Carlsen 7 | * @copyright Copyright (c) 2016 Fred Carlsen 8 | * @link http://sjelfull.no 9 | * @package UptimeRobot 10 | * @since 1.0.0 11 | */ 12 | 13 | var UptimeRobotWidget = { 14 | init: function() { 15 | var self = this; 16 | 17 | Craft.postActionRequest('uptimeRobot/stats', self.parseData.bind(self)); 18 | }, 19 | 20 | parseData: function( data ) { 21 | var self = this; 22 | var $spinner = $('#js-uptimeRobotSpinner'); 23 | var $uptime = $('#js-uptimeRobotUptime'); 24 | var $log = $('#js-uptimeRobotLog'); 25 | 26 | $uptime.text( data.alltimeuptimeratio + '%' ); 27 | 28 | var logOutput = ''; 29 | 30 | for (var i = 0; i < data.log.length; i++) { 31 | logOutput += self.parseLogItem( data.log[i] ); 32 | } 33 | 34 | $log.html(logOutput); 35 | 36 | // Hide spinner and show results 37 | $spinner.addClass('hidden'); 38 | $log.parent().removeClass('hidden'); 39 | $uptime.parent().removeClass('hidden'); 40 | }, 41 | 42 | parseLogItem: function( data ) { 43 | var self = this; 44 | var type = null; 45 | 46 | switch (parseInt(data.type)) { 47 | case 1: 48 | type = 'Down'; 49 | break; 50 | case 2: 51 | type = 'Up'; 52 | break; 53 | case 99: 54 | type = 'Paused'; 55 | break; 56 | case 98: 57 | type = 'Started'; 58 | break; 59 | } 60 | 61 | var output = '