Skip to content

Release v3.0.1 #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
# Change Log
## [v3.0.1](https://github.com/NETWAYS/icingaweb2-module-grafana/tree/v3.0.0) (2025-02-03)

**Fixes**
- Fix debugTable creation in iframe mode
- Add type check to substr_count to avoid deprecation warning
- Reintroduce permission to control the appearance of the Grafana link
- Add small Link to panel

## [v3.0.0](https://github.com/NETWAYS/icingaweb2-module-grafana/tree/v3.0.0) (2024-12-10)

**BREAKING CHANGES:**
Expand All @@ -17,7 +25,7 @@ It now uses the check interval to determine how long a graph's image is cached.
- PHP 8.2 and PHP 8.3 Support
- Support strict CSP
- Dark/Light Theme depending on user's settings (removed the `theme` configuration option)
- Debug information can be requested via the `debugGrafana` URL parameter (removed the `debug` configuration option)
- Debug information can be requested via the `grafanaDebug` URL parameter (removed the `debug` configuration option)

**Fixes**
- Use of special characters in custom variables now works
Expand Down
1 change: 1 addition & 0 deletions configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
$this->providePermission('grafana/graph', $this->translate('Allow to view graphs in dashboards.'));
$this->providePermission('grafana/debug', $this->translate('Allow to see debug information for graphs.'));
$this->providePermission('grafana/showall', $this->translate('Allow access to see all graphs of a host.'));
$this->providePermission('grafana/showlink', $this->translate('Display a link to the Grafana instance.'));

$this->provideConfigTab('config', [
'title' => 'Configuration',
Expand Down
1 change: 1 addition & 0 deletions doc/01-about.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The module provides the following permissions:
* `grafana/graphconfig`, Allow to configure graphs.
* `grafana/graph`, Allow to view graphs in dashboards.
* `grafana/showall`, Allow access to see all graphs of a host.
* `grafana/showlink` Display a link to the Grafana instance.
* `grafana/debug` Allow to see debug information for graphs (can be accessed via the URL parameter `&grafanaDebug`).

## Show all graphs
Expand Down
2 changes: 2 additions & 0 deletions doc/03-module-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ ssl_verifypeer = "0"
ssl_verifyhost = "0"
```

Hint: to display debug information for graphs you can use the URL parameter `&grafanaDebug`. This requires the `grafana/debug` permission.

## Available Options

|Setting | Short description|
Expand Down
42 changes: 25 additions & 17 deletions library/Grafana/ProvidedHook/Icingadb/IcingaDbGrapher.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,7 @@ public function getPreviewHtml(Model $object, $report = false)
}

if ($this->repeatable === "yes") {
$panelEnd = ($this->panelId - 1) +
intval(substr_count($object->state->performance_data, '=') / $this->numberMetrics);
$panelEnd = ($this->panelId - 1) + intval(substr_count(strval($object->state->performance_data), '=') / $this->numberMetrics);
$this->panelId = implode(
',',
range($this->panelId, $panelEnd)
Expand Down Expand Up @@ -435,14 +434,16 @@ public function getPreviewHtml(Model $object, $report = false)
);

// 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']
));
if ($this->permission->hasPermission('grafana/showlink')) {
$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']
));
}

// Hide menu if in reporting or compact mode
$menu = "";
Expand All @@ -463,6 +464,16 @@ public function getPreviewHtml(Model $object, $report = false)
$res = $this->getMyPreviewHtml($serviceName, $hostName, $previewHtml);

if ($res) {
// Add Link to Panel if the user has the permission
if ($this->permission->hasPermission('grafana/showlink')) {
$linkUrl = $url;
$linkUrl = preg_replace('/(viewPanel=)[^&]+/', '${1}' . $panelid, $linkUrl);
$textLink = new Link('View in Grafana', $linkUrl, ['target' => '_blank', 'class' => 'external-link']);
$html->add($textLink);
$iconLink = new Link(new Icon('arrow-up-right-from-square', ['title' => 'View in Grafana']), $linkUrl, ['target' => '_blank', 'class' => 'external-link']);
$html->add($iconLink);
}

$html->addHtml($previewHtml);
}

Expand All @@ -472,7 +483,7 @@ public function getPreviewHtml(Model $object, $report = false)
// Add a data table with runtime information and configuration for debugging purposes
if (Url::fromRequest()->hasParam('grafanaDebug') && $this->permission->hasPermission('grafana/debug') && $report === false) {
$returnHtml->addHtml(HtmlElement::create('h2', null, 'Performance Graph Debug'));
$returnHtml->add($this->createDebugTable());
$returnHtml->add($this->createDebugTable($previewHtml));
}

$htmlForObject = HtmlElement::create("div", ["class" => "icinga-module module-grafana"]);
Expand All @@ -486,15 +497,12 @@ public function getPreviewHtml(Model $object, $report = false)
/**
* createDebugTable creates a data table with runtime information and configuration for debugging purposes
*/
private function createDebugTable()
private function createDebugTable($previewHtml)
{
if ($this->accessMode === 'indirectproxy') {
$usedUrl = $this->pngUrl;
} else {
$usedUrl = preg_replace('/.*?src\s*=\s*[\'\"](.*?)[\'\"].*/', "$1", $previewHtml);
}
$usedUrl = $this->pngUrl;

if ($this->accessMode === 'iframe') {
$usedUrl = preg_replace('/.*?src\s*=\s*[\'\"](.*?)[\'\"].*/', "$1", $previewHtml);
$this->height = '100%';
}

Expand Down
2 changes: 1 addition & 1 deletion module.info
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name: Grafana
Version: 3.0.0
Version: 3.0.1
Requires:
Libraries: icinga-php-library (>=0.10.1)
Modules: icingadb (>=1.0.0)
Expand Down