Skip to content

Commit 87e5aeb

Browse files
authored
Merge pull request #81 from mrdsam/grafana_link_switch
Feature: Config option that switches Grafana-Link destination
2 parents 993a04b + b03cad1 commit 87e5aeb

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

application/forms/Config/GeneralConfigForm.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,17 @@ public function createElements(array $formData)
161161
]
162162
);
163163

164+
// Grafana link to dashboard/panel configuration
165+
$this->addElement(
166+
'checkbox',
167+
'grafana_dashboardlink',
168+
[
169+
'value' => false,
170+
'label' => $this->translate('Link to dashboard'),
171+
'description' => $this->translate('Link points to the dashboard instead of a single panel.'),
172+
]
173+
);
174+
164175
// Default theme
165176
$this->addElement(
166177
'select',

doc/03-module-configuration.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ publicprotocol = "http"
3838
custvardisable = "idontwanttoseeagraph"
3939
ssl_verifypeer = "0"
4040
ssl_verifyhost = "0"
41+
dashboardlink = "0"
4142
```
4243

4344
Hint: to display debug information for graphs you can use the URL parameter `&grafanaDebug`. This requires the `grafana/debug` permission.
@@ -57,6 +58,7 @@ Hint: to display debug information for graphs you can use the URL parameter `&gr
5758
|defaultdashboarduid | **Required for Grafana 5** The UID of the default dashboard for **Grafana 5**.
5859
|defaultdashboardpanelid| **Required** IDs of the panels used in the default dashboard. Defaults to `1`.
5960
|shadows | **Optional.** Show shadows around the graphs. ** Defaults to `false`.|
61+
|dashboardlink | **Optional.** Link to the dashboard instead to a single panel. |
6062
|defaultorgid | **Required.** Number of the default organization id where dashboards are located. Defaults to `1`.
6163
|accessmode | **Optional.** Controls whether graphs are fetched with curl (`indirectproxy`) or in iframe ('iframe'). Iframe needs `auth.anonymous` enabled in Grafana. Defaults to `indirectproxy`.|
6264
|timeout | **Proxy only** **Optional.** Timeout in seconds for proxy mode to fetch images. Defaults to `5`.|
@@ -123,6 +125,9 @@ The IDs of the panels used in the default dashboard. Defaults to `1`.
123125
### shadows
124126
Enable/Disable fancy shadows around the graph image.
125127

128+
### dashboardlink
129+
Controls whether the "view in grafana" link points to the whole dashboard or only to the panel (default). This is useful when only specific or single panels are shown in Icingaweb2 and the dashboard contains additional panels.
130+
126131
### accessmode
127132
Controls how the graphs are fetched/delivered for/to the users.
128133
Defaults to `indirectproxy`.

library/Grafana/ProvidedHook/Icingadb/IcingaDbGrapher.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ trait IcingaDbGrapher
6161
protected $defaultDashboardPanelId = "1";
6262
protected $defaultOrgId = "1";
6363
protected $shadows = false;
64+
protected $dashboardLink = false;
6465
protected $dataSource = null;
6566
protected $accessMode = "proxy";
6667
protected $proxyTimeout = "5";
@@ -142,6 +143,7 @@ protected function init()
142143
$this->timerange = $this->config->get('timerange', $this->timerange);
143144
$this->dataSource = $this->config->get('datasource', $this->dataSource);
144145
$this->shadows = $this->config->get('shadows', $this->shadows);
146+
$this->dashboardLink = $this->config->get('dashboardlink', $this->dashboardLink);
145147
$this->custvardisable = ($this->config->get('custvardisable', $this->custvardisable));
146148
$this->custvarconfig = ($this->config->get('custvarconfig', $this->custvarconfig));
147149

@@ -482,7 +484,11 @@ public function getPreviewHtml(Model $object, $report = false): ValidHtml
482484
// Add Link to Panel if the user has the permission
483485
if ($this->permission->hasPermission('grafana/showlink')) {
484486
$linkUrl = $url;
485-
$linkUrl = preg_replace('/(viewPanel=)[^&]+/', '${1}' . $panelid, $linkUrl);
487+
if ($this->dashboardLink) {
488+
$linkUrl = preg_replace('/(viewPanel=)[^&]+/', '', $linkUrl);
489+
} else {
490+
$linkUrl = preg_replace('/(viewPanel=)[^&]+/', '${1}' . $panelid, $linkUrl);
491+
}
486492
$textLink = new Link('View in Grafana', $linkUrl, ['target' => '_blank', 'class' => 'external-link']);
487493
$html->add($textLink);
488494
$iconLink = new Link(new Icon('arrow-up-right-from-square', ['title' => 'View in Grafana']), $linkUrl, ['target' => '_blank', 'class' => 'external-link']);

0 commit comments

Comments
 (0)