Add end time and comment options to settings section for host/service downtime dialog

[hostdowntime_end_fixed], [hostdowntime_end_flexible], [hostdowntime_flexible_duration], [servicedowntime_end_fixed], [servicedwontime_end_flexible],
[servicedowntime_flexible_duration] and [comment_text] options added to [settings] section in config.ini file used in  host/service downtime dialog.
This commit is contained in:
Ravi Kumar Kempapura Srinivasa 2021-06-16 16:42:02 +02:00 committed by Johannes Meyer
parent 35659c8d51
commit f8b122b894
3 changed files with 103 additions and 41 deletions

View File

@ -3,6 +3,7 @@
namespace Icinga\Module\Monitoring\Forms\Command\Object;
use DateInterval;
use DateTime;
use Icinga\Application\Config;
use Icinga\Module\Monitoring\Command\Object\PropagateHostDowntimeCommand;
@ -15,6 +16,29 @@ use Icinga\Web\Notification;
*/
class ScheduleHostDowntimeCommandForm extends ScheduleServiceDowntimeCommandForm
{
/** @var bool */
protected $hostDowntimeAllServices;
public function init()
{
$this->start = new DateTime();
$config = Config::module('monitoring');
$this->commentText = $config->get('settings', 'hostdowntime_comment_text');
$this->hostDowntimeAllServices = (bool) $config->get('settings', 'hostdowntime_all_services', false);
$fixedEnd = clone $this->start;
$fixed = $config->get('settings', 'hostdowntime_end_fixed', 'PT1H');
$this->fixedEnd = $fixedEnd->add(new DateInterval($fixed));
$flexibleEnd = clone $this->start;
$flexible = $config->get('settings', 'hostdowntime_end_flexible', 'PT1H');
$this->flexibleEnd = $flexibleEnd->add(new DateInterval($flexible));
$flexibleDuration = $config->get('settings', 'hostdowntime_flexible_duration', 'PT2H');
$this->flexibleDuration = new DateInterval($flexibleDuration);
}
/**
* (non-PHPDoc)
* @see \Icinga\Web\Form::createElements() For the method documentation.
@ -23,8 +47,6 @@ class ScheduleHostDowntimeCommandForm extends ScheduleServiceDowntimeCommandForm
{
parent::createElements($formData);
$config = Config::module('monitoring');
$this->addElement(
'checkbox',
'all_services',
@ -33,7 +55,7 @@ class ScheduleHostDowntimeCommandForm extends ScheduleServiceDowntimeCommandForm
'Schedule downtime for all services on the hosts and the hosts themselves.'
),
'label' => $this->translate('All Services'),
'value' => (bool) $config->get('settings', 'hostdowntime_all_services', false)
'value' => $this->hostDowntimeAllServices
)
);

View File

@ -5,6 +5,7 @@ namespace Icinga\Module\Monitoring\Forms\Command\Object;
use DateTime;
use DateInterval;
use Icinga\Application\Config;
use Icinga\Module\Monitoring\Command\Object\ScheduleServiceDowntimeCommand;
use Icinga\Web\Notification;
use Icinga\Web\Request;
@ -24,18 +25,41 @@ class ScheduleServiceDowntimeCommandForm extends ObjectsCommandForm
*/
const FLEXIBLE = 'flexible';
/** @var DateTime downtime start */
protected $start;
/** @var DateTime fixed downtime end */
protected $fixedEnd;
/** @var DateTime flexible downtime end */
protected $flexibleEnd;
/** @var DateInterval flexible downtime duration */
protected $flexibleDuration;
/** @var mixed Comment text */
protected $commentText;
/**
* Initialize this form
*/
public function init()
{
$this->addDescription($this->translate(
'This command is used to schedule host and service downtimes. During the specified downtime,'
. ' Icinga will not send notifications out about the hosts and services. When the scheduled'
. ' downtime expires, Icinga will send out notifications for the hosts and services as it'
. ' normally would. Scheduled downtimes are preserved across program shutdowns and'
. ' restarts.'
));
$this->start = new DateTime();
$config = Config::module('monitoring');
$this->commentText = $config->get('settings', 'servicedowntime_comment_text');
$fixedEnd = clone $this->start;
$fixed = $config->get('settings', 'servicedowntime_end_fixed', 'PT1H');
$this->fixedEnd = $fixedEnd->add(new DateInterval($fixed));
$flexibleEnd = clone $this->start;
$flexible = $config->get('settings', 'servicedowntime_end_flexible', 'PT1H');
$this->flexibleEnd = $flexibleEnd->add(new DateInterval($flexible));
$flexibleDuration = $config->get('settings', 'servicedowntime_flexible_duration', 'PT2H');
$this->flexibleDuration = new DateInterval($flexibleDuration);
}
/**
@ -53,9 +77,16 @@ class ScheduleServiceDowntimeCommandForm extends ObjectsCommandForm
*/
public function createElements(array $formData = array())
{
$start = new DateTime;
$end = clone $start;
$end->add(new DateInterval('PT1H'));
$this->addDescription($this->translate(
'This command is used to schedule host and service downtimes. During the specified downtime,'
. ' Icinga will not send notifications out about the hosts and services. When the scheduled'
. ' downtime expires, Icinga will send out notifications for the hosts and services as it'
. ' normally would. Scheduled downtimes are preserved across program shutdowns and'
. ' restarts.'
));
$isFlexible = (bool) isset($formData['type']) && $formData['type'] === self::FLEXIBLE;
$this->addElements(array(
array(
'textarea',
@ -68,37 +99,39 @@ class ScheduleServiceDowntimeCommandForm extends ObjectsCommandForm
. ' the host or service that is having problems. Make sure you enter a brief description of'
. ' what you are doing.'
),
'attribs' => array('class' => 'autofocus')
'attribs' => array('class' => 'autofocus'),
'value' => $this->commentText
)
),
array(
'dateTimePicker',
'start',
array(
'required' => true,
'label' => $this->translate('Start Time'),
'description' => $this->translate('Set the start date and time for the downtime.'),
'value' => $start
'required' => true,
'label' => $this->translate('Start Time'),
'description' => $this->translate('Set the start date and time for the downtime.'),
'value' => $this->start
)
),
array(
'dateTimePicker',
'end',
array(
'required' => true,
'label' => $this->translate('End Time'),
'description' => $this->translate('Set the end date and time for the downtime.'),
'value' => $end
'required' => true,
'label' => $this->translate('End Time'),
'description' => $this->translate('Set the end date and time for the downtime.'),
'preserveDefault' => true,
'value' => $isFlexible ? $this->flexibleEnd : $this->fixedEnd
)
),
array(
'select',
'type',
array(
'required' => true,
'autosubmit' => true,
'label' => $this->translate('Type'),
'description' => $this->translate(
'required' => true,
'autosubmit' => true,
'label' => $this->translate('Type'),
'description' => $this->translate(
'If you select the fixed option, the downtime will be in effect between the start and end'
. ' times you specify whereas a flexible downtime starts when the host or service enters a'
. ' problem state sometime between the start and end times you specified and lasts as long'
@ -128,7 +161,7 @@ class ScheduleServiceDowntimeCommandForm extends ObjectsCommandForm
)
)
);
if (isset($formData['type']) && $formData['type'] === self::FLEXIBLE) {
if ($isFlexible) {
$this->addElements(array(
array(
'number',
@ -136,7 +169,7 @@ class ScheduleServiceDowntimeCommandForm extends ObjectsCommandForm
array(
'required' => true,
'label' => $this->translate('Hours'),
'value' => 2,
'value' => $this->flexibleDuration->h,
'min' => -1
)
),
@ -146,7 +179,7 @@ class ScheduleServiceDowntimeCommandForm extends ObjectsCommandForm
array(
'required' => true,
'label' => $this->translate('Minutes'),
'value' => 0,
'value' => $this->flexibleDuration->m,
'min' => -1
)
)

View File

@ -19,18 +19,25 @@ by this module.
### Default Settings <a id="monitoring-module-configuration-settings"></a>
Option | Description
------------------------------|-----------------------------------------------
acknowledge_expire | **Optional.** Check "Use Expire Time" in Acknowledgement dialog by default. Defaults to **0 (false)**.
acknowledge_expire_time | **Optional.** Set default value for "Expire Time" in Acknowledgement dialog, its calculated as now + this setting. Format is a [PHP Dateinterval](http://www.php.net/manual/en/dateinterval.construct.php). Defaults to **1 hour (PT1H)**.
acknowledge_notify | **Optional.** Check "Send Notification" in Acknowledgement dialog by default. Defaults to **1 (true)**.
acknowledge_persistent | **Optional.** Check "Persistent Comment" in Acknowledgement dialog by default. Defaults to **0 (false)**.
acknowledge_sticky | **Optional.** Check "Sticky Acknowledgement" in Acknowledgement dialog by default. Defaults to **0 (false)**.
comment_expire | **Optional.** Check "Use Expire Time" in Comment dialog by default. Defaults to **0 (false)**.
comment_expire_time | **Optional.** Set default value for "Expire Time" in Comment dialog, its calculated as now + this setting. Format is a [PHP Dateinterval](http://www.php.net/manual/en/dateinterval.construct.php). Defaults to **1 hour (PT1H)**.
custom_notification_forced | **Optional.** Check "Forced" in Custom Notification dialog by default. Defaults to **0 (false)**.
hostcheck_all_services | **Optional.** Check "All Services" in Schedule Host Check dialog by default. Defaults to **0 (false)**.
hostdowntime_all_services | **Optional.** Check "All Services" in Schedule Host Downtime dialog by default. Defaults to **0 (false)**.
Option | Description
----------------------------------|-----------------------------------------------
acknowledge_expire | **Optional.** Check "Use Expire Time" in Acknowledgement dialog by default. Defaults to **0 (false)**.
acknowledge_expire_time | **Optional.** Set default value for "Expire Time" in Acknowledgement dialog, its calculated as now + this setting. Format is a [PHP Dateinterval](http://www.php.net/manual/en/dateinterval.construct.php). Defaults to **1 hour (PT1H)**.
acknowledge_notify | **Optional.** Check "Send Notification" in Acknowledgement dialog by default. Defaults to **1 (true)**.
acknowledge_persistent | **Optional.** Check "Persistent Comment" in Acknowledgement dialog by default. Defaults to **0 (false)**.
acknowledge_sticky | **Optional.** Check "Sticky Acknowledgement" in Acknowledgement dialog by default. Defaults to **0 (false)**.
comment_expire | **Optional.** Check "Use Expire Time" in Comment dialog by default. Defaults to **0 (false)**.
hostdowntime_comment_text | **Optional.** Set default text for "Comment" in Host Downtime dialog by default.
servicedowntime_comment_text | **Optional.** Set default text for "Comment" in Service Downtime dialog by default.
comment_expire_time | **Optional.** Set default value for "Expire Time" in Comment dialog, its calculated as now + this setting. Format is a [PHP Dateinterval](http://www.php.net/manual/en/dateinterval.construct.php). Defaults to **1 hour (PT1H)**.
custom_notification_forced | **Optional.** Check "Forced" in Custom Notification dialog by default. Defaults to **0 (false)**.
hostcheck_all_services | **Optional.** Check "All Services" in Schedule Host Check dialog by default. Defaults to **0 (false)**.
hostdowntime_end_fixed | **Optional.** Set default value for "End Time" in Schedule Host Downtime dialog for **Fixed** downtime, its calculated as now + this setting. Format is a [PHP Dateinterval](http://www.php.net/manual/en/dateinterval.construct.php). Defaults to **1 hour (PT1H)**.
hostdowntime_end_flexible | **Optional.** Set default value for "End Time" in Schedule Host Downtime dialog for **Flexible** downtime, its calculated as now + this setting. Format is a [PHP Dateinterval](http://www.php.net/manual/en/dateinterval.construct.php). Defaults to **1 hour (PT1H)**.
hostdowntime_flexible_duration | **Optional.** Set default value for "Flexible Duration" in Schedule Host Downtime dialog for **Flexible** downtime. Format is a [PHP Dateinterval](http://www.php.net/manual/en/dateinterval.construct.php). Defaults to **2 hour (PT2H)**.
servicedowntime_end_fixed | **Optional.** Set default value for "End Time" in Schedule Service Downtime dialog for **Fixed** downtime, its calculated as now + this setting. Format is a [PHP Dateinterval](http://www.php.net/manual/en/dateinterval.construct.php). Defaults to **1 hour (PT1H)**.
servicedowntime_end_flexible | **Optional.** Set default value for "End Time" in Schedule Service Downtime dialog for **Flexible** downtime, its calculated as now + this setting. Format is a [PHP Dateinterval](http://www.php.net/manual/en/dateinterval.construct.php). Defaults to **1 hour (PT1H)**.
servicedowntime_flexible_duration | **Optional.** Set default value for "Flexible Duration" in Schedule Service Downtime dialog for **Flexible** downtime. Format is a [PHP Dateinterval](http://www.php.net/manual/en/dateinterval.construct.php). Defaults to **2 hour (PT2H)**.
Example for having acknowledgements with 2 hours expire time by default.