@@ -235,7 +235,7 @@ private function getGraphConf($serviceName, $serviceCommand = null): ?self
235235 * @return bool
236236 * @throws \Icinga\Exception\ProgrammingError
237237 */
238- private function getMyPreviewHtml ($ serviceName , $ hostName , HtmlDocument $ previewHtml ): bool
238+ private function getMyPreviewHtml ($ serviceName , $ hostName , HtmlDocument $ previewHtml, $ imageFilter = "" ): bool
239239 {
240240 $ imgClass = $ this ->shadows ? "grafana-img grafana-img-shadows " : "grafana-img " ;
241241
@@ -249,7 +249,8 @@ private function getMyPreviewHtml($serviceName, $hostName, HtmlDocument $preview
249249 'panelid ' => $ this ->panelId ,
250250 'timerange ' => urlencode ($ this ->timerange ),
251251 'timerangeto ' => urlencode ($ this ->timerangeto ),
252- 'cachetime ' => $ this ->cacheTime
252+ 'cachetime ' => $ this ->cacheTime ,
253+ 'imagefilter ' => urlencode ($ imageFilter )
253254 ]
254255 );
255256 } else {
@@ -260,7 +261,8 @@ private function getMyPreviewHtml($serviceName, $hostName, HtmlDocument $preview
260261 'panelid ' => $ this ->panelId ,
261262 'timerange ' => urlencode ($ this ->timerange ),
262263 'timerangeto ' => urlencode ($ this ->timerangeto ),
263- 'cachetime ' => $ this ->cacheTime
264+ 'cachetime ' => $ this ->cacheTime ,
265+ 'imagefilter ' => urlencode ($ imageFilter )
264266 ]
265267 );
266268 }
@@ -459,24 +461,35 @@ public function getPreviewHtml(Model $object, $report = false)
459461 $ html = new HtmlDocument ();
460462 $ this ->panelId = $ panelid ;
461463
462- // The image value will be returned as reference
463- $ previewHtml = new HtmlDocument ();
464- $ res = $ this ->getMyPreviewHtml ($ serviceName , $ hostName , $ previewHtml );
465-
466- if ($ res ) {
467- // Add Link to Panel if the user has the permission
468- if ($ this ->permission ->hasPermission ('grafana/showlink ' )) {
469- $ linkUrl = $ url ;
470- $ linkUrl = preg_replace ('/(viewPanel=)[^&]+/ ' , '${1} ' . $ panelid , $ linkUrl );
471- $ textLink = new Link ('View in Grafana ' , $ linkUrl , ['target ' => '_blank ' , 'class ' => 'external-link ' ]);
472- $ html ->add ($ textLink );
473- $ iconLink = new Link (new Icon ('arrow-up-right-from-square ' , ['title ' => 'View in Grafana ' ]), $ linkUrl , ['target ' => '_blank ' , 'class ' => 'external-link ' ]);
474- $ html ->add ($ iconLink );
475- }
476-
477- $ html ->addHtml ($ previewHtml );
464+ $ flattened_vars = $ object ->vars ;
465+ // The $object->vars array is flattened, we unflatten the subarray grafanaimagefiltersarray here:
466+ $ i = 0 ;
467+ $ info = [];
468+ while (isset ($ flattened_vars ['grafanaimagefiltersarray[ ' . $ i . '] ' ])) {
469+ $ info [$ i ] = $ flattened_vars ['grafanaimagefiltersarray[ ' . $ i . '] ' ];
470+ $ i ++;
478471 }
479472
473+ foreach ($ info as $ value ) {
474+
475+ // The image value will be returned as reference
476+ $ previewHtml = new HtmlDocument ();
477+ $ res = $ this ->getMyPreviewHtml ($ serviceName , $ hostName , $ previewHtml , $ value );
478+
479+ if ($ res ) {
480+ // Add Link to Panel if the user has the permission
481+ if ($ this ->permission ->hasPermission ('grafana/showlink ' )) {
482+ $ linkUrl = $ url ;
483+ $ linkUrl = preg_replace ('/(viewPanel=)[^&]+/ ' , '${1} ' . $ panelid , $ linkUrl );
484+ $ textLink = new Link ('View in Grafana ' , $ linkUrl , ['target ' => '_blank ' , 'class ' => 'external-link ' ]);
485+ $ html ->add ($ textLink );
486+ $ iconLink = new Link (new Icon ('arrow-up-right-from-square ' , ['title ' => 'View in Grafana ' ]), $ linkUrl , ['target ' => '_blank ' , 'class ' => 'external-link ' ]);
487+ $ html ->add ($ iconLink );
488+ }
489+
490+ $ html ->addHtml ($ previewHtml );
491+ }
492+
480493 $ returnHtml ->add ($ html );
481494 }
482495
0 commit comments