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; namespace Icinga\Module\Monitoring\Forms\Command\Object;
use DateInterval;
use DateTime; use DateTime;
use Icinga\Application\Config; use Icinga\Application\Config;
use Icinga\Module\Monitoring\Command\Object\PropagateHostDowntimeCommand; use Icinga\Module\Monitoring\Command\Object\PropagateHostDowntimeCommand;
@ -15,6 +16,29 @@ use Icinga\Web\Notification;
*/ */
class ScheduleHostDowntimeCommandForm extends ScheduleServiceDowntimeCommandForm 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) * (non-PHPDoc)
* @see \Icinga\Web\Form::createElements() For the method documentation. * @see \Icinga\Web\Form::createElements() For the method documentation.
@ -23,8 +47,6 @@ class ScheduleHostDowntimeCommandForm extends ScheduleServiceDowntimeCommandForm
{ {
parent::createElements($formData); parent::createElements($formData);
$config = Config::module('monitoring');
$this->addElement( $this->addElement(
'checkbox', 'checkbox',
'all_services', 'all_services',
@ -33,7 +55,7 @@ class ScheduleHostDowntimeCommandForm extends ScheduleServiceDowntimeCommandForm
'Schedule downtime for all services on the hosts and the hosts themselves.' 'Schedule downtime for all services on the hosts and the hosts themselves.'
), ),
'label' => $this->translate('All Services'), '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 DateTime;
use DateInterval; use DateInterval;
use Icinga\Application\Config;
use Icinga\Module\Monitoring\Command\Object\ScheduleServiceDowntimeCommand; use Icinga\Module\Monitoring\Command\Object\ScheduleServiceDowntimeCommand;
use Icinga\Web\Notification; use Icinga\Web\Notification;
use Icinga\Web\Request; use Icinga\Web\Request;
@ -24,18 +25,41 @@ class ScheduleServiceDowntimeCommandForm extends ObjectsCommandForm
*/ */
const FLEXIBLE = 'flexible'; 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 * Initialize this form
*/ */
public function init() public function init()
{ {
$this->addDescription($this->translate( $this->start = new DateTime();
'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' $config = Config::module('monitoring');
. ' downtime expires, Icinga will send out notifications for the hosts and services as it'
. ' normally would. Scheduled downtimes are preserved across program shutdowns and' $this->commentText = $config->get('settings', 'servicedowntime_comment_text');
. ' restarts.' $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()) public function createElements(array $formData = array())
{ {
$start = new DateTime; $this->addDescription($this->translate(
$end = clone $start; 'This command is used to schedule host and service downtimes. During the specified downtime,'
$end->add(new DateInterval('PT1H')); . ' 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( $this->addElements(array(
array( array(
'textarea', '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' . ' the host or service that is having problems. Make sure you enter a brief description of'
. ' what you are doing.' . ' what you are doing.'
), ),
'attribs' => array('class' => 'autofocus') 'attribs' => array('class' => 'autofocus'),
'value' => $this->commentText
) )
), ),
array( array(
'dateTimePicker', 'dateTimePicker',
'start', 'start',
array( array(
'required' => true, 'required' => true,
'label' => $this->translate('Start Time'), 'label' => $this->translate('Start Time'),
'description' => $this->translate('Set the start date and time for the downtime.'), 'description' => $this->translate('Set the start date and time for the downtime.'),
'value' => $start 'value' => $this->start
) )
), ),
array( array(
'dateTimePicker', 'dateTimePicker',
'end', 'end',
array( array(
'required' => true, 'required' => true,
'label' => $this->translate('End Time'), 'label' => $this->translate('End Time'),
'description' => $this->translate('Set the end date and time for the downtime.'), 'description' => $this->translate('Set the end date and time for the downtime.'),
'value' => $end 'preserveDefault' => true,
'value' => $isFlexible ? $this->flexibleEnd : $this->fixedEnd
) )
), ),
array( array(
'select', 'select',
'type', 'type',
array( array(
'required' => true, 'required' => true,
'autosubmit' => true, 'autosubmit' => true,
'label' => $this->translate('Type'), 'label' => $this->translate('Type'),
'description' => $this->translate( 'description' => $this->translate(
'If you select the fixed option, the downtime will be in effect between the start and end' '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' . ' 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' . ' 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( $this->addElements(array(
array( array(
'number', 'number',
@ -136,7 +169,7 @@ class ScheduleServiceDowntimeCommandForm extends ObjectsCommandForm
array( array(
'required' => true, 'required' => true,
'label' => $this->translate('Hours'), 'label' => $this->translate('Hours'),
'value' => 2, 'value' => $this->flexibleDuration->h,
'min' => -1 'min' => -1
) )
), ),
@ -146,7 +179,7 @@ class ScheduleServiceDowntimeCommandForm extends ObjectsCommandForm
array( array(
'required' => true, 'required' => true,
'label' => $this->translate('Minutes'), 'label' => $this->translate('Minutes'),
'value' => 0, 'value' => $this->flexibleDuration->m,
'min' => -1 'min' => -1
) )
) )

View File

@ -19,18 +19,25 @@ by this module.
### Default Settings <a id="monitoring-module-configuration-settings"></a> ### Default Settings <a id="monitoring-module-configuration-settings"></a>
Option | Description Option | Description
------------------------------|----------------------------------------------- ----------------------------------|-----------------------------------------------
acknowledge_expire | **Optional.** Check "Use Expire Time" in Acknowledgement dialog by default. Defaults to **0 (false)**. 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_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_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_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)**. 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 | **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)**. hostdowntime_comment_text | **Optional.** Set default text for "Comment" in Host Downtime dialog by default.
custom_notification_forced | **Optional.** Check "Forced" in Custom Notification dialog by default. Defaults to **0 (false)**. servicedowntime_comment_text | **Optional.** Set default text for "Comment" in Service Downtime dialog by default.
hostcheck_all_services | **Optional.** Check "All Services" in Schedule Host Check 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)**.
hostdowntime_all_services | **Optional.** Check "All Services" in Schedule Host Downtime dialog by default. Defaults to **0 (false)**. 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. Example for having acknowledgements with 2 hours expire time by default.