Skip to content

Commit febc9d3

Browse files
authored
Merge pull request #34 from NETWAYS/docs/inline-comments
Add and or cleanup some inline comments
2 parents f9fc8c8 + 4da855d commit febc9d3

File tree

7 files changed

+72
-94
lines changed

7 files changed

+72
-94
lines changed

application/controllers/ConfigController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
use Icinga\Web\Controller;
88

9+
/**
10+
* ConfigController for showing the module's configuration
11+
*/
912
class ConfigController extends Controller
1013
{
1114
public function init()

application/controllers/DashboardController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
use ipl\Web\Url;
1313

14+
/**
15+
* DashboardController for showing graphs for Monitoring Module dashboards
16+
*/
1417
class DashboardController extends Controller
1518
{
1619
public function init()
@@ -21,6 +24,7 @@ public function init()
2124

2225
public function indexAction()
2326
{
27+
// Redirect to IcingaDB if it is enabled
2428
if (Module::exists('icingadb') && IcingadbSupport::useIcingaDbAsBackend()) {
2529
$this->redirectNow(Url::fromPath('grafana/icingadbdashboard')->setQueryString($this->params));
2630
}

application/controllers/GraphController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ public function newAction()
4242
->setIniConfig($this->Config('graphs'))
4343
->setRedirectUrl('grafana/graph')
4444
->handleRequest();
45+
4546
$this->view->form = $graphs;
4647
}
48+
4749
/**
4850
* Remove a graph
4951
*/

application/controllers/IcingadbdashboardController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
use ipl\Web\Url;
1212

13+
/**
14+
* IcingadbdashboardController for showing graphs for IcingaDB Module dashboards
15+
*/
1316
class IcingadbdashboardController extends IcingadbGrafanaController
1417
{
1518
public function init()

application/controllers/IcingadbimgController.php

Lines changed: 45 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
use ipl\Stdlib\Filter;
1414
use ipl\Web\Url;
1515

16+
/**
17+
* IcingadbimgController loads graphs as images from the grafana-image-renderer.
18+
*/
1619
class IcingadbimgController extends IcingadbGrafanaController
1720
{
1821
protected $host;
@@ -21,26 +24,26 @@ class IcingadbimgController extends IcingadbGrafanaController
2124
protected $myConfig;
2225
protected $myAuth;
2326
protected $authentication;
24-
protected $grafanaHost = null;
25-
protected $grafanaTheme = null;
26-
protected $protocol = "http";
27-
protected $username = null;
28-
protected $password = null;
29-
protected $apiToken = null;
30-
protected $width = 640;
31-
protected $height = 280;
32-
protected $defaultDashboard = "icinga2-default";
33-
protected $defaultDashboardPanelId = "1";
34-
protected $defaultOrgId = "1";
35-
protected $shadows = false;
36-
protected $dataSource = null;
37-
protected $proxyTimeout = "5";
38-
protected $custvarconfig = "grafana_graph_config";
39-
protected $SSLVerifyPeer = false;
40-
protected $SSLVerifyHost = "0";
41-
protected $cacheTime = 300;
27+
protected $grafanaHost = null;
28+
protected $grafanaTheme = null;
29+
protected $protocol = "http";
30+
protected $username = null;
31+
protected $password = null;
32+
protected $apiToken = null;
33+
protected $width = 640;
34+
protected $height = 280;
4235
protected $defaultdashboarduid;
43-
protected $enableCache = "yes";
36+
protected $defaultDashboard = "icinga2-default";
37+
protected $defaultDashboardPanelId = "1";
38+
protected $defaultOrgId = "1";
39+
protected $shadows = false;
40+
protected $dataSource = null;
41+
protected $proxyTimeout = "5";
42+
protected $custvarconfig = "grafana_graph_config";
43+
protected $SSLVerifyPeer = false;
44+
protected $SSLVerifyHost = "0";
45+
protected $cacheTime = 300;
46+
protected $enableCache = "yes";
4447
protected $customVars;
4548
protected $timerangeto;
4649
protected $object;
@@ -49,17 +52,21 @@ class IcingadbimgController extends IcingadbGrafanaController
4952
protected $panelId;
5053
protected $orgId;
5154

55+
/**
56+
* Mainly loading defaults and the configuration.
57+
*/
5258
public function init()
5359
{
5460
if (! $this->useIcingadbAsBackend) {
5561
$this->redirectNow(Url::fromPath('grafana/dashboard')->setQueryString($this->params));
5662
}
57-
/* we need at least a host name */
63+
64+
// We need at least a host name
5865
if (is_null($this->getParam('host'))) {
5966
throw new \Error('No host given!');
6067
}
6168

62-
/* save timerange from params for later use */
69+
// Save timerange from params for later use
6370
$this->timerange = $this->hasParam('timerange') ? urldecode($this->getParam('timerange')) : null;
6471
if ($this->hasParam('timerangeto')) {
6572
$this->timerangeto = urldecode($this->getParam('timerangeto'));
@@ -70,16 +77,18 @@ public function init()
7077
// Get the cachetime URL parameter and use the default if not present
7178
$this->cacheTime = $this->hasParam('cachetime') ? $this->getParam('cachetime') : $this->cacheTime;
7279

73-
/* load global configuration */
80+
// Load global configuration
7481
$this->myConfig = Config::module('grafana')->getSection('grafana');
7582
$this->grafanaHost = $this->myConfig->get('host', $this->grafanaHost);
7683
if ($this->grafanaHost == null) {
7784
throw new ConfigurationError(
7885
'No Grafana host configured!'
7986
);
8087
}
88+
8189
$this->protocol = $this->myConfig->get('protocol', $this->protocol);
8290

91+
// Get defaults for Grafana dashboards
8392
$this->defaultDashboard = $this->myConfig->get('defaultdashboard', $this->defaultDashboard);
8493
$this->defaultdashboarduid = $this->myConfig->get('defaultdashboarduid', null);
8594
if (is_null($this->defaultdashboarduid)) {
@@ -91,43 +100,27 @@ public function init()
91100
'defaultdashboardpanelid',
92101
$this->defaultDashboardPanelId
93102
);
103+
94104
$this->defaultOrgId = $this->myConfig->get('defaultorgid', $this->defaultOrgId);
95105
$this->grafanaTheme = Util::getUserThemeMode(Auth::getInstance()->getUser());
96106
$this->height = $this->myConfig->get('height', $this->height);
97107
$this->width = $this->myConfig->get('width', $this->width);
98108
$this->proxyTimeout = $this->myConfig->get('proxytimeout', $this->proxyTimeout);
99109
$this->enableCache = $this->myConfig->get('enablecache', $this->enableCache);
100-
/**
101-
* Read the global default timerange
102-
*/
110+
111+
// Read the global default timerange
103112
if ($this->timerange == null) {
104113
$this->timerange = $this->config->get('timerange', $this->timerange);
105114
}
106-
/**
107-
* Datasource needed to regex special chars
108-
*/
115+
116+
// Datasource needed to regex special chars
109117
$this->dataSource = $this->myConfig->get('datasource', $this->dataSource);
110-
/**
111-
* Display shadows around graph
112-
*/
113118
$this->shadows = $this->myConfig->get('shadows', $this->shadows);
114-
/**
115-
* Name of the custom variable for graph config
116-
*/
117119
$this->custvarconfig = ($this->myConfig->get('custvarconfig', $this->custvarconfig));
118-
/**
119-
* Verify the certificate's name against host
120-
*/
121120
$this->SSLVerifyHost = ($this->myConfig->get('ssl_verifyhost', $this->SSLVerifyHost));
122-
/**
123-
* Verify the peer's SSL certificate
124-
*/
125121
$this->SSLVerifyPeer = ($this->myConfig->get('ssl_verifypeer', $this->SSLVerifyPeer));
126122

127-
/**
128-
* Username & Password or token
129-
*/
130-
123+
// Username & Password or token
131124
$this->apiToken = $this->myConfig->get('apitoken', $this->apiToken);
132125
$this->authentication = $this->myConfig->get('authentication');
133126
if ($this->apiToken == null && $this->authentication == "token") {
@@ -192,7 +185,8 @@ public function indexAction()
192185
$this->customVars = str_replace($search, $replace, $this->customVars);
193186
}
194187

195-
// urlencode values
188+
// urlencode custom variable values
189+
// TODO: Could this be a Util function?
196190
$customVars = "";
197191
foreach (preg_split('/\&/', $this->customVars, -1, PREG_SPLIT_NO_EMPTY) as $param) {
198192
$arr = explode("=", $param);
@@ -206,7 +200,8 @@ public function indexAction()
206200
}
207201
$this->customVars = $customVars;
208202
}
209-
// replace special chars for graphite
203+
204+
// Replace special chars for graphite
210205
if ($this->dataSource == "graphite") {
211206
$serviceName = Util::graphiteReplace($serviceName);
212207
$hostName = Util::graphiteReplace($hostName);
@@ -225,8 +220,8 @@ public function indexAction()
225220
$string = wordwrap($this->translate('Error'). ': ' . $imageHtml, 40, "\n");
226221
$lines = explode("\n", $string);
227222
$im = @imagecreate($this->width, $this->height);
228-
$background_color = imagecolorallocate($im, 255, 255, 255); //white background
229-
$text_color = imagecolorallocate($im, 255, 0, 0);//black text
223+
$background_color = imagecolorallocate($im, 255, 255, 255);
224+
$text_color = imagecolorallocate($im, 255, 0, 0);
230225
foreach ($lines as $i => $line) {
231226
imagestring($im, 5, 0, 5 + $i * 15, $line, $text_color);
232227
}
@@ -275,6 +270,7 @@ private function setGraphConf($serviceName, $serviceCommand = null)
275270
private function getMyimageHtml($serviceName, $hostName, &$imageHtml)
276271
{
277272
$imgClass = $this->shadows ? "grafana-img grafana-img-shadows" : "grafana-img";
273+
278274
// Test whether curl is loaded
279275
if (extension_loaded('curl') === false) {
280276
$imageHtml = $this->translate('CURL extension is missing.'
@@ -352,6 +348,7 @@ private function getMyimageHtml($serviceName, $hostName, &$imageHtml)
352348

353349
curl_close($curl_handle);
354350
$imageHtml = $result;
351+
355352
return true;
356353
}
357354
}

application/controllers/IcingadbshowController.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
class IcingadbshowController extends IcingadbGrafanaController
2020
{
21-
/** @var bool */
2221
protected $showFullscreen;
2322
protected $host;
2423
protected $custvardisable = 'grafana_graph_disable';
@@ -33,9 +32,8 @@ public function init()
3332
= (bool)$this->_helper->layout()->showFullscreen;
3433
$this->host = $this->getParam('host');
3534
$this->config = Config::module('grafana')->getSection('grafana');
36-
/**
37-
* Name of the custom variable to disable graph
38-
*/
35+
36+
// Name of the custom variable to disable graph
3937
$this->custvardisable = ($this->config->get('custvardisable', $this->custvardisable));
4038
}
4139

@@ -57,11 +55,10 @@ public function indexAction()
5755
$parameters['timerange'] = $this->getParam('timerange');
5856
}
5957

60-
/* The timerange menu */
6158
$menu = new Timeranges($parameters, 'grafana/icingadbshow');
6259
$this->addControl(new HtmlString($menu->getTimerangeMenu()));
6360

64-
/* first host object for host graph */
61+
// First host object for host graph
6562
$this->object = $this->getHostObject($this->host);
6663
$varsFlat = CustomvarFlat::on($this->getDb());
6764
$this->applyRestrictions($varsFlat);
@@ -70,7 +67,9 @@ public function indexAction()
7067
->columns(['flatname', 'flatvalue'])
7168
->orderBy('flatname');
7269
$varsFlat->filter(Filter::equal('host.id', $this->object->id));
70+
7371
$customVars = $this->getDb()->fetchPairs($varsFlat->assembleSelect());
72+
7473
if ($this->object->perfdata_enabled == "y"
7574
|| !(isset($customVars[$this->custvardisable])
7675
&& json_decode(strtolower($customVars[$this->custvardisable])) !== false)
@@ -80,13 +79,15 @@ public function indexAction()
8079
$this->addContent($object);
8180
$this->addContent((new HostDetailExtension())->getPreviewHtml($this->object, true));
8281
}
83-
/* Get all services for this host */
82+
83+
// Get all services for this host
8484
$query = Service::on($this->getDb())->with([
8585
'state',
8686
'icon_image',
8787
'host',
8888
'host.state'
8989
]);
90+
9091
$query->filter(Filter::equal('host.name', $this->host));
9192

9293
$this->applyRestrictions($query);
@@ -101,6 +102,7 @@ public function indexAction()
101102
->orderBy('flatname');
102103
$varsFlat->filter(Filter::equal('service.id', $service->id));
103104
$customVars = $this->getDb()->fetchPairs($varsFlat->assembleSelect());
105+
104106
if ($this->object->perfdata_enabled == "y"
105107
&& !(isset($customVars[$this->custvardisable])
106108
&& json_decode(strtolower($customVars[$this->custvardisable])) !== false)

0 commit comments

Comments
 (0)