diff --git a/library/Icingadb/Common/Macros.php b/library/Icingadb/Common/Macros.php index 733c116ef..2c90e6cfe 100644 --- a/library/Icingadb/Common/Macros.php +++ b/library/Icingadb/Common/Macros.php @@ -5,6 +5,8 @@ namespace Icinga\Module\Icingadb\Common; use Icinga\Application\Logger; +use Icinga\Module\Icingadb\Compat\CompatHost; +use Icinga\Module\Icingadb\Compat\CompatService; use Icinga\Module\Icingadb\Model\Host; use ipl\Orm\Model; use ipl\Orm\Query; @@ -18,11 +20,11 @@ trait Macros * Get the given string with macros being resolved * * @param string $input The string in which to look for macros - * @param Model $object The host or service used to resolve the macros + * @param Model|CompatService|CompatHost $object The host or service used to resolve the macros * * @return string */ - public function expandMacros(string $input, Model $object): string + public function expandMacros(string $input, $object): string { if (preg_match_all('@\$([^\$\s]+)\$@', $input, $matches)) { foreach ($matches[1] as $key => $value) { @@ -40,11 +42,11 @@ public function expandMacros(string $input, Model $object): string * Resolve a macro based on the given object * * @param string $macro The macro to resolve - * @param Model $object The host or service used to resolve the macros + * @param Model|CompatService|CompatHost $object The host or service used to resolve the macros * * @return string */ - public function resolveMacro(string $macro, Model $object): string + public function resolveMacro(string $macro, $object): string { if ($object instanceof Host) { $objectType = 'host'; diff --git a/library/Icingadb/Widget/Detail/ObjectDetail.php b/library/Icingadb/Widget/Detail/ObjectDetail.php index c431a84bd..26f7a4f6f 100644 --- a/library/Icingadb/Widget/Detail/ObjectDetail.php +++ b/library/Icingadb/Widget/Detail/ObjectDetail.php @@ -20,6 +20,7 @@ use Icinga\Module\Icingadb\Common\Links; use Icinga\Module\Icingadb\Common\Macros; use Icinga\Module\Icingadb\Compat\CompatHost; +use Icinga\Module\Icingadb\Compat\CompatService; use Icinga\Module\Icingadb\Model\CustomvarFlat; use Icinga\Module\Icingadb\Web\Navigation\Action; use Icinga\Module\Icingadb\Widget\MarkdownText; @@ -132,8 +133,15 @@ protected function createActions() $item->setObject($this->object); } + $monitoringInstalled = Icinga::app()->getModuleManager()->hasInstalled('monitoring'); foreach ($this->object->action_url->first()->action_url ?? [] as $url) { - $url = $this->expandMacros($url, $this->object); + if ($monitoringInstalled) { + $obj = $this->compatObject(); + } else { + $obj = $this->object; + } + + $url = $this->expandMacros($url, $obj); $navigation->addItem( Html::wantHtml([ // Add warning to links that open in new tabs, as recommended by WCAG20 G201 @@ -320,8 +328,15 @@ protected function createNotes() $navigation = new Navigation(); $notes = trim($this->object->notes); + $monitoringInstalled = Icinga::app()->getModuleManager()->hasInstalled('monitoring'); foreach ($this->object->notes_url->first()->notes_url ?? [] as $url) { - $url = $this->expandMacros($url, $this->object); + if ($monitoringInstalled) { + $obj = $this->compatObject(); + } else { + $obj = $this->object; + } + + $url = $this->expandMacros($url, $obj); $navigation->addItem( Html::wantHtml([ // Add warning to links that open in new tabs, as recommended by WCAG20 G201