[IMPROVED] Allow multi-monitor setup via API Keys

This commit is contained in:
Sebastian Grewe 2013-10-29 18:00:21 +01:00
parent 861172e6f8
commit 272448dc6c
4 changed files with 54 additions and 36 deletions

View File

@ -10,14 +10,24 @@ class Monitoring extends Base {
} }
public function storeUptimeRobotStatus() { public function storeUptimeRobotStatus() {
if ($api_key = $this->setting->getValue('monitoring_uptimerobot_private_key')) { if ($api_keys = $this->setting->getValue('monitoring_uptimerobot_private_key')) {
$aJSONData = array();
$url = 'http://api.uptimerobot.com'; $url = 'http://api.uptimerobot.com';
$target = '/getMonitors?apiKey=' . $api_key . '&format=json&noJsonCallback=1&customUptimeRatio=1&logs=1'; $aMonitors = explode(',', $api_keys);
if (!$json = json_encode($this->tools->getApi($url, $target))) { foreach ($aMonitors as $aData) {
$this->setErrorMessage('Failed to run API call: ' . $this->tools->getError()); $temp = explode('|', $aData);
return false; $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']);
var_dump($aMonitorStatus['monitors']['monitor'][0]);
$aAllMonitorsStatus[] = $aMonitorStatus['monitors']['monitor'][0];
} }
if (!$this->setting->setValue('monitoring_uptimerobot_status', $json) || !$this->setting->setValue('monitoring_uptimerobot_lastcheck', time())) { 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()); $this->setErrorMessage('Failed to store uptime status: ' . $setting->getError());
} }
} }

View File

@ -259,9 +259,9 @@ $aSettings['recaptcha'][] = array(
$aSettings['monitoring'][] = array( $aSettings['monitoring'][] = array(
'display' => 'Uptime Robot Private API Key', 'type' => 'text', 'display' => 'Uptime Robot Private API Key', 'type' => 'text',
'size' => 25, 'size' => 25,
'default' => 'MAIN_API_KEY', 'default' => '<API KEY>|<MONITOR ID>,<API KEY>|<MONITOR ID>, ...',
'name' => 'monitoring_uptimerobot_private_key', 'value' => $setting->getValue('monitoring_uptimerobot_private_key'), 'name' => 'monitoring_uptimerobot_private_key', 'value' => $setting->getValue('monitoring_uptimerobot_private_key'),
'tooltip' => 'Your private key. You can find it in your account as the Main API Key.' 'tooltip' => 'Create per-monitor API keys and save them here to propagate your uptime statistics.'
); );
?> ?>

View File

@ -4,22 +4,32 @@
<table class="tablesorter" width="80%" cellspacing="0"> <table class="tablesorter" width="80%" cellspacing="0">
<thead> <thead>
<tr> <tr>
<th align="center">Location</th> <th class="center">Location</th>
<th align="center">Service</th> <th class="center">Service</th>
<th align="center">State Since</th> <th class="center">State Since</th>
<th align="center">Status</th> <th class="center">Status</th>
<th align="center" style="padding-right: 10px">Uptime</th> <th class="center" colspan="4" style="padding-right: 10px">Uptime</th>
</tr>
<tr>
<th colspan="4"></th>
<th>Day</th>
<th>Week</th>
<th>Month</th>
<th>All Time</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{foreach key=key item=item from=$STATUS.monitors.monitor} {foreach key=key item=item from=$STATUS}
{assign var=node value="."|explode:$item.friendlyname} {assign var=node value="."|explode:$item.friendlyname}
<tr> <tr>
<td align="center"><img src="{$GLOBALASSETS}/images/flags/{$node.0}.png"/></td> <td class="center"><img src="{$GLOBALASSETS}/images/flags/{$node.0}.png"/></td>
<td align="center">{$node.1}</td> <td class="center">{$node.1}</td>
<td align="center">{$item.log.1.datetime|date_format:"%b %d, %Y %H:%M"}</td> <td class="center">{$item.log.1.datetime|date_format:"%b %d, %Y %H:%M"}</td>
<td align="center"><span class="ur-status-{$CODES[$item.status]|lower}">{$CODES[$item.status]}</span></td> <td class="center"><span class="ur-status-{$CODES[$item.status]|lower}">{$CODES[$item.status]}</span></td>
<td align="center"><span class="chart-{$item.id}" data-percent="{$item.customuptimeratio}"><span class="percent"></span></span></td> <td class="center"><span class="chart" data-percent="{$item.customuptimeratio.0}"><span class="percent"></span></span></td>
<td class="center"><span class="chart" data-percent="{$item.customuptimeratio.1}"><span class="percent"></span></span></td>
<td class="center"><span class="chart" data-percent="{$item.customuptimeratio.2}"><span class="percent"></span></span></td>
<td class="center"><span class="chart" data-percent="{$item.alltimeuptimeratio}"><span class="percent"></span></span></td>
</tr> </tr>
{/foreach} {/foreach}
</tbody> </tbody>
@ -29,10 +39,7 @@
<script> <script>
{literal} {literal}
$(document).ready(function(){ $(document).ready(function(){
{/literal} $('.chart').easyPieChart({
{foreach key=key item=item from=$STATUS.monitors.monitor}
{literal}
$('.chart-{/literal}{$item.id}{literal}').easyPieChart({
easing: 'easeOutBounce', easing: 'easeOutBounce',
size: 26, size: 26,
scaleColor: false, scaleColor: false,
@ -45,9 +52,6 @@ $(document).ready(function(){
$(this.el).find('.percent-{/literal}{$item.id}{literal}').text(Math.round(percent)); $(this.el).find('.percent-{/literal}{$item.id}{literal}').text(Math.round(percent));
} }
}); });
{/literal}
{/foreach}
{literal}
}); });
{/literal} {/literal}
</script> </script>

View File

@ -9,18 +9,28 @@
<th align="center">Service</th> <th align="center">Service</th>
<th align="center">Status</th> <th align="center">Status</th>
<th align="center">Status Since</th> <th align="center">Status Since</th>
<th align="center" style="padding-right: 10px">Uptime</th> <th align="center" colspan="4" style="padding-right: 10px">Uptime</th>
</tr>
<tr>
<th colspan="4"></th>
<th>Day</th>
<th>Week</th>
<th>Month</th>
<th>All Time</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{foreach key=key item=item from=$STATUS.monitors.monitor} {foreach key=key item=item from=$STATUS}
{assign var=node value="."|explode:$item.friendlyname} {assign var=node value="."|explode:$item.friendlyname}
<tr> <tr>
<td align="center"><img src="{$GLOBALASSETS}/images/flags/{$node.0}.png"/></td> <td align="center"><img src="{$GLOBALASSETS}/images/flags/{$node.0}.png"/></td>
<td align="center">{$node.1}</td> <td align="center">{$node.1}</td>
<td align="center"><span class="ur-status-{$CODES[$item.status]|lower}">{$CODES[$item.status]}</span></td> <td align="center"><span class="ur-status-{$CODES[$item.status]|lower}">{$CODES[$item.status]}</span></td>
<td align="center">{$item.log.1.datetime|date_format:"%b %d, %Y %H:%M"}</td> <td align="center">{$item.log.1.datetime|date_format:"%b %d, %Y %H:%M"}</td>
<td align="center"><span class="chart-{$item.id}" data-percent="{$item.customuptimeratio}"><span class="percent"></span></span></td> <td align="center"><span class="chart" data-percent="{$item.customuptimeratio.0}"><span class="percent"></span></span></td>
<td align="center"><span class="chart" data-percent="{$item.customuptimeratio.1}"><span class="percent"></span></span></td>
<td align="center"><span class="chart" data-percent="{$item.customuptimeratio.2}"><span class="percent"></span></span></td>
<td align="center"><span class="chart" data-percent="{$item.alltimeuptimeratio}"><span class="percent"></span></span></td>
</tr> </tr>
{/foreach} {/foreach}
</tbody> </tbody>
@ -33,10 +43,7 @@
<script> <script>
{literal} {literal}
$(document).ready(function(){ $(document).ready(function(){
{/literal} $('.chart').easyPieChart({
{foreach key=key item=item from=$STATUS.monitors.monitor}
{literal}
$('.chart-{/literal}{$item.id}{literal}').easyPieChart({
easing: 'easeOutBounce', easing: 'easeOutBounce',
size: 26, size: 26,
scaleColor: false, scaleColor: false,
@ -49,9 +56,6 @@ $(document).ready(function(){
$(this.el).find('.percent-{/literal}{$item.id}{literal}').text(Math.round(percent)); $(this.el).find('.percent-{/literal}{$item.id}{literal}').text(Math.round(percent));
} }
}); });
{/literal}
{/foreach}
{literal}
}); });
{/literal} {/literal}
</script> </script>