Skip to content

Commit a10b936

Browse files
authored
Merge pull request #16 from NETWAYS/chore/review
Normalize and Cleanup Code
2 parents 08d523e + 2faabd9 commit a10b936

18 files changed

+292
-327
lines changed

application/controllers/DashboardController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ public function indexAction()
2323
$this->redirectNow(Url::fromPath('grafana/icingadbdashboard')->setQueryString($this->params));
2424
}
2525

26-
$this->getTabs()->add('graphs', array(
26+
$this->getTabs()->add('graphs', [
2727
'active' => true,
2828
'label' => $this->translate('Graphs'),
2929
'url' => $this->getRequest()->getUrl()
30-
));
30+
]);
3131

3232
$hostname = $this->params->getRequired('host');
3333
$servicename = $this->params->get('service');

application/controllers/GraphController.php

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,23 @@ public function init()
2020
*/
2121
public function indexAction()
2222
{
23-
/*
24-
$this->getTabs()->add('graphs', array(
25-
'active' => true,
26-
'label' => $this->translate('Graphs'),
27-
'url' => $this->getRequest()->getUrl()
28-
));
29-
$this->view->graphs = $this->Config('graphs');
30-
*/
3123
$this->view->tabs = $this->Module()->getConfigTabs()->activate('graph');
3224
$this->view->graphs = $this->Config('graphs');
3325
}
26+
3427
/**
3528
* Add a new graph
3629
*/
3730
public function newAction()
3831
{
39-
$this->getTabs()->add('new-graph', array(
40-
'active' => true,
41-
'label' => $this->translate('New Graph'),
42-
'url' => $this->getRequest()->getUrl()
43-
));
32+
$this->getTabs()->add('new-graph', [
33+
'active' => true,
34+
'label' => $this->translate('New Graph'),
35+
'url' => $this->getRequest()->getUrl()
36+
]);
37+
4438
$graphs = new GraphForm();
39+
4540
$graphs
4641
->setIniConfig($this->Config('graphs'))
4742
->setRedirectUrl('grafana/graph')
@@ -54,20 +49,23 @@ public function newAction()
5449
public function removeAction()
5550
{
5651
$graph = $this->params->getRequired('graph');
57-
$this->getTabs()->add('remove-graph', array(
58-
'active' => true,
59-
'label' => $this->translate('Remove Graph'),
60-
'url' => $this->getRequest()->getUrl()
61-
));
52+
$this->getTabs()->add('remove-graph', [
53+
'active' => true,
54+
'label' => $this->translate('Remove Graph'),
55+
'url' => $this->getRequest()->getUrl()
56+
]);
57+
6258
$graphs = new GraphForm();
59+
6360
try {
6461
$graphs
6562
->setIniConfig($this->Config('graphs'))
6663
->bind($graph);
6764
} catch (NotFoundError $e) {
6865
$this->httpNotFound($e->getMessage());
6966
}
70-
$confirmation = new ConfirmRemovalForm(array(
67+
68+
$confirmation = new ConfirmRemovalForm([
7169
'onSuccess' => function (ConfirmRemovalForm $confirmation) use ($graph, $graphs) {
7270
$graphs->remove($graph);
7371
if ($graphs->save()) {
@@ -76,35 +74,42 @@ public function removeAction()
7674
}
7775
return false;
7876
}
79-
));
77+
]);
78+
8079
$confirmation
8180
->setRedirectUrl('grafana/graph')
8281
->setSubmitLabel($this->translate('Remove Graph'))
8382
->handleRequest();
83+
8484
$this->view->form = $confirmation;
8585
}
86+
8687
/**
8788
* Update a graph
8889
*/
8990
public function updateAction()
9091
{
9192
$graph = $this->params->getRequired('graph');
92-
$this->getTabs()->add('update-graph', array(
93-
'active' => true,
94-
'label' => $this->translate('Update Graph'),
95-
'url' => $this->getRequest()->getUrl()
96-
));
93+
$this->getTabs()->add('update-graph', [
94+
'active' => true,
95+
'label' => $this->translate('Update Graph'),
96+
'url' => $this->getRequest()->getUrl()
97+
]);
98+
9799
$graphs = new GraphForm();
100+
98101
try {
99102
$graphs
100103
->setIniConfig($this->Config('graphs'))
101104
->bind($graph);
102105
} catch (NotFoundError $e) {
103106
$this->httpNotFound($e->getMessage());
104107
}
108+
105109
$graphs
106110
->setRedirectUrl('grafana/graph')
107111
->handleRequest();
112+
108113
$this->view->form = $graphs;
109114
}
110115
}

application/controllers/IcingadbdashboardController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ public function indexAction()
5656
}
5757

5858
$this->applyRestrictions($query);
59+
5960
$object = $query->first();
61+
6062
if ($object === null) {
6163
throw new NotFoundError(t('Host or Service not found'));
6264
}

application/controllers/IcingadbimgController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,15 +348,15 @@ private function getMyimageHtml($serviceName, $hostName, &$imageHtml)
348348

349349
// fetch image with curl
350350
$curl_handle = curl_init();
351-
$curl_opts = array(
351+
$curl_opts = [
352352
CURLOPT_URL => $pngUrl,
353353
CURLOPT_CONNECTTIMEOUT => 2,
354354
CURLOPT_FOLLOWLOCATION => true,
355355
CURLOPT_RETURNTRANSFER => true,
356356
CURLOPT_SSL_VERIFYPEER => $this->SSLVerifyPeer,
357357
CURLOPT_SSL_VERIFYHOST => ($this->SSLVerifyHost) ? 2 : 0,
358358
CURLOPT_TIMEOUT => $this->proxyTimeout,
359-
);
359+
];
360360

361361
if ($this->authentication == "token") {
362362
$curl_opts[CURLOPT_HTTPHEADER] = [

application/controllers/IcingadbshowController.php

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Icinga\Module\Grafana\ProvidedHook\Icingadb\HostDetailExtension;
77
use Icinga\Module\Grafana\ProvidedHook\Icingadb\ServiceDetailExtension;
88
use Icinga\Module\Grafana\Web\Controller\IcingadbGrafanaController;
9-
use Icinga\Module\Grafana\Web\Widget\PrintAction;
109
use Icinga\Module\Icingadb\Model\CustomvarFlat;
1110
use Icinga\Module\Icingadb\Model\Host;
1211
use Icinga\Module\Icingadb\Model\Service;
@@ -16,14 +15,13 @@
1615
use ipl\Html\HtmlElement;
1716
use ipl\Html\HtmlString;
1817
use ipl\Stdlib\Filter;
19-
use ipl\Web\Url;
2018

2119
class IcingadbshowController extends IcingadbGrafanaController
2220
{
2321
/** @var bool */
2422
protected $showFullscreen;
2523
protected $host;
26-
protected $custvardisable = "grafana_graph_disable";
24+
protected $custvardisable = 'grafana_graph_disable';
2725
protected $config;
2826
protected $object;
2927

@@ -45,20 +43,6 @@ public function indexAction()
4543
{
4644
$this->disableAutoRefresh();
4745

48-
/*
49-
if (!$this->showFullscreen) {
50-
$this->getTabs()->add(
51-
'graphs',
52-
[
53-
'label' => $this->translate('Grafana Graphs'),
54-
'url' => $this->getRequest()->getUrl()
55-
]
56-
)->activate('graphs');
57-
58-
$this->getTabs()->extend(new PrintAction());
59-
}
60-
*/
61-
6246
$this->addControl(
6347
HtmlElement::create(
6448
'h1',
@@ -133,7 +117,7 @@ public function indexAction()
133117
}
134118

135119

136-
public function getHostObject($host)
120+
public function getHostObject(string $host): Host
137121
{
138122
$query = Host::on($this->getDb())->with(['state', 'icon_image']);
139123
$query->filter(Filter::equal('name', $host));
@@ -147,7 +131,7 @@ public function getHostObject($host)
147131
return $host;
148132
}
149133

150-
public function getServiceObject($service, $host)
134+
public function getServiceObject(string $service, string $host): Service
151135
{
152136
$query = Service::on($this->getDb());
153137

0 commit comments

Comments
 (0)