Skip to content
Open
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
12 changes: 10 additions & 2 deletions application/controllers/IcingadbimgController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class IcingadbimgController extends IcingadbGrafanaController
protected $dashboarduid;
protected $panelId;
protected $orgId;
protected $imagefilter;

/**
* Mainly loading defaults and the configuration.
Expand Down Expand Up @@ -115,6 +116,12 @@ public function init()
$this->dataSource = $this->myConfig->get('datasource', $this->dataSource);
$this->shadows = $this->myConfig->get('shadows', $this->shadows);
$this->custvarconfig = ($this->myConfig->get('custvarconfig', $this->custvarconfig));

$this->imagefilter = $this->hasParam('imagefilter') ? urldecode($this->getParam('imagefilter')) : "";

/**
* Verify the certificate's name against host
*/
$this->SSLVerifyHost = ($this->myConfig->get('ssl_verifyhost', $this->SSLVerifyHost));
$this->SSLVerifyPeer = ($this->myConfig->get('ssl_verifypeer', $this->SSLVerifyPeer));

Expand Down Expand Up @@ -278,7 +285,7 @@ private function getMyimageHtml($serviceName, $hostName, &$imageHtml)

$pngUrl = sprintf(
'%s://%s/render/d-solo/%s/%s?var-hostname=%s&var-service=%s&var-command=%s%s&panelId=%s&orgId=%s'
. '&width=%s&height=%s&theme=%s&from=%s&to=%s',
. '&width=%s&height=%s&theme=%s&from=%s&to=%s%s',
$this->protocol,
$this->grafanaHost,
$this->dashboarduid,
Expand All @@ -293,7 +300,8 @@ private function getMyimageHtml($serviceName, $hostName, &$imageHtml)
$this->height,
$this->grafanaTheme,
urlencode($this->timerange),
urlencode($this->timerangeto)
urlencode($this->timerangeto),
$this->imagefilter
);

// fetch image with curl
Expand Down
55 changes: 36 additions & 19 deletions library/Grafana/ProvidedHook/Icingadb/IcingaDbGrapher.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ private function getGraphConf($serviceName, $serviceCommand = null): ?self
* @return bool
* @throws \Icinga\Exception\ProgrammingError
*/
private function getMyPreviewHtml($serviceName, $hostName, HtmlDocument $previewHtml): bool
private function getMyPreviewHtml($serviceName, $hostName, HtmlDocument $previewHtml, $imageFilter = ""): bool
{
$imgClass = $this->shadows ? "grafana-img grafana-img-shadows" : "grafana-img";

Expand All @@ -249,7 +249,8 @@ private function getMyPreviewHtml($serviceName, $hostName, HtmlDocument $preview
'panelid' => $this->panelId,
'timerange' => urlencode($this->timerange),
'timerangeto' => urlencode($this->timerangeto),
'cachetime' => $this->cacheTime
'cachetime' => $this->cacheTime,
'imagefilter' => urlencode($imageFilter)
]
);
} else {
Expand All @@ -260,7 +261,8 @@ private function getMyPreviewHtml($serviceName, $hostName, HtmlDocument $preview
'panelid' => $this->panelId,
'timerange' => urlencode($this->timerange),
'timerangeto' => urlencode($this->timerangeto),
'cachetime' => $this->cacheTime
'cachetime' => $this->cacheTime,
'imagefilter' => urlencode($imageFilter)
]
);
}
Expand Down Expand Up @@ -459,24 +461,39 @@ public function getPreviewHtml(Model $object, $report = false)
$html = new HtmlDocument();
$this->panelId = $panelid;

// The image value will be returned as reference
$previewHtml = new HtmlDocument();
$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);
$flattened_vars = $object->vars;
// The $object->vars array is flattened, we unflatten the subarray grafanaimagefiltersarray here:
$i = 0;
$info = [];
while (isset($flattened_vars['grafanaimagefiltersarray[' . $i . ']'])) {
$info[$i] = $flattened_vars['grafanaimagefiltersarray[' . $i . ']'];
$i++;
}

$i = 0;
do {
$value = $info ? $info[$i] : "";

// The image value will be returned as reference
$previewHtml = new HtmlDocument();
$res = $this->getMyPreviewHtml($serviceName, $hostName, $previewHtml, $value);

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);
}
$i++;
} while ($i < count($info));

$returnHtml->add($html);
}

Expand Down