Merge pull request #4162 from Icinga/feature/expire-comments-3447
Monitoring: add expire option for comments
This commit is contained in:
commit
bef52f3f2e
|
@ -3,6 +3,8 @@
|
||||||
|
|
||||||
namespace Icinga\Module\Monitoring\Forms\Command\Object;
|
namespace Icinga\Module\Monitoring\Forms\Command\Object;
|
||||||
|
|
||||||
|
use DateInterval;
|
||||||
|
use DateTime;
|
||||||
use Icinga\Application\Config;
|
use Icinga\Application\Config;
|
||||||
use Icinga\Module\Monitoring\Command\Object\AddCommentCommand;
|
use Icinga\Module\Monitoring\Command\Object\AddCommentCommand;
|
||||||
use Icinga\Web\Notification;
|
use Icinga\Web\Notification;
|
||||||
|
@ -63,6 +65,52 @@ class AddCommentCommandForm extends ObjectsCommandForm
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (version_compare($this->getBackend()->getProgramVersion(), '2.13.0', '>=')) {
|
||||||
|
$config = Config::module('monitoring');
|
||||||
|
$commentExpire = (bool) $config->get('settings', 'comment_expire', false);
|
||||||
|
|
||||||
|
$this->addElement(
|
||||||
|
'checkbox',
|
||||||
|
'expire',
|
||||||
|
[
|
||||||
|
'label' => $this->translate('Use Expire Time'),
|
||||||
|
'value' => $commentExpire,
|
||||||
|
'description' => $this->translate('If the comment should expire, check this option.'),
|
||||||
|
'autosubmit' => true
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
if (isset($formData['expire']) ? $formData['expire'] : $commentExpire) {
|
||||||
|
$expireTime = new DateTime();
|
||||||
|
$expireTime->add(new DateInterval($config->get('settings', 'comment_expire_time', 'PT1H')));
|
||||||
|
|
||||||
|
$this->addElement(
|
||||||
|
'dateTimePicker',
|
||||||
|
'expire_time',
|
||||||
|
[
|
||||||
|
'label' => $this->translate('Expire Time'),
|
||||||
|
'value' => $expireTime,
|
||||||
|
'description' => $this->translate(
|
||||||
|
'Enter the expire date and time for this comment here. Icinga will delete the'
|
||||||
|
. ' comment after this time expired.'
|
||||||
|
)
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->addDisplayGroup(
|
||||||
|
['expire', 'expire_time'],
|
||||||
|
'expire-expire_time',
|
||||||
|
[
|
||||||
|
'decorators' => [
|
||||||
|
'FormElements',
|
||||||
|
['HtmlTag', ['tag' => 'div']]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,6 +129,13 @@ class AddCommentCommandForm extends ObjectsCommandForm
|
||||||
if (($persistent = $this->getElement('persistent')) !== null) {
|
if (($persistent = $this->getElement('persistent')) !== null) {
|
||||||
$comment->setPersistent($persistent->isChecked());
|
$comment->setPersistent($persistent->isChecked());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$expire = $this->getElement('expire');
|
||||||
|
|
||||||
|
if ($expire !== null && $expire->isChecked()) {
|
||||||
|
$comment->setExpireTime($this->getElement('expire_time')->getValue()->getTimestamp());
|
||||||
|
}
|
||||||
|
|
||||||
$this->getTransport($this->request)->send($comment);
|
$this->getTransport($this->request)->send($comment);
|
||||||
}
|
}
|
||||||
Notification::success($this->translatePlural(
|
Notification::success($this->translatePlural(
|
||||||
|
|
|
@ -50,6 +50,13 @@ if (empty($object->comments) && ! $addLink) {
|
||||||
<span class="comment-time">
|
<span class="comment-time">
|
||||||
<?= $this->translate('commented') ?>
|
<?= $this->translate('commented') ?>
|
||||||
<?= $this->timeAgo($comment->timestamp) ?>
|
<?= $this->timeAgo($comment->timestamp) ?>
|
||||||
|
<?php if ($comment->expiration): ?>
|
||||||
|
<span aria-hidden="true">ǀ</span>
|
||||||
|
<?= sprintf(
|
||||||
|
$this->translate('Expires %s'),
|
||||||
|
$this->timeUntil($comment->expiration)
|
||||||
|
) ?>
|
||||||
|
<?php endif ?>
|
||||||
</span>
|
</span>
|
||||||
<?= $comment->persistent ? $this->icon('attach', 'This comment is persistent.') : '' ?>
|
<?= $comment->persistent ? $this->icon('attach', 'This comment is persistent.') : '' ?>
|
||||||
<?php if (isset($delCommentForm)) {
|
<?php if (isset($delCommentForm)) {
|
||||||
|
|
|
@ -26,6 +26,8 @@ acknowledge_expire_time | **Optional.** Set default value for "Expire Time
|
||||||
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_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)**.
|
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)**.
|
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)**.
|
hostdowntime_all_services | **Optional.** Check "All Services" in Schedule Host Downtime dialog by default. Defaults to **0 (false)**.
|
||||||
|
|
|
@ -24,6 +24,13 @@ class AddCommentCommand extends WithCommentCommand
|
||||||
*/
|
*/
|
||||||
protected $persistent;
|
protected $persistent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Optional time when the acknowledgement should expire
|
||||||
|
*
|
||||||
|
* @var int|null
|
||||||
|
*/
|
||||||
|
protected $expireTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set whether the comment is persistent
|
* Set whether the comment is persistent
|
||||||
*
|
*
|
||||||
|
@ -46,4 +53,28 @@ class AddCommentCommand extends WithCommentCommand
|
||||||
{
|
{
|
||||||
return $this->persistent;
|
return $this->persistent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the time when the acknowledgement should expire
|
||||||
|
*
|
||||||
|
* @param int $expireTime
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setExpireTime($expireTime)
|
||||||
|
{
|
||||||
|
$this->expireTime = (int) $expireTime;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the time when the acknowledgement should expire
|
||||||
|
*
|
||||||
|
* @return int|null
|
||||||
|
*/
|
||||||
|
public function getExpireTime()
|
||||||
|
{
|
||||||
|
return $this->expireTime;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,6 +99,11 @@ class IcingaApiCommandRenderer implements IcingaCommandRendererInterface
|
||||||
'author' => $command->getAuthor(),
|
'author' => $command->getAuthor(),
|
||||||
'comment' => $command->getComment()
|
'comment' => $command->getComment()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ($command->getExpireTime() !== null) {
|
||||||
|
$data['expiry'] = $command->getExpireTime();
|
||||||
|
}
|
||||||
|
|
||||||
$this->applyFilter($data, $command->getObject());
|
$this->applyFilter($data, $command->getObject());
|
||||||
return IcingaApiCommand::create($endpoint, $data);
|
return IcingaApiCommand::create($endpoint, $data);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue