-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathPerfdataController.php
More file actions
110 lines (102 loc) · 4.38 KB
/
Copy pathPerfdataController.php
File metadata and controls
110 lines (102 loc) · 4.38 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
<?php
// SPDX-FileCopyrightText: 2019 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 gipfl\ZfDbStore\NotFoundError;
use gipfl\ZfDbStore\ZfDbStore;
use Icinga\Module\Vspheredb\Storable\PerfdataConsumer;
use Icinga\Module\Vspheredb\Web\Controller;
use Icinga\Module\Vspheredb\Web\Form\FilterVCenterForm;
use Icinga\Module\Vspheredb\Web\Form\PerfdataConsumerForm;
use Icinga\Module\Vspheredb\Web\Table\PerfDataConsumerTable;
use Icinga\Module\Vspheredb\Web\Table\PerformanceCounterTable;
use Icinga\Module\Vspheredb\Web\Tabs\ConfigTabs;
use Icinga\Module\Vspheredb\Web\Tabs\VCenterTabs;
use Icinga\Module\Vspheredb\Web\Widget\AdditionalTableActions;
use Icinga\Web\Notification;
use ipl\Html\Html;
use Ramsey\Uuid\Uuid;
class PerfdataController extends Controller
{
use AsyncControllerHelper;
public function init()
{
$this->assertPermission('vspheredb/admin');
}
public function countersAction()
{
$vCenter = $this->requireVCenter();
$this->tabs(new VCenterTabs($vCenter))->activate('perfcounters');
$this->addTitle($this->translate('Available Performance Counters'));
$form = new FilterVCenterForm($this->db(), $this->Auth());
$form->handleRequest($this->getServerRequest());
$this->content()->add($form);
$uuid = $form->getHexUuid();
if ($uuid === null) {
return;
}
$table = (new PerformanceCounterTable($this->db(), $this->url(), $vCenter));
(new AdditionalTableActions($table, $this->Auth(), $this->url()))
->appendTo($this->actions());
$table->renderTo($this);
}
public function consumersAction()
{
$this->setAutorefreshInterval(10);
$this->tabs(new ConfigTabs())->activate('perfdata');
$this->addTitle($this->translate('Performance Data Consumers'));
$this->actions()->add(Link::create($this->translate('Add'), 'vspheredb/perfdata/consumer', null, [
'data-base-target' => '_next',
'class' => 'icon-plus',
]));
$table = new PerfDataConsumerTable($this->db()->getDbAdapter());
if (count($table) === 0) {
$this->content()->add(Hint::info($this->translate('Please create your first Performance Data Consumer')));
return;
}
$table->renderTo($this);
}
public function consumerAction()
{
$store = new ZfDbStore($this->db()->getDbAdapter());
$form = new PerfdataConsumerForm($this->loop(), $this->remoteClient(), $store);
$form->on($form::ON_DELETE, function () {
Notification::success($this->translate('Performance Data Consumer has been removed'));
$this->redirectNow('vspheredb/perfdata/consumers');
});
$form->on(PerfdataConsumerForm::ON_SUCCESS, function (PerfdataConsumerForm $form) {
if ($form->wasNew()) {
Notification::success($this->translate('Performance Data Consumer has been created'));
} else {
Notification::success($this->translate('Performance Data Consumer has been updated'));
}
$this->redirectNow(Url::fromPath('vspheredb/perfdata/consumer', [
'uuid' => Uuid::fromBytes($form->getObject()->get('uuid'))->toString()
]));
});
$uuid = $this->params->get('uuid');
if ($uuid === null) {
$this->addSingleTab($this->translate('Add Consumer'));
$this->addTitle($this->translate('Define a new Performance Data Consumer'));
} else {
$this->addSingleTab($this->translate('Consumer'));
$uuid = Uuid::fromString($uuid);
try {
$consumer = $store->load($uuid->getBytes(), PerfdataConsumer::class);
} catch (NotFoundError $e) {
$this->addTitle($this->translate('Not found'));
$this->content()->add(
Hint::error($this->translate('There is no such Performance Data Consumer: %s'), $uuid->toString())
);
return;
}
$this->addTitle($consumer->get('name'));
$form->setObject($consumer);
}
$form->handleRequest($this->getServerRequest());
$this->content()->add($form);
}
}