[IMPROVED] Allow multi-monitor setup via API Keys
This commit is contained in:
parent
861172e6f8
commit
272448dc6c
@ -10,14 +10,24 @@ class Monitoring extends Base {
|
||||
}
|
||||
|
||||
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';
|
||||
$target = '/getMonitors?apiKey=' . $api_key . '&format=json&noJsonCallback=1&customUptimeRatio=1&logs=1';
|
||||
if (!$json = json_encode($this->tools->getApi($url, $target))) {
|
||||
$this->setErrorMessage('Failed to run API call: ' . $this->tools->getError());
|
||||
return false;
|
||||
$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']);
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
@ -259,9 +259,9 @@ $aSettings['recaptcha'][] = array(
|
||||
$aSettings['monitoring'][] = array(
|
||||
'display' => 'Uptime Robot Private API Key', 'type' => 'text',
|
||||
'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'),
|
||||
'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.'
|
||||
);
|
||||
|
||||
?>
|
||||
|
||||
@ -4,22 +4,32 @@
|
||||
<table class="tablesorter" width="80%" cellspacing="0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th align="center">Location</th>
|
||||
<th align="center">Service</th>
|
||||
<th align="center">State Since</th>
|
||||
<th align="center">Status</th>
|
||||
<th align="center" style="padding-right: 10px">Uptime</th>
|
||||
<th class="center">Location</th>
|
||||
<th class="center">Service</th>
|
||||
<th class="center">State Since</th>
|
||||
<th class="center">Status</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>
|
||||
</thead>
|
||||
<tbody>
|
||||
{foreach key=key item=item from=$STATUS.monitors.monitor}
|
||||
{foreach key=key item=item from=$STATUS}
|
||||
{assign var=node value="."|explode:$item.friendlyname}
|
||||
<tr>
|
||||
<td align="center"><img src="{$GLOBALASSETS}/images/flags/{$node.0}.png"/></td>
|
||||
<td align="center">{$node.1}</td>
|
||||
<td align="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 align="center"><span class="chart-{$item.id}" data-percent="{$item.customuptimeratio}"><span class="percent"></span></span></td>
|
||||
<td class="center"><img src="{$GLOBALASSETS}/images/flags/{$node.0}.png"/></td>
|
||||
<td class="center">{$node.1}</td>
|
||||
<td class="center">{$item.log.1.datetime|date_format:"%b %d, %Y %H:%M"}</td>
|
||||
<td class="center"><span class="ur-status-{$CODES[$item.status]|lower}">{$CODES[$item.status]}</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>
|
||||
{/foreach}
|
||||
</tbody>
|
||||
@ -29,10 +39,7 @@
|
||||
<script>
|
||||
{literal}
|
||||
$(document).ready(function(){
|
||||
{/literal}
|
||||
{foreach key=key item=item from=$STATUS.monitors.monitor}
|
||||
{literal}
|
||||
$('.chart-{/literal}{$item.id}{literal}').easyPieChart({
|
||||
$('.chart').easyPieChart({
|
||||
easing: 'easeOutBounce',
|
||||
size: 26,
|
||||
scaleColor: false,
|
||||
@ -45,9 +52,6 @@ $(document).ready(function(){
|
||||
$(this.el).find('.percent-{/literal}{$item.id}{literal}').text(Math.round(percent));
|
||||
}
|
||||
});
|
||||
{/literal}
|
||||
{/foreach}
|
||||
{literal}
|
||||
});
|
||||
{/literal}
|
||||
</script>
|
||||
|
||||
@ -9,18 +9,28 @@
|
||||
<th align="center">Service</th>
|
||||
<th align="center">Status</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>
|
||||
</thead>
|
||||
<tbody>
|
||||
{foreach key=key item=item from=$STATUS.monitors.monitor}
|
||||
{foreach key=key item=item from=$STATUS}
|
||||
{assign var=node value="."|explode:$item.friendlyname}
|
||||
<tr>
|
||||
<td align="center"><img src="{$GLOBALASSETS}/images/flags/{$node.0}.png"/></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">{$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>
|
||||
{/foreach}
|
||||
</tbody>
|
||||
@ -33,10 +43,7 @@
|
||||
<script>
|
||||
{literal}
|
||||
$(document).ready(function(){
|
||||
{/literal}
|
||||
{foreach key=key item=item from=$STATUS.monitors.monitor}
|
||||
{literal}
|
||||
$('.chart-{/literal}{$item.id}{literal}').easyPieChart({
|
||||
$('.chart').easyPieChart({
|
||||
easing: 'easeOutBounce',
|
||||
size: 26,
|
||||
scaleColor: false,
|
||||
@ -49,9 +56,6 @@ $(document).ready(function(){
|
||||
$(this.el).find('.percent-{/literal}{$item.id}{literal}').text(Math.round(percent));
|
||||
}
|
||||
});
|
||||
{/literal}
|
||||
{/foreach}
|
||||
{literal}
|
||||
});
|
||||
{/literal}
|
||||
</script>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user