Icinga(Commmand)Arguments: small improvements

This commit is contained in:
Thomas Gelf 2015-12-18 16:11:36 +01:00
parent 6ba5e44071
commit a0b5e79115
2 changed files with 32 additions and 12 deletions

View File

@ -100,26 +100,41 @@ class IcingaArguments implements Iterator, Countable, IcingaConfigRenderer
$attrs[$dbKey] = $value->$apiKey;
}
}
if (property_exists($value, 'value')) {
$argValue = $value->value;
}
if (property_exists($value, 'type')) {
if ($value->type === 'Function') {
$attrs['argument_value'] = '/* Unable to fetch function body through API */';
$attrs['argument_format'] = 'expression';
}
} elseif (property_exists($value, 'value')) {
if (is_object($value->value)) {
if ($value->value->type === 'Function') {
$attrs['argument_value'] = '/* Unable to fetch function body through API */';
$attrs['argument_format'] = 'expression';
} else {
var_dump($value);
die('Unable to resolve command argument');
}
} else {
$argValue = $value->value;
if (is_string($argValue)) {
$attrs['argument_value'] = $argValue;
$attrs['argument_format'] = 'string';
} else {
$attrs['argument_value'] = json_encode($argValue);
$attrs['argument_format'] = 'json';
}
}
}
} else {
$argValue = $value;
if (is_string($value)) {
$attrs['argument_value'] = $value;
$attrs['argument_format'] = 'string';
} else {
$attrs['argument_value'] = json_encode($value);
$attrs['argument_format'] = 'json';
}
}
if (is_string($argValue)) {
$attrs['argument_value'] = $argValue;
$attrs['argument_format'] = 'string';
} elseif ($argValue !== null) {
$attrs['argument_value'] = $argValue;
$attrs['argument_format'] = 'json';
}
$this->add(IcingaCommandArgument::create($attrs));

View File

@ -58,8 +58,13 @@ class IcingaCommandArgument extends IcingaObject
$data['value'] = c::renderDictionary($this->argument_value);
} elseif (is_array($this->argument_value)) {
$data['value'] = c::renderArray($this->argument_value);
} elseif (is_null($this->argument_value)) {
// TODO: recheck all this. I bet we never reach this:
$data['value'] = 'null';
} elseif (is_bool($this->argument_value)) {
$data['value'] = c::renderBoolean($this->argument_value);
} else {
die('Unhandled');
$data['value'] = $this->argument_value;
}
break;
case 'expression':