CustomVariables: beatify v1.x unsupported vars

This commit is contained in:
Thomas Gelf 2016-11-04 19:51:02 +01:00
parent f6a5c8cbc5
commit 5168f5e887
1 changed files with 11 additions and 10 deletions

View File

@ -6,7 +6,6 @@ use Icinga\Module\Director\Db;
use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c; use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c;
use Icinga\Module\Director\IcingaConfig\IcingaLegacyConfigHelper as c1; use Icinga\Module\Director\IcingaConfig\IcingaLegacyConfigHelper as c1;
use Icinga\Module\Director\IcingaConfig\IcingaConfigRenderer; use Icinga\Module\Director\IcingaConfig\IcingaConfigRenderer;
use Icinga\Module\Director\Objects\IcingaHostVar;
use Icinga\Module\Director\Objects\IcingaObject; use Icinga\Module\Director\Objects\IcingaObject;
use Countable; use Countable;
use Exception; use Exception;
@ -17,6 +16,7 @@ class CustomVariables implements Iterator, Countable, IcingaConfigRenderer
/** @var CustomVariable[] */ /** @var CustomVariable[] */
protected $storedVars = array(); protected $storedVars = array();
/** @var CustomVariable[] */
protected $vars = array(); protected $vars = array();
protected $modified = false; protected $modified = false;
@ -292,10 +292,7 @@ class CustomVariables implements Iterator, Countable, IcingaConfigRenderer
ksort($this->vars); ksort($this->vars);
foreach ($this->vars as $key => $var) { foreach ($this->vars as $key => $var) {
/** @var CustomVariable $var */
// TODO: ctype_alnum + underscore? // TODO: ctype_alnum + underscore?
$value = null;
// vars with ARGn will be handled by IcingaObject::renderLegacyCheck_command // vars with ARGn will be handled by IcingaObject::renderLegacyCheck_command
if (substr($key, 0, 3) == 'ARG') { if (substr($key, 0, 3) == 'ARG') {
continue; continue;
@ -303,17 +300,21 @@ class CustomVariables implements Iterator, Countable, IcingaConfigRenderer
switch ($type = $var->getType()) { switch ($type = $var->getType()) {
case 'String': case 'String':
case 'Number':
# TODO: Make Prefetchable # TODO: Make Prefetchable
$value = $var->toLegacyConfigString(); $out .= c1::renderKeyValue(
'_' . $key,
$var->toLegacyConfigString()
);
break; break;
default: default:
$out .= sprintf("# Unsupported var: %s (%s)\n", $key, $type); $out .= c1::renderKeyValue(
} '# _' . $key,
sprintf('(unsupported: %s)', $type)
if ($value !== null) { );
$out .= c1::renderKeyValue('_' . $key, $value);
} }
} }
if ($out !== '') { if ($out !== '') {
$out = "\n".$out; $out = "\n".$out;
} }