Merge pull request #812 from TheSerapher/uptimerobot

Uptimerobot
This commit is contained in:
Sebastian Grewe 2013-11-02 02:58:03 -07:00
commit ab2b2d6062
265 changed files with 306 additions and 20 deletions

View File

@ -33,8 +33,18 @@ if ($price = $tools->getPrice()) {
if (!$setting->setValue('price', $price))
$log->logError("unable to update value in settings table");
} else {
$log->logFatal("failed to fetch API data: " . $tools->getError());
$log->logError("failed to fetch API data: " . $tools->getError());
}
if ($setting->getValue('monitoring_uptimerobot_private_key')) {
$monitoring->setTools($tools);
if (!$monitoring->storeUptimeRobotStatus()) {
$log->logError('Failed to update Uptime Robot Status: ' . $monitoring->getError());
}
} else {
$log->logDebug('Skipped Uptime Robot API update, missing private key');
}
require_once('cron_end.inc.php');
?>

View File

@ -41,6 +41,9 @@ class Base {
public function setSetting($setting) {
$this->setting = $setting;
}
public function setTools($tools) {
$this->tools = $tools;
}
public function setBitcoin($bitcoin) {
$this->bitcoin = $bitcoin;
}

View File

@ -4,13 +4,52 @@
if (!defined('SECURITY'))
die('Hacking attempt');
class Monitoring {
public function __construct($debug, $mysqli) {
$this->debug = $debug;
$this->mysqli = $mysqli;
class Monitoring extends Base {
public function __construct() {
$this->table = 'monitoring';
}
/**
* Store Uptime Robot status information as JSON in settings table
* @param none
* @return bool true on success, false on error
**/
public function storeUptimeRobotStatus() {
if ($api_keys = $this->setting->getValue('monitoring_uptimerobot_private_key')) {
$aJSONData = array();
$url = 'http://api.uptimerobot.com';
$aMonitors = explode(',', $api_keys);
foreach ($aMonitors as $aData) {
$temp = explode('|', $aData);
$aMonitor['api_key'] = $temp[0];
$aMonitor['monitor_id'] = $temp[1];
$target = '/getMonitors?apiKey=' . $aMonitor['api_key'] . '&monitors=' . $aMonitor['monitor_id'] . '&format=json&noJsonCallback=1&customUptimeRatio=1-7-30&logs=1';
if (!$aMonitorStatus = $this->tools->getApi($url, $target)) {
$this->setErrorMessage('Failed to run API call: ' . $this->tools->getError());
return false;
}
$aMonitorStatus['monitors']['monitor'][0]['customuptimeratio'] = explode('-', $aMonitorStatus['monitors']['monitor'][0]['customuptimeratio']);
$aAllMonitorsStatus[] = $aMonitorStatus['monitors']['monitor'][0];
}
if (!$this->setting->setValue('monitoring_uptimerobot_status', json_encode($aAllMonitorsStatus)) || !$this->setting->setValue('monitoring_uptimerobot_lastcheck', time())) {
$this->setErrorMessage('Failed to store uptime status: ' . $setting->getError());
return false;
}
}
return true;
}
/**
* Fetch Uptime Robot Status from settings table
* @param none
* @return array Data on success, false on failure
**/
public function getUptimeRobotStatus() {
if ($json = $this->setting->getValue('monitoring_uptimerobot_status'))
return json_decode($json, true);
return false;
}
/**
* Fetch a value from our table
* @param name string Setting name
@ -46,4 +85,8 @@ class Monitoring {
}
}
$monitoring = new Monitoring($debug, $mysqli);
$monitoring = new Monitoring();
$monitoring->setConfig($config);
$monitoring->setDebug($debug);
$monitoring->setMysql($mysqli);
$monitoring->setSetting($setting);

View File

@ -1,15 +1,10 @@
<?php
// Make sure we are called from index.php
if (!defined('SECURITY'))
die('Hacking attempt');
if (!defined('SECURITY')) die('Hacking attempt');
class Setting {
public function __construct($debug, $mysqli) {
$this->debug = $debug;
$this->mysqli = $mysqli;
$this->table = 'settings';
}
class Setting extends Base {
protected $table = 'settings';
/**
* Fetch a value from our table
@ -51,3 +46,5 @@ class Setting {
}
$setting = new Setting($debug, $mysqli);
$setting->setDebug($debug);
$setting->setMysql($mysqli);

View File

@ -17,7 +17,7 @@ class Tools extends Base {
* @param auth array Optional authentication data to be sent with
* @return dec array JSON decoded PHP array
**/
private function getApi($url, $target, $auth=NULL) {
public function getApi($url, $target, $auth=NULL) {
static $ch = null;
static $ch = null;
if (is_null($ch)) {
@ -32,9 +32,15 @@ class Tools extends Base {
// run the query
$res = curl_exec($ch);
if ($res === false) throw new Exception('Could not get reply: '.curl_error($ch));
if ($res === false) {
$this->setErrorMessage('Could not get reply: '.curl_error($ch));
return false;
}
$dec = json_decode($res, true);
if (!$dec) throw new Exception('Invalid data received, please make sure connection is working and requested API exists');
if (!$dec) {
$this->setErrorMessage('Invalid data received, please make sure connection is working and requested API exists');
return false;
}
return $dec;
}

View File

@ -172,6 +172,13 @@ $aSettings['acl'][] = array(
'name' => 'acl_round_statistics', 'value' => $setting->getValue('acl_round_statistics'),
'tooltip' => 'Make the round statistics page private (users only) or public.'
);
$aSettings['acl'][] = array(
'display' => 'Uptime Statistics', 'type' => 'select',
'options' => array( 0 => 'Private', 1 => 'Public'),
'default' => 1,
'name' => 'acl_uptime_statistics', 'value' => $setting->getValue('acl_uptime_statistics'),
'tooltip' => 'Make the uptime statistics page private (users only) or public.'
);
$aSettings['system'][] = array(
'display' => 'E-mail address for system error notifications', 'type' => 'text',
'size' => 25,
@ -256,5 +263,12 @@ $aSettings['recaptcha'][] = array(
'name' => 'recaptcha_public_key', 'value' => $setting->getValue('recaptcha_public_key'),
'tooltip' => 'Your public key as given by your re-Captcha account.'
);
$aSettings['monitoring'][] = array(
'display' => 'Uptime Robot Private API Key', 'type' => 'text',
'size' => 25,
'default' => '<API KEY>|<MONITOR ID>,<API KEY>|<MONITOR ID>, ...',
'name' => 'monitoring_uptimerobot_private_key', 'value' => $setting->getValue('monitoring_uptimerobot_private_key'),
'tooltip' => 'Create per-monitor API keys and save them here to propagate your uptime statistics.'
);
?>

View File

@ -0,0 +1,29 @@
<?php
// Make sure we are called from index.php
if (!defined('SECURITY')) die('Hacking attempt');
if (!$smarty->isCached('master.tpl', $smarty_cache_key)) {
$debug->append('No cached version available, fetching from backend', 3);
if ($setting->getValue('monitoring_uptimerobot_private_key')) {
if ($aStatus = $monitoring->getUptimeRobotStatus()) {
$smarty->assign("STATUS", $aStatus);
$smarty->assign("UPDATED", $setting->getValue('monitoring_uptimerobot_lastcheck'));
$smarty->assign("CODES", array(
0 => 'Paused',
1 => 'Unchecked',
2 => 'Up',
8 => 'Down',
9 => 'Down'
));
}
$smarty->assign("CONTENT", "default.tpl");
} else {
$_SESSION['POPUP'][] = array('CONTENT' => 'UptimeRobot API Key not configured.', 'TYPE' => 'info');
$smarty->assign("CONTENT", "");
}
} else {
$debug->append('Using cached page', 3);
}
?>

View File

@ -96,6 +96,7 @@ $setting->getValue('website_chaininfo_url') ? $aGlobal['website']['chaininfo']['
$aGlobal['acl']['pool']['statistics'] = $setting->getValue('acl_pool_statistics');
$aGlobal['acl']['block']['statistics'] = $setting->getValue('acl_block_statistics');
$aGlobal['acl']['round']['statistics'] = $setting->getValue('acl_round_statistics');
$aGlobal['acl']['uptime']['statistics'] = $setting->getValue('acl_uptime_statistics');
// We don't want these session infos cached
if (@$_SESSION['USERDATA']['id']) {
@ -165,5 +166,6 @@ $smarty->assign('DEBUG', DEBUG);
// Make it available in Smarty
$smarty->assign('PATH', 'site_assets/' . THEME);
$smarty->assign('GLOBALASSETS', 'site_assets/global');
$smarty->assign('GLOBAL', $aGlobal);
?>

Binary file not shown.

After

Width:  |  Height:  |  Size: 643 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 408 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 604 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 591 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 643 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 600 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 497 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 488 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 428 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 506 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 647 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 403 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 673 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 524 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 663 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 589 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 593 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 585 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 504 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 449 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 497 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 462 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 457 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 675 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 486 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 611 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 639 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 500 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 593 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 526 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 631 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 512 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 443 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 514 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 600 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 628 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 398 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 625 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 528 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 614 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 521 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 367 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 453 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 586 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 450 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 525 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 472 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 483 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 477 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 439 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 563 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 529 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 608 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 428 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 476 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 545 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 572 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 495 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 508 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 582 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 500 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 429 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 465 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 508 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 496 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 653 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 469 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 592 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 479 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 532 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 489 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 610 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 648 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 552 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 474 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 545 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 489 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 599 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 637 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 594 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 545 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 490 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 463 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 470 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 493 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 480 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 488 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 537 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 487 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 630 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 493 B

Some files were not shown because too many files have changed in this diff Show More