IcingaCommand(Legacy): Fix type and render command_line

refs #12919
This commit is contained in:
Markus Frosch 2016-10-14 10:32:51 +02:00
parent 1cedc64c5a
commit ffa5da86c9
1 changed files with 22 additions and 0 deletions

View File

@ -3,6 +3,7 @@
namespace Icinga\Module\Director\Objects; namespace Icinga\Module\Director\Objects;
use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c; use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c;
use Icinga\Module\Director\IcingaConfig\IcingaLegacyConfigHelper as c1;
class IcingaCommand extends IcingaObject class IcingaCommand extends IcingaObject
{ {
@ -175,4 +176,25 @@ class IcingaCommand extends IcingaObject
{ {
self::$pluginDir = $pluginDir; self::$pluginDir = $pluginDir;
} }
protected function getLegacyObjectType()
{
// there is only one type of command in Icinga 1.x
return 'command';
}
protected function renderLegacyCommand()
{
$command = $this->command;
if (preg_match('~^(\$USER\d+\$/?)(.+)$~', $command)) {
// should be fine, since the user decided to use a macro
} elseif (! $this->isAbsolutePath($command)) {
$command = '$USER1$/'.$command;
}
return c1::renderKeyValue(
$this->getLegacyObjectType().'_line',
c1::renderString($command)
);
}
} }