diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:43:12 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:43:12 +0000 |
commit | cd989f9c3aff968e19a3aeabc4eb9085787a6673 (patch) | |
tree | fbff2135e7013f196b891bbde54618eb050e4aaf /application/forms/IcingaCommandForm.php | |
parent | Initial commit. (diff) | |
download | icingaweb2-module-director-cd989f9c3aff968e19a3aeabc4eb9085787a6673.tar.xz icingaweb2-module-director-cd989f9c3aff968e19a3aeabc4eb9085787a6673.zip |
Adding upstream version 1.10.2.upstream/1.10.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'application/forms/IcingaCommandForm.php')
-rw-r--r-- | application/forms/IcingaCommandForm.php | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/application/forms/IcingaCommandForm.php b/application/forms/IcingaCommandForm.php new file mode 100644 index 0000000..ba1386b --- /dev/null +++ b/application/forms/IcingaCommandForm.php @@ -0,0 +1,137 @@ +<?php + +namespace Icinga\Module\Director\Forms; + +use Icinga\Module\Director\Web\Form\DirectorObjectForm; + +class IcingaCommandForm extends DirectorObjectForm +{ + public function setup() + { + $this->addObjectTypeElement(); + if (! $this->hasObjectType()) { + return; + } + + $this->addElement('select', 'methods_execute', array( + 'label' => $this->translate('Command type'), + 'multiOptions' => array( + null => '- please choose -', + $this->translate('Plugin commands') => array( + 'PluginCheck' => 'Plugin Check Command', + 'PluginNotification' => 'Notification Plugin Command', + 'PluginEvent' => 'Event Plugin Command', + ), + $this->translate('Internal commands') => array( + 'IcingaCheck' => 'Icinga Check Command', + 'ClusterCheck' => 'Icinga Cluster Check Command', + 'ClusterZoneCheck' => 'Icinga Cluster Zone Check Command', + 'IdoCheck' => 'Ido Check Command', + 'RandomCheck' => 'Random Check Command', + ) + ), + 'required' => ! $this->isTemplate(), + 'description' => $this->translate( + 'Plugin Check commands are what you need when running checks agains' + . ' your infrastructure. Notification commands will be used when it' + . ' comes to notify your users. Event commands allow you to trigger' + . ' specific actions when problems occur. Some people use them for' + . ' auto-healing mechanisms, like restarting services or rebooting' + . ' systems at specific thresholds' + ), + 'class' => 'autosubmit' + )); + + $nameLabel = $this->isTemplate() + ? $this->translate('Name') + : $this->translate('Command name'); + + $this->addElement('text', 'object_name', array( + 'label' => $nameLabel, + 'required' => true, + 'description' => $this->translate('Identifier for the Icinga command you are going to create') + )); + + $this->addImportsElement(false); + + $this->addElement('text', 'command', array( + 'label' => $this->translate('Command'), + 'required' => ! $this->isTemplate(), + 'description' => $this->translate( + 'The command Icinga should run. Absolute paths are accepted as provided,' + . ' relative paths are prefixed with "PluginDir + ", similar Constant prefixes are allowed.' + . ' Spaces will lead to separation of command path and standalone arguments. Please note that' + . ' this means that we do not support spaces in plugin names and paths right now.' + ) + )); + + $this->addElement('text', 'timeout', array( + 'label' => $this->translate('Timeout'), + 'description' => $this->translate( + 'Optional command timeout. Allowed values are seconds or durations postfixed with a' + . ' specific unit (e.g. 1m or also 3m 30s).' + ) + )); + + $descIsString = [ + $this->translate('Render the command as a plain string instead of an array.'), + $this->translate('If enabled you can not define arguments.'), + $this->translate('Disabled by default, and should only be used in rare cases.'), + $this->translate('WARNING, this can allow shell script injection via custom variables used in command.'), + ]; + + $this->addBoolean( + 'is_string', + array( + 'label' => $this->translate('Render as string'), + 'description' => join(' ', $descIsString), + ) + ); + + $this->addDisabledElement(); + $this->addZoneSection(); + $this->setButtons(); + } + + protected function addZoneSection() + { + $this->addZoneElement(true); + + $elements = array( + 'zone_id', + ); + $this->addDisplayGroup($elements, 'clustering', array( + 'decorators' => array( + 'FormElements', + array('HtmlTag', array('tag' => 'dl')), + 'Fieldset', + ), + 'order' => self::GROUP_ORDER_CLUSTERING, + 'legend' => $this->translate('Zone settings') + )); + + return $this; + } + + protected function enumAllowedTemplates() + { + $object = $this->object(); + $tpl = $this->db->enum($object->getTableName()); + if (empty($tpl)) { + return array(); + } + + $id = $object->get('id'); + + if (array_key_exists($id, $tpl)) { + unset($tpl[$id]); + } + + if (empty($tpl)) { + return array(); + } + + $tpl = array_combine($tpl, $tpl); + return $tpl; + } +} |