-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathEventsController.php
More file actions
123 lines (108 loc) · 3.81 KB
/
Copy pathEventsController.php
File metadata and controls
123 lines (108 loc) · 3.81 KB
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
<?php
// SPDX-FileCopyrightText: 2018 Icinga GmbH <https://icinga.com>
// SPDX-License-Identifier: GPL-3.0-or-later
namespace Icinga\Module\Vspheredb\Controllers;
use gipfl\IcingaWeb2\Link;
use gipfl\IcingaWeb2\Url;
use gipfl\Web\Widget\Hint;
use Icinga\Date\DateFormatter;
use Icinga\Module\Vspheredb\Web\Form\FilterHostParentForm;
use Icinga\Module\Vspheredb\Web\Table\EventHistoryTable;
use Icinga\Module\Vspheredb\Web\Controller;
use Icinga\Module\Vspheredb\Web\Widget\CalendarForEvents;
use Icinga\Module\Vspheredb\Web\Widget\VMotionHeatmap;
use Ramsey\Uuid\Uuid;
class EventsController extends Controller
{
public function init()
{
$this->assertPermission('vspheredb/admin');
parent::init();
$this->handleTabs();
}
public function indexAction()
{
$this->actions()->add(Link::create(
$this->translate('Calendar'),
'vspheredb/events/heatmap',
$this->url()->getParams()->toArray(false),
[
'class' => 'icon-calendar',
'data-base-target' => '_main',
]
));
$form = $this->addFilterForm();
$day = $this->params->get('day');
$table = new EventHistoryTable($this->db());
$table
->filterEventType($form->getElement('type')->getValue())
->filterParent($form->getElement('parent')->getValue());
if ($day) {
$dayStamp = strtotime($day);
$this->addTitle('Event History on %s', DateFormatter::formatDate($dayStamp));
$table->getQuery()->where(
'ts_event_ms >= ?',
strtotime("$day 00:00:00") * 1000
)->where(
'ts_event_ms <= ?',
(strtotime("$day 23:59:59") + 1) * 1000
);
} else {
$this->addTitle($this->translate('Event History'));
}
$count = count($table);
if ($count === 0) {
$this->content()->add(Hint::warning($this->translate('No events found')));
}
$table->renderTo($this);
}
protected function addFilterForm()
{
$form = new FilterHostParentForm($this->db());
$form->handleRequest($this->getServerRequest());
$this->content()->add($form);
return $form;
}
public function heatmapAction()
{
$this->actions()->add(Link::create(
$this->translate('Table'),
'vspheredb/events',
$this->url()->getParams()->toArray(false),
[
'class' => 'icon-th-list',
'data-base-target' => '_main',
]
));
$this->addTitle($this->translate('Event HeatMap'));
$form = $this->addFilterForm();
$heatMap = new VMotionHeatmap($this->db());
$heatMap->filterEventType($form->getElement('type')->getValue());
if ($parent = $form->getElement('parent')->getValue()) {
$heatMap->filterParent(Uuid::fromString($parent)->getBytes());
}
$baseUrl = Url::fromPath('vspheredb/events')->setParams(
$this->url()->getParams()
);
$this->content()->add(new CalendarForEvents($heatMap, $baseUrl, $form->getColors()));
}
protected function handleTabs()
{
$params = [];
if ($day = $this->params->get('day')) {
$params['day'] = $day;
$alarmsUrl = 'vspheredb/alarms';
} else {
$alarmsUrl = 'vspheredb/alarms/heatmap';
}
$tabs = $this->tabs()->add('events', [
'label' => $this->translate('Events'),
'url' => $this->url(),
])->add('alarms', [
'label' => $this->translate('Alarms'),
'url' => $alarmsUrl,
'urlParams' => $params
]);
$tabs->activate($this->getRequest()->getControllerName());
}
}