diff --git a/application/controllers/IcingadbimgController.php b/application/controllers/IcingadbimgController.php index 15dbd95..04ea8d5 100644 --- a/application/controllers/IcingadbimgController.php +++ b/application/controllers/IcingadbimgController.php @@ -49,6 +49,7 @@ class IcingadbimgController extends IcingadbGrafanaController protected $dashboarduid; protected $panelId; protected $orgId; + protected $imagefilter; /** * Mainly loading defaults and the configuration. @@ -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)); @@ -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, @@ -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 diff --git a/library/Grafana/ProvidedHook/Icingadb/IcingaDbGrapher.php b/library/Grafana/ProvidedHook/Icingadb/IcingaDbGrapher.php index 3bb24a3..76a485a 100644 --- a/library/Grafana/ProvidedHook/Icingadb/IcingaDbGrapher.php +++ b/library/Grafana/ProvidedHook/Icingadb/IcingaDbGrapher.php @@ -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"; @@ -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 { @@ -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) ] ); } @@ -458,14 +460,29 @@ 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) { - $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) { + $html->addHtml($previewHtml); + } + $i++; + } while ($i < count($info)); + $returnHtml->add($html); }