2015-04-24 08:26:44 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\Forms;
|
|
|
|
|
|
|
|
|
|
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
|
|
|
|
|
|
|
|
|
|
class IcingaCommandForm extends DirectorObjectForm
|
|
|
|
|
{
|
|
|
|
|
public function setup()
|
|
|
|
|
{
|
2016-02-17 15:58:28 -05:00
|
|
|
$this->addObjectTypeElement();
|
2016-03-07 08:20:58 -05:00
|
|
|
if (! $this->hasObjectType()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-02-17 15:58:28 -05:00
|
|
|
|
|
|
|
|
$this->addElement('select', 'methods_execute', array(
|
|
|
|
|
'label' => $this->translate('Command type'),
|
|
|
|
|
'multiOptions' => array(
|
2026-02-11 11:34:51 -05:00
|
|
|
'' => '- please choose -',
|
2016-03-22 16:22:09 -04:00
|
|
|
$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',
|
|
|
|
|
)
|
2016-02-17 15:58:28 -05:00
|
|
|
),
|
2016-03-09 13:38:15 -05:00
|
|
|
'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'
|
2016-02-17 15:58:28 -05:00
|
|
|
));
|
2015-04-24 08:26:44 -04:00
|
|
|
|
2018-10-05 09:25:55 -04:00
|
|
|
$nameLabel = $this->isTemplate()
|
|
|
|
|
? $this->translate('Name')
|
|
|
|
|
: $this->translate('Command name');
|
|
|
|
|
|
2015-04-24 08:26:44 -04:00
|
|
|
$this->addElement('text', 'object_name', array(
|
2018-10-05 09:25:55 -04:00
|
|
|
'label' => $nameLabel,
|
2015-04-24 08:26:44 -04:00
|
|
|
'required' => true,
|
|
|
|
|
'description' => $this->translate('Identifier for the Icinga command you are going to create')
|
|
|
|
|
));
|
|
|
|
|
|
2016-10-25 07:28:54 -04:00
|
|
|
$this->addImportsElement(false);
|
2015-11-06 03:12:19 -05:00
|
|
|
|
2015-08-28 17:37:06 -04:00
|
|
|
$this->addElement('text', 'command', array(
|
|
|
|
|
'label' => $this->translate('Command'),
|
2015-12-01 20:45:16 -05:00
|
|
|
'required' => ! $this->isTemplate(),
|
2016-02-26 06:42:21 -05:00
|
|
|
'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.'
|
|
|
|
|
)
|
2015-08-28 17:37:06 -04:00
|
|
|
));
|
|
|
|
|
|
2015-04-24 08:26:44 -04:00
|
|
|
$this->addElement('text', 'timeout', array(
|
|
|
|
|
'label' => $this->translate('Timeout'),
|
2016-03-09 12:33:03 -05:00
|
|
|
'description' => $this->translate(
|
|
|
|
|
'Optional command timeout. Allowed values are seconds or durations postfixed with a'
|
|
|
|
|
. ' specific unit (e.g. 1m or also 3m 30s).'
|
|
|
|
|
)
|
2015-04-24 08:26:44 -04:00
|
|
|
));
|
2019-03-26 07:02:13 -04:00
|
|
|
|
|
|
|
|
$descIsString = [
|
|
|
|
|
$this->translate('Render the command as a plain string instead of an array.'),
|
2019-03-26 06:38:04 -04:00
|
|
|
$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.'),
|
2019-03-26 07:02:13 -04:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$this->addBoolean(
|
|
|
|
|
'is_string',
|
|
|
|
|
array(
|
|
|
|
|
'label' => $this->translate('Render as string'),
|
|
|
|
|
'description' => join(' ', $descIsString),
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
2016-02-17 14:10:22 -05:00
|
|
|
$this->addDisabledElement();
|
2017-02-17 10:08:57 -05:00
|
|
|
$this->addZoneSection();
|
2015-11-06 03:12:19 -05:00
|
|
|
$this->setButtons();
|
2015-04-24 08:26:44 -04:00
|
|
|
}
|
2016-11-15 12:23:39 -05:00
|
|
|
|
2017-02-17 10:08:57 -05:00
|
|
|
protected function addZoneSection()
|
|
|
|
|
{
|
|
|
|
|
$this->addZoneElement(true);
|
|
|
|
|
|
|
|
|
|
$elements = array(
|
|
|
|
|
'zone_id',
|
|
|
|
|
);
|
|
|
|
|
$this->addDisplayGroup($elements, 'clustering', array(
|
|
|
|
|
'decorators' => array(
|
|
|
|
|
'FormElements',
|
|
|
|
|
array('HtmlTag', array('tag' => 'dl')),
|
|
|
|
|
'Fieldset',
|
|
|
|
|
),
|
2020-11-30 06:39:48 -05:00
|
|
|
'order' => self::GROUP_ORDER_CLUSTERING,
|
2017-02-17 10:08:57 -05:00
|
|
|
'legend' => $this->translate('Zone settings')
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-15 12:23:39 -05:00
|
|
|
protected function enumAllowedTemplates()
|
|
|
|
|
{
|
|
|
|
|
$object = $this->object();
|
|
|
|
|
$tpl = $this->db->enum($object->getTableName());
|
|
|
|
|
if (empty($tpl)) {
|
|
|
|
|
return array();
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-11 11:34:51 -05:00
|
|
|
$id = $object->get('id') ?? ''; // NULL is not allowed as array key
|
2016-11-15 12:23:39 -05:00
|
|
|
|
|
|
|
|
if (array_key_exists($id, $tpl)) {
|
|
|
|
|
unset($tpl[$id]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (empty($tpl)) {
|
|
|
|
|
return array();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$tpl = array_combine($tpl, $tpl);
|
|
|
|
|
return $tpl;
|
|
|
|
|
}
|
2015-04-24 08:26:44 -04:00
|
|
|
}
|