From cfd5d6dc3d8b20e9ffdd1a747f9717da0d899db6 Mon Sep 17 00:00:00 2001 From: Markus Opolka Date: Tue, 3 Dec 2024 15:10:19 +0100 Subject: [PATCH] Remove enableLink configuration and permission --- .../forms/Config/GeneralConfigForm.php | 16 +-- configuration.php | 1 - doc/03-module-configuration.md | 5 - .../ProvidedHook/Icingadb/IcingaDbGrapher.php | 100 +++++++++--------- 4 files changed, 50 insertions(+), 72 deletions(-) diff --git a/application/forms/Config/GeneralConfigForm.php b/application/forms/Config/GeneralConfigForm.php index 957866a..abb652f 100644 --- a/application/forms/Config/GeneralConfigForm.php +++ b/application/forms/Config/GeneralConfigForm.php @@ -271,22 +271,8 @@ public function createElements(array $formData) 'description' => $this->translate('The default graph width in pixels.') ] ); - $this->addElement( - 'select', - 'grafana_enableLink', - [ - 'label' => $this->translate('Enable link'), - 'value' => 'no', - 'multiOptions' => [ - 'yes' => $this->translate('Yes'), - 'no' => $this->translate('No'), - ], - 'description' => $this->translate('Image is an link to the dashboard on the Grafana server.'), - 'class' => 'autosubmit' - ] - ); } - if (isset($formData['grafana_enableLink']) && ( $formData['grafana_enableLink'] === 'yes') && ( $formData['grafana_accessmode'] != 'iframe' )) { + if (( $formData['grafana_accessmode'] != 'iframe' )) { $this->addElement( 'select', 'grafana_usepublic', diff --git a/configuration.php b/configuration.php index 5ac96ad..66e1a58 100644 --- a/configuration.php +++ b/configuration.php @@ -9,7 +9,6 @@ $this->providePermission('grafana/graph', $this->translate('Allow to view graphs in dashboards.')); $this->providePermission('grafana/debug', $this->translate('Allow to see module debug information.')); $this->providePermission('grafana/showall', $this->translate('Allow access to see all graphs of a host.')); -$this->providePermission('grafana/enablelink', $this->translate('Allow to follow links to Grafana.')); $this->provideConfigTab('config', [ 'title' => 'Configuration', diff --git a/doc/03-module-configuration.md b/doc/03-module-configuration.md index dc61aca..71a8cb3 100644 --- a/doc/03-module-configuration.md +++ b/doc/03-module-configuration.md @@ -35,7 +35,6 @@ height = "280" width = "640" timerange = "3h" timerangeAll = "1M/M" -enableLink = "yes" defaultorgid = "1" defaultdashboard = "icinga2-default" defaultdashboardpanelid = "1" @@ -66,7 +65,6 @@ ssl_verifyhost = "0" |width | **Optional.** Global graph width in pixel. Defaults to `640`.| |timerange | **Optional.** Global time range for graphs. Defaults to `6h`.| |timerangeAll | **Optional.** Time range for all graphs feature. Defaults to `Previous week`.| -|enableLink | **Optional.** Enable/disable graph with a rendered URL to the Grafana dashboard. Defaults to `yes`.| |datasource | **Required for Grafana 4.x only.** Type of the Grafana datasource (`influxdb`, `graphite` or `pnp`). Defaults to `influxdb`.| |defaultdashboard | **Required.** Name of the default dashboard which will be shown for unconfigured graphs. Set to `none` to hide the module output. Defaults to `icinga2-default`.| |defaultdashboarduid | **Required for Grafana 5** The UID of the default dashboard for **Grafana 5**. @@ -118,9 +116,6 @@ This option can be overwritten by a graph configuration. ### timerangeAll Time range for all graphs feature. Defaults to `Previous week` -### enableLink -Enable or disable the graphs as a link to the Grafana Server. - ### datasource The datasource that Grafana server uses. Can be InfluxDB, Graphite. diff --git a/library/Grafana/ProvidedHook/Icingadb/IcingaDbGrapher.php b/library/Grafana/ProvidedHook/Icingadb/IcingaDbGrapher.php index b3d5c95..3216ea5 100644 --- a/library/Grafana/ProvidedHook/Icingadb/IcingaDbGrapher.php +++ b/library/Grafana/ProvidedHook/Icingadb/IcingaDbGrapher.php @@ -25,6 +25,9 @@ use ipl\Web\Widget\Link; use ipl\Web\Widget\Icon; +/** + * IcingaDbGrapher contains methods for retrieving and rendering the data from Grafana + */ trait IcingaDbGrapher { use Database; @@ -51,7 +54,6 @@ trait IcingaDbGrapher protected $apiToken = null; protected $width = 640; protected $height = 280; - protected $enableLink = true; protected $defaultDashboard = "icinga2-default"; protected $defaultDashboardPanelId = "1"; protected $defaultOrgId = "1"; @@ -95,21 +97,19 @@ protected function init() } $this->protocol = $this->config->get('protocol', $this->protocol); - $this->enableLink = $this->config->get('enableLink', $this->enableLink); - if ($this->enableLink === "yes" && $this->permission->hasPermission('grafana/enablelink')) { - $this->usePublic = $this->config->get('usepublic', $this->usePublic); - if ($this->usePublic === "yes") { - $this->publicHost = $this->config->get('publichost', $this->publicHost); - if ($this->publicHost === null) { - throw new ConfigurationError( - 'No Grafana public host configured!' - ); - } - $this->publicProtocol = $this->config->get('publicprotocol', $this->publicProtocol); - } else { - $this->publicHost = $this->grafanaHost; - $this->publicProtocol = $this->protocol; + + $this->usePublic = $this->config->get('usepublic', $this->usePublic); + if ($this->usePublic === "yes") { + $this->publicHost = $this->config->get('publichost', $this->publicHost); + if ($this->publicHost === null) { + throw new ConfigurationError( + 'No Grafana public host configured!' + ); } + $this->publicProtocol = $this->config->get('publicprotocol', $this->publicProtocol); + } else { + $this->publicHost = $this->grafanaHost; + $this->publicProtocol = $this->protocol; } // Confid needed for Grafana @@ -342,16 +342,8 @@ private function getMyPreviewHtml($serviceName, $hostName, HtmlDocument $preview ); $previewHtml->add($iframeHtml); - // Add a link to Grafana in the title - $this->title->add(new Link( - new Icon( - 'arrow-up-right-from-square', - ['title' => 'View in Grafana'] - ), - str_replace('/d-solo/', '/d/', $iFramesrc), - ['target' => '_blank', 'class' => 'external-link'] - )); } + return true; } @@ -471,41 +463,47 @@ public function getPreviewHtml(Model $object, $report = false) $html = new HtmlDocument(); $this->panelId = $panelid; - //image value will be returned as reference + // The image value will be returned as reference $previewHtml = new HtmlDocument(); $res = $this->getMyPreviewHtml($serviceName, $hostName, $previewHtml); - //do not render URLs on error or if disabled - if (! $res - || $this->enableLink === "no" - || ! $this->permission->hasPermission('grafana/enablelink')) { - $html->addHtml($previewHtml); - } else { - $url = sprintf( - $this->GRAFANA_URL, - $this->publicProtocol, - $this->publicHost, - $this->dashboarduid, - $this->dashboard, - rawurlencode(($this->dataSource === "graphite" ? Util::graphiteReplace($hostName) : $hostName)), - rawurlencode( - ($this->dataSource === "graphite" ? Util::graphiteReplace($serviceName) : $serviceName) - ), - rawurlencode($object->checkcommand_name), - $this->customVars, - urlencode($this->timerange), - urlencode($this->timerangeto), - $this->orgId, - $this->panelId - ); - - $link = new Link($previewHtml, $url, ["target" => "_blank"]); - $html->add($link); + if ($res) { + $html->addHtml($previewHtml); } $return_html->add($html); } + // URL for link to external Grafana + $url = sprintf( + $this->GRAFANA_URL, + $this->publicProtocol, + $this->publicHost, + $this->dashboarduid, + $this->dashboard, + rawurlencode(($this->dataSource === "graphite" ? Util::graphiteReplace($hostName) : $hostName)), + rawurlencode( + ($this->dataSource === "graphite" ? Util::graphiteReplace($serviceName) : $serviceName) + ), + rawurlencode($object->checkcommand_name), + $this->customVars, + urlencode($this->timerange), + urlencode($this->timerangeto), + $this->orgId, + $this->panelId + ); + + // Add a link to Grafana in the title + $this->title->add(new Link( + new Icon( + 'arrow-up-right-from-square', + ['title' => 'View in Grafana'] + ), + str_replace('/d-solo/', '/d/', $url), + ['target' => '_blank', 'class' => 'external-link'] + )); + + // Add a data table with runtime information and configuration for debugging purposes if ($this->debug && $this->permission->hasPermission('grafana/debug') && $report === false) { if ($this->accessMode === "indirectproxy") { $usedUrl = $this->pngUrl;