-
Notifications
You must be signed in to change notification settings - Fork 0
/
Controller.php
127 lines (100 loc) · 4.02 KB
/
Controller.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
* @copyright (c) 2014-2016, Joachim Barthel
* @author Joachim Barthel <jobarthel@gmail.com>
* @category Piwik_Plugins
* @package UptimeRobotMonitor
**/
namespace Piwik\Plugins\UptimeRobotMonitor;
use Piwik\API\Request;
use Piwik\Common;
use Piwik\Date;
use Piwik\Piwik;
use Piwik\View;
use Piwik\ViewDataTable\Factory as ViewDataTableFactory;
class Controller extends \Piwik\Plugin\Controller
{
protected $apiKey = '';
/**
* Container for the Live Log List widget
**/
function widgetLiveLogList()
{
$settings = new Settings('UptimeRobotMonitor');
$apiKeys = explode( "\n", $settings->apiKeys->getValue() );
$output = '';
foreach ($apiKeys as $index => $apiKey) {
$apiKey = trim($apiKey);
$monitorData = API::getInstance()->getMonitorData($apiKey);
$output .= '<div style="font-size:1.1em;font-weight:bold;background-color:#e0e0e0;padding:6px;" title="' . $monitorData->url . '">' . $monitorData->friendlyname . '</div>';
$output .= $this->widgetLiveLogTable($index, $apiKey);
}
return $output;
}
/**
* This widget shows ...
**/
function widgetLiveLogTable($index, $apiKey)
{
$controllerAction = $this->pluginName . '.' . __FUNCTION__;
$apiAction = 'UptimeRobotMonitor.getLiveLogData' . $index;
$this->apiKey = $apiKey;
$view = ViewDataTableFactory::build('table', $apiAction, $controllerAction);
$view->config->columns_to_display = array('type', 'datetime', 'timediff');
$view->config->translations['type'] = Piwik::translate('UptimeRobotMonitor_Event');
$view->config->translations['datetime'] = Piwik::translate('UptimeRobotMonitor_DateTime');
$view->config->translations['timediff'] = Piwik::translate('UptimeRobotMonitor_Duration');
$view->requestConfig->filter_sort_column = 'datetime';
$view->requestConfig->filter_sort_order = 'asc';
$view->requestConfig->filter_limit = 5;
$view->config->show_exclude_low_population = false;
$view->config->show_table_all_columns = false;
$view->config->show_all_views_icons = false;
$view->config->disable_row_evolution = true;
$view->config->enable_sort = false;
$view->config->show_search = false;
return $view->render();
}
/**
* Container for the TimeBars of all monitored servers
**/
function widgetTimeBar()
{
$settings = new Settings('UptimeRobotMonitor');
$widgets = explode( "---", $settings->apiKeys->getValue() );
$widgetNo = Common::getRequestVar('id');
$apiKeys = explode( "\n", $widgets[$widgetNo] );
$output = '';
foreach ($apiKeys as $index => $apiKey) {
$apiKey = trim($apiKey);
if (strlen($apiKey) > 5) {
$output .= $this->widgetTimeBarElement($apiKey);
}
}
return $output;
}
/**
* This widget shows one timebar (for one monitor)
**/
function widgetTimeBarElement($apiKey)
{
$monitorData = API::getInstance()->getMonitorData($apiKey);
$logData = API::getInstance()->getTimeBarData($apiKey);
$settings = new Settings('UptimeRobotMonitor');
$watchTime = '-' . $settings->monitorRange->getValue() . ' day';
$dateStart = Common::getRequestVar('date', false);
$dateEnd = date('Y-m-d', strtotime($watchTime, strtotime($dateStart)));
$view = new View('@UptimeRobotMonitor/widgetTimeBarElement.twig');
$this->setBasicVariablesView($view);
$view->friendlyName = $monitorData->friendlyname;
$view->url = $monitorData->url;
$view->timeRange = array( 'start' => $dateStart, 'end' => $dateEnd );
$view->timeBar = $logData;
return $view->render();
}
}