2013-07-16 15:39:47 +02:00
|
|
|
<?php
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
/**
|
2013-10-23 15:10:33 +02:00
|
|
|
* This file is part of Icinga Web 2.
|
2013-07-16 15:39:47 +02:00
|
|
|
*
|
2013-10-23 15:10:33 +02:00
|
|
|
* Icinga Web 2 - Head for multiple monitoring backends.
|
2013-07-16 15:39:47 +02:00
|
|
|
* Copyright (C) 2013 Icinga Development Team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
2013-10-23 15:10:33 +02:00
|
|
|
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
|
|
|
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
|
|
|
* @author Icinga Development Team <info@icinga.org>
|
|
|
|
*
|
2013-07-16 15:39:47 +02:00
|
|
|
*/
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
|
2013-08-20 15:32:25 +02:00
|
|
|
namespace Icinga\Module\Monitoring\Form\Command;
|
2013-07-16 15:39:47 +02:00
|
|
|
|
2013-08-15 13:42:38 +02:00
|
|
|
use \Icinga\Web\Form\Element\DateTimePicker;
|
|
|
|
use \Icinga\Protocol\Commandpipe\Comment;
|
|
|
|
use \Icinga\Util\DateTimeFactory;
|
2013-09-04 16:21:44 +02:00
|
|
|
use \Icinga\Module\Monitoring\Command\AcknowledgeCommand;
|
2013-08-06 16:11:36 +02:00
|
|
|
|
2013-07-16 15:39:47 +02:00
|
|
|
/**
|
2013-08-06 16:11:36 +02:00
|
|
|
* Form for problem acknowledgements
|
2013-07-16 15:39:47 +02:00
|
|
|
*/
|
2013-08-06 11:01:43 +02:00
|
|
|
class AcknowledgeForm extends CommandForm
|
2013-07-16 15:39:47 +02:00
|
|
|
{
|
|
|
|
/**
|
2013-08-12 13:04:30 +02:00
|
|
|
* Create the form's elements
|
2013-07-16 15:39:47 +02:00
|
|
|
*/
|
|
|
|
protected function create()
|
|
|
|
{
|
2013-08-26 15:06:07 +02:00
|
|
|
$this->addNote(
|
|
|
|
t(
|
|
|
|
'This command is used to acknowledge host or service problems. When a problem is '
|
|
|
|
. 'acknowledged, future notifications about problems are temporarily disabled until the '
|
|
|
|
. 'host/service changes from its current state.'
|
2013-08-15 13:42:38 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2013-07-16 15:39:47 +02:00
|
|
|
$this->addElement($this->createAuthorField());
|
|
|
|
|
|
|
|
$this->addElement(
|
|
|
|
'textarea',
|
|
|
|
'comment',
|
|
|
|
array(
|
2013-08-12 14:20:06 +02:00
|
|
|
'label' => t('Comment'),
|
|
|
|
'rows' => 4,
|
2014-03-25 09:05:53 +01:00
|
|
|
'cols' => 72,
|
2013-08-26 15:06:07 +02:00
|
|
|
'required' => true,
|
|
|
|
'helptext' => t(
|
|
|
|
' If you work with other administrators you may find it useful to share information '
|
|
|
|
. 'about a host or service that is having problems if more than one of you may be working on '
|
|
|
|
. 'it. Make sure you enter a brief description of what you are doing.'
|
2013-08-15 13:42:38 +02:00
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2013-07-16 15:39:47 +02:00
|
|
|
|
|
|
|
$this->addElement(
|
|
|
|
'checkbox',
|
|
|
|
'persistent',
|
|
|
|
array(
|
2013-08-26 15:06:07 +02:00
|
|
|
'label' => t('Persistent Comment'),
|
|
|
|
'value' => false,
|
|
|
|
'helptext' => t(
|
|
|
|
'If you would like the comment to remain even when the acknowledgement is removed, '
|
|
|
|
. 'check this option.'
|
2013-08-15 13:42:38 +02:00
|
|
|
)
|
2013-08-02 16:55:28 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2013-08-15 13:42:38 +02:00
|
|
|
$this->addElement(
|
2013-07-17 14:08:07 +02:00
|
|
|
'checkbox',
|
|
|
|
'expire',
|
|
|
|
array(
|
2013-08-26 15:06:07 +02:00
|
|
|
'label' => t('Use Expire Time'),
|
|
|
|
'helptext' => t('If the acknowledgement should expire, check this option.')
|
2013-08-15 13:42:38 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->enableAutoSubmit(array('expire'));
|
2013-08-26 15:06:07 +02:00
|
|
|
|
2013-08-02 16:55:28 +02:00
|
|
|
if ($this->getRequest()->getPost('expire', '0') === '1') {
|
2013-08-12 14:20:06 +02:00
|
|
|
$now = DateTimeFactory::create();
|
2013-08-15 13:42:38 +02:00
|
|
|
$this->addElement(
|
|
|
|
new DateTimePicker(
|
|
|
|
array(
|
2013-08-30 10:37:32 +02:00
|
|
|
'name' => 'expiretime',
|
|
|
|
'label' => t('Expire Time'),
|
|
|
|
'value' => $now->getTimestamp() + 3600,
|
|
|
|
'patterns' => $this->getValidDateTimeFormats(),
|
|
|
|
'helptext' => t(
|
2013-08-16 17:38:00 +02:00
|
|
|
'Enter the expire date/time for this acknowledgement here. Icinga will '
|
|
|
|
. ' delete the acknowledgement after this date expired.'
|
2013-10-20 15:30:49 +02:00
|
|
|
),
|
|
|
|
'jspicker' => true
|
2013-08-15 13:42:38 +02:00
|
|
|
)
|
2013-08-02 16:55:28 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2013-07-17 14:08:07 +02:00
|
|
|
|
2013-07-16 15:39:47 +02:00
|
|
|
$this->addElement(
|
|
|
|
'checkbox',
|
|
|
|
'sticky',
|
|
|
|
array(
|
2013-08-26 15:06:07 +02:00
|
|
|
'label' => t('Sticky Acknowledgement'),
|
|
|
|
'value' => true,
|
|
|
|
'helptext' => t(
|
|
|
|
'If you want the acknowledgement to disable notifications until the host/service '
|
|
|
|
. 'recovers, check this option.'
|
2013-08-15 13:42:38 +02:00
|
|
|
)
|
2013-07-16 15:39:47 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->addElement(
|
|
|
|
'checkbox',
|
|
|
|
'notify',
|
|
|
|
array(
|
2013-08-26 15:06:07 +02:00
|
|
|
'label' => t('Send Notification'),
|
|
|
|
'value' => true,
|
|
|
|
'helptext' => t(
|
|
|
|
'If you do not want an acknowledgement notification to be sent out to the appropriate '
|
|
|
|
. 'contacts, uncheck this option.'
|
2013-08-15 13:42:38 +02:00
|
|
|
)
|
2013-07-16 15:39:47 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2013-08-15 14:49:20 +02:00
|
|
|
$this->setSubmitLabel(t('Acknowledge Problem'));
|
2013-07-16 15:39:47 +02:00
|
|
|
|
|
|
|
parent::create();
|
|
|
|
}
|
2013-07-18 13:46:12 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add validator for dependent fields
|
2013-08-12 14:20:06 +02:00
|
|
|
*
|
2013-08-15 13:42:38 +02:00
|
|
|
* @param array $data
|
|
|
|
*
|
2013-08-12 14:20:06 +02:00
|
|
|
* @see \Icinga\Web\Form::preValidation()
|
2013-07-18 13:46:12 +02:00
|
|
|
*/
|
2013-07-23 17:09:06 +02:00
|
|
|
protected function preValidation(array $data)
|
2013-07-18 13:46:12 +02:00
|
|
|
{
|
2013-07-24 12:43:26 +02:00
|
|
|
if (isset($data['expire']) && intval($data['expire']) === 1) {
|
2013-07-18 13:46:12 +02:00
|
|
|
$expireTime = $this->getElement('expiretime');
|
|
|
|
$expireTime->setRequired(true);
|
|
|
|
}
|
|
|
|
}
|
2013-08-01 15:15:38 +02:00
|
|
|
|
2013-08-15 13:42:38 +02:00
|
|
|
/**
|
2013-09-03 14:50:50 +02:00
|
|
|
* Create the acknowledgement command object
|
2013-08-15 13:42:38 +02:00
|
|
|
*
|
2013-09-03 14:50:50 +02:00
|
|
|
* @return AcknowledgeCommand
|
2013-08-15 13:42:38 +02:00
|
|
|
*/
|
2013-09-03 14:50:50 +02:00
|
|
|
public function createCommand()
|
2013-08-01 15:15:38 +02:00
|
|
|
{
|
2013-09-04 10:50:00 +02:00
|
|
|
return new AcknowledgeCommand(
|
2013-08-01 15:15:38 +02:00
|
|
|
new Comment(
|
|
|
|
$this->getAuthorName(),
|
|
|
|
$this->getValue('comment'),
|
|
|
|
$this->getValue('persistent')
|
2013-09-04 10:50:00 +02:00
|
|
|
),
|
|
|
|
$this->getValue('expire') ? $this->getValue('expire') : -1,
|
|
|
|
$this->getValue('notify'),
|
|
|
|
$this->getValue('sticky')
|
2013-08-01 15:15:38 +02:00
|
|
|
);
|
|
|
|
}
|
2013-07-17 14:08:07 +02:00
|
|
|
}
|