Skip to content

Commit

Permalink
Transform compat action & notes url macros automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabteab committed Sep 27, 2023
1 parent cd41a20 commit ac3c3ce
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
32 changes: 30 additions & 2 deletions library/Icingadb/Common/Macros.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@

namespace Icinga\Module\Icingadb\Common;

use Exception;
use Icinga\Application\Icinga;
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;
use ipl\Orm\ResultSet;
use OutOfBoundsException;

use function ipl\Stdlib\get_php_type;

Expand Down Expand Up @@ -99,9 +104,22 @@ public function resolveMacro(string $macro, Model $object): string
} else {
$value = $object->$macro;
}
} catch (\Exception $e) {
} catch (Exception $e) {
$value = null;
Logger::debug('Unable to resolve macro "%s". An error occurred: %s', $macro, $e);
$monitoringInstalled = Icinga::app()->getModuleManager()->hasInstalled('monitoring');
if ($monitoringInstalled && $e instanceof OutOfBoundsException) {
$compatObj = $this->getCompatObject();
if ($compatObj) {
try {
$value = $compatObj->$macro;
} catch (Exception $e) {
$value = null;
Logger::debug('Unable to resolve macro "%s". An error occurred: %s', $macro, $e);
}
}
} else {
Logger::debug('Unable to resolve macro "%s". An error occurred: %s', $macro, $e);
}
}

if ($value instanceof Query || $value instanceof ResultSet || is_array($value)) {
Expand All @@ -115,4 +133,14 @@ public function resolveMacro(string $macro, Model $object): string

return $value !== null ? $value : $macro;
}

/**
* Get the associated monitoring object
*
* @return null|CompatHost|CompatService
*/
protected function getCompatObject()
{
return null;
}
}
5 changes: 5 additions & 0 deletions library/Icingadb/Widget/Detail/ObjectDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ protected function compatObject()
return $this->compatObject;
}

protected function getCompatObject()
{
return $this->compatObject();
}

protected function createPrintHeader()
{
$info = [new HorizontalKeyValue(t('Name'), $this->object->name)];
Expand Down

0 comments on commit ac3c3ce

Please sign in to comment.