@@ -377,8 +377,7 @@ public function getPreviewHtml(Model $object, $report = false)
377377 }
378378
379379 if ($ this ->repeatable === "yes " ) {
380- $ panelEnd = ($ this ->panelId - 1 ) +
381- intval (substr_count ($ object ->state ->performance_data , '= ' ) / $ this ->numberMetrics );
380+ $ panelEnd = ($ this ->panelId - 1 ) + intval (substr_count (strval ($ object ->state ->performance_data ), '= ' ) / $ this ->numberMetrics );
382381 $ this ->panelId = implode (
383382 ', ' ,
384383 range ($ this ->panelId , $ panelEnd )
@@ -435,14 +434,16 @@ public function getPreviewHtml(Model $object, $report = false)
435434 );
436435
437436 // Add a link to Grafana in the title
438- $ this ->title ->add (new Link (
439- new Icon (
440- 'arrow-up-right-from-square ' ,
441- ['title ' => 'View in Grafana ' ]
442- ),
443- str_replace ('/d-solo/ ' , '/d/ ' , $ url ),
444- ['target ' => '_blank ' , 'class ' => 'external-link ' ]
445- ));
437+ if ($ this ->permission ->hasPermission ('grafana/showlink ' )) {
438+ $ this ->title ->add (new Link (
439+ new Icon (
440+ 'arrow-up-right-from-square ' ,
441+ ['title ' => 'View in Grafana ' ]
442+ ),
443+ str_replace ('/d-solo/ ' , '/d/ ' , $ url ),
444+ ['target ' => '_blank ' , 'class ' => 'external-link ' ]
445+ ));
446+ }
446447
447448 // Hide menu if in reporting or compact mode
448449 $ menu = "" ;
@@ -463,6 +464,16 @@ public function getPreviewHtml(Model $object, $report = false)
463464 $ res = $ this ->getMyPreviewHtml ($ serviceName , $ hostName , $ previewHtml );
464465
465466 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+
466477 $ html ->addHtml ($ previewHtml );
467478 }
468479
@@ -472,7 +483,7 @@ public function getPreviewHtml(Model $object, $report = false)
472483 // Add a data table with runtime information and configuration for debugging purposes
473484 if (Url::fromRequest ()->hasParam ('grafanaDebug ' ) && $ this ->permission ->hasPermission ('grafana/debug ' ) && $ report === false ) {
474485 $ returnHtml ->addHtml (HtmlElement::create ('h2 ' , null , 'Performance Graph Debug ' ));
475- $ returnHtml ->add ($ this ->createDebugTable ());
486+ $ returnHtml ->add ($ this ->createDebugTable ($ previewHtml ));
476487 }
477488
478489 $ htmlForObject = HtmlElement::create ("div " , ["class " => "icinga-module module-grafana " ]);
@@ -486,15 +497,12 @@ public function getPreviewHtml(Model $object, $report = false)
486497 /**
487498 * createDebugTable creates a data table with runtime information and configuration for debugging purposes
488499 */
489- private function createDebugTable ()
500+ private function createDebugTable ($ previewHtml )
490501 {
491- if ($ this ->accessMode === 'indirectproxy ' ) {
492- $ usedUrl = $ this ->pngUrl ;
493- } else {
494- $ usedUrl = preg_replace ('/.*?src\s*=\s*[ \'\"](.*?)[ \'\"].*/ ' , "$1 " , $ previewHtml );
495- }
502+ $ usedUrl = $ this ->pngUrl ;
496503
497504 if ($ this ->accessMode === 'iframe ' ) {
505+ $ usedUrl = preg_replace ('/.*?src\s*=\s*[ \'\"](.*?)[ \'\"].*/ ' , "$1 " , $ previewHtml );
498506 $ this ->height = '100% ' ;
499507 }
500508
0 commit comments