-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathAlarmsController.php
More file actions
94 lines (85 loc) · 2.85 KB
/
Copy pathAlarmsController.php
File metadata and controls
94 lines (85 loc) · 2.85 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
<?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 Icinga\Date\DateFormatter;
use Icinga\Module\Vspheredb\Web\Table\AlarmHistoryTable;
use Icinga\Module\Vspheredb\Web\Controller;
use Icinga\Module\Vspheredb\Web\Widget\AlarmHeatmap;
use Icinga\Module\Vspheredb\Web\Widget\CalendarForEvents;
class AlarmsController 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/alarms/heatmap',
$this->url()->getParams()->toArray(false),
[
'class' => 'icon-calendar',
'data-base-target' => '_main',
]
));
$day = $this->params->shift('day');
$table = new AlarmHistoryTable($this->db());
if ($day) {
$dayStamp = strtotime($day);
$this->addTitle('Alarm 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('Alarm History');
}
$table->renderTo($this);
}
public function heatmapAction()
{
$this->actions()->add(Link::create(
$this->translate('Table'),
'vspheredb/alarms',
$this->url()->getParams()->toArray(false),
[
'class' => 'icon-th-list',
'data-base-target' => '_main',
]
));
$this->addTitle($this->translate('Alarm Heatmap'));
$heatMap = new AlarmHeatmap($this->db());
$baseUrl = Url::fromPath('vspheredb/alarms')->setParams(
$this->url()->getParams()
);
$this->content()->add(new CalendarForEvents($heatMap, $baseUrl, [255, 0, 0]));
}
protected function handleTabs()
{
$params = [];
if ($day = $this->params->get('day')) {
$params['day'] = $day;
$eventsUrl = 'vspheredb/events';
} else {
$eventsUrl = 'vspheredb/events/heatmap';
}
$tabs = $this->tabs()->add('events', [
'label' => $this->translate('Events'),
'url' => $eventsUrl,
'urlParams' => $params
])->add('alarms', [
'label' => $this->translate('Alarms'),
'url' => $this->url()
]);
$tabs->activate($this->getRequest()->getControllerName());
}
}