From 348cb1aa6322ea0988f0cf372721e9bd24264918 Mon Sep 17 00:00:00 2001 From: Marc DeTrano Date: Fri, 23 Sep 2016 15:18:58 +0000 Subject: [PATCH] IcingaCommandArgument: allow expressions in set_if fixes #12153 --- .../forms/IcingaCommandArgumentForm.php | 28 +++++++++++++------ .../Objects/IcingaCommandArgument.php | 10 ++++++- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/application/forms/IcingaCommandArgumentForm.php b/application/forms/IcingaCommandArgumentForm.php index 1ba4009b..c8e58868 100644 --- a/application/forms/IcingaCommandArgumentForm.php +++ b/application/forms/IcingaCommandArgumentForm.php @@ -75,16 +75,28 @@ class IcingaCommandArgumentForm extends DirectorObjectForm 'description' => $this->translate( 'Whether the set_if parameter is a string (allowing macros like $host$)' . ' or an Icinga DSL lambda function (will be enclosed with {{ ... }}' - ) + ), + 'class' => 'autosubmit', )); - $this->addElement('text', 'set_if', array( - 'label' => $this->translate('Condition (set_if)'), - 'description' => $this->translate( - 'Only set this parameter if the argument value resolves to a' - . ' numeric value. String values are not supported' - ) - )); + if ($this->getSentOrObjectValue('set_if_format') === 'expression') { + $this->addElement('textarea', 'set_if', array( + 'label' => $this->translate('Condition (set_if)'), + 'description' => $this->translate( + 'An Icinga DSL expression that returns a boolean value, e.g.: var cmd = bool(macro("$cmd$"));' + . ' return cmd ...' + ), + 'rows' => 3 + )); + } else { + $this->addElement('text', 'set_if', array( + 'label' => $this->translate('Condition (set_if)'), + 'description' => $this->translate( + 'Only set this parameter if the argument value resolves to a' + . ' numeric value. String values are not supported' + ) + )); + } $this->addBoolean('repeat_key', array( 'label' => $this->translate('Repeat key'), diff --git a/library/Director/Objects/IcingaCommandArgument.php b/library/Director/Objects/IcingaCommandArgument.php index 5a51dd98..a6aea237 100644 --- a/library/Director/Objects/IcingaCommandArgument.php +++ b/library/Director/Objects/IcingaCommandArgument.php @@ -124,6 +124,7 @@ class IcingaCommandArgument extends IcingaObject $data['argument_name'] = $this->argument_name; $data['argument_value'] = $this->argument_value; $data['argument_format'] = $this->argument_format; + $data['set_if_format'] = $this->set_if_format; return (object) $data; } } @@ -161,7 +162,14 @@ class IcingaCommandArgument extends IcingaObject } if ($this->set_if) { - $data['set_if'] = c::renderString($this->set_if); + switch ($this->set_if_format) { + case 'string': + $data['set_if'] = c::renderString($this->set_if); + break; + case 'expression': + $data['set_if'] = c::renderExpression($this->set_if); + break; + } } if ($this->required) {