2018-06-14 17:51:48 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\Forms;
|
|
|
|
|
|
|
|
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
|
|
|
|
|
|
|
|
class IcingaScheduledDowntimeForm extends DirectorObjectForm
|
|
|
|
{
|
2018-06-15 01:31:06 +02:00
|
|
|
/**
|
|
|
|
* @throws \Zend_Form_Exception
|
|
|
|
*/
|
2018-06-14 17:51:48 +02:00
|
|
|
public function setup()
|
|
|
|
{
|
2018-06-15 02:08:06 +02:00
|
|
|
if ($this->isTemplate()) {
|
2018-06-15 01:31:06 +02:00
|
|
|
$this->addElement('text', 'object_name', [
|
|
|
|
'label' => $this->translate('Template name'),
|
|
|
|
'required' => true,
|
|
|
|
]);
|
2018-06-14 17:51:48 +02:00
|
|
|
} else {
|
2018-06-15 01:31:06 +02:00
|
|
|
$this->addElement('text', 'object_name', [
|
|
|
|
'label' => $this->translate('Downtime name'),
|
|
|
|
'required' => true,
|
|
|
|
]);
|
2018-06-14 17:51:48 +02:00
|
|
|
}
|
|
|
|
$this->addImportsElement();
|
2018-06-15 01:31:06 +02:00
|
|
|
$this->addElement('text', 'author', [
|
2019-04-10 17:45:31 +02:00
|
|
|
'label' => $this->translate('Author'),
|
|
|
|
'description' => $this->translate(
|
|
|
|
'This name will show up as the author for ever related downtime'
|
|
|
|
. ' comment'
|
|
|
|
),
|
|
|
|
'required' => ! $this->isTemplate()
|
2018-06-15 01:31:06 +02:00
|
|
|
]);
|
|
|
|
$this->addElement('textarea', 'comment', [
|
|
|
|
'label' => $this->translate('Comment'),
|
2019-04-10 17:45:31 +02:00
|
|
|
'description' => $this->translate(
|
|
|
|
'Every related downtime will show this comment'
|
|
|
|
),
|
2018-06-15 01:31:06 +02:00
|
|
|
'required' => ! $this->isTemplate(),
|
|
|
|
'rows' => 4,
|
|
|
|
]);
|
|
|
|
$this->addBoolean('fixed', [
|
2019-04-10 17:45:31 +02:00
|
|
|
'label' => $this->translate('Fixed'),
|
|
|
|
'description' => $this->translate(
|
|
|
|
'Whether this downtime is fixed or flexible. If unsure please'
|
|
|
|
. ' check the related documentation:'
|
|
|
|
. ' https://icinga.com/docs/icinga2/latest/doc/08-advanced-topics/#downtimes'
|
|
|
|
),
|
|
|
|
'required' => ! $this->isTemplate(),
|
2018-06-15 01:31:06 +02:00
|
|
|
]);
|
|
|
|
$this->addElement('text', 'duration', [
|
2019-04-10 17:45:31 +02:00
|
|
|
'label' => $this->translate('Duration'),
|
|
|
|
'description' => $this->translate(
|
|
|
|
'How long the downtime lasts. Only has an effect for flexible'
|
|
|
|
. ' (non-fixed) downtimes. Time in seconds, supported suffixes'
|
|
|
|
. ' include ms (milliseconds), s (seconds), m (minutes),'
|
|
|
|
. ' h (hours) and d (days). To express "90 minutes" you might'
|
|
|
|
. ' want to write 1h 30m'
|
|
|
|
)
|
2018-06-15 01:31:06 +02:00
|
|
|
]);
|
2019-04-10 17:45:31 +02:00
|
|
|
$this->addDisabledElement();
|
2018-06-15 12:06:18 +02:00
|
|
|
$this->addAssignmentElements();
|
2018-06-14 17:51:48 +02:00
|
|
|
$this->setButtons();
|
|
|
|
}
|
2018-06-15 12:06:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return $this
|
|
|
|
* @throws \Zend_Form_Exception
|
|
|
|
*/
|
|
|
|
protected function addAssignmentElements()
|
|
|
|
{
|
|
|
|
if ($this->isTemplate()) {
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->addElement('select', 'apply_to', [
|
|
|
|
'label' => $this->translate('Apply to'),
|
|
|
|
'description' => $this->translate(
|
|
|
|
'Whether this dependency should affect hosts or services'
|
|
|
|
),
|
|
|
|
'required' => true,
|
|
|
|
'class' => 'autosubmit',
|
|
|
|
'multiOptions' => $this->optionalEnum([
|
|
|
|
'host' => $this->translate('Hosts'),
|
|
|
|
'service' => $this->translate('Services'),
|
|
|
|
])
|
|
|
|
]);
|
|
|
|
|
|
|
|
$applyTo = $this->getSentOrObjectValue('apply_to');
|
|
|
|
|
|
|
|
if (! $applyTo) {
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2019-04-12 12:12:32 +02:00
|
|
|
if ($applyTo === 'host') {
|
|
|
|
$this->addBoolean('with_services', [
|
|
|
|
'label' => $this->translate('With Services'),
|
|
|
|
'description' => $this->translate(
|
|
|
|
'Whether Downtimes should also explicitly be scheduled for'
|
|
|
|
. ' all Services belonging to affected Hosts'
|
|
|
|
)
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2018-06-15 12:06:18 +02:00
|
|
|
$suggestionContext = ucfirst($applyTo) . 'FilterColumns';
|
|
|
|
$this->addAssignFilter([
|
|
|
|
'suggestionContext' => $suggestionContext,
|
|
|
|
'required' => true,
|
|
|
|
'description' => $this->translate(
|
|
|
|
'This allows you to configure an assignment filter. Please feel'
|
2019-07-08 14:11:53 +02:00
|
|
|
. ' free to combine as many nested operators as you want. The'
|
|
|
|
. ' "contains" operator is valid for arrays only. Please use'
|
|
|
|
. ' wildcards and the = (equals) operator when searching for'
|
|
|
|
. ' partial string matches, like in *.example.com'
|
2018-06-15 12:06:18 +02:00
|
|
|
)
|
|
|
|
]);
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
2019-04-11 08:58:19 +02:00
|
|
|
|
|
|
|
protected function setObjectSuccessUrl()
|
|
|
|
{
|
|
|
|
$this->setSuccessUrl(
|
|
|
|
'director/scheduled-downtime',
|
|
|
|
$this->object()->getUrlParams()
|
|
|
|
);
|
|
|
|
}
|
2018-06-14 17:51:48 +02:00
|
|
|
}
|