2013-07-16 15:39:47 +02:00
|
|
|
<?php
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
/**
|
|
|
|
* This file is part of Icinga 2 Web.
|
|
|
|
*
|
|
|
|
* Icinga 2 Web - Head for multiple monitoring backends.
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @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>
|
|
|
|
*/
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
|
|
|
|
namespace Monitoring\Form\Command;
|
|
|
|
|
2013-08-15 13:42:38 +02:00
|
|
|
use \Icinga\Web\Form\Element\DateTimePicker;
|
|
|
|
use \Icinga\Web\Form\Element\Note;
|
|
|
|
use \Icinga\Protocol\Commandpipe\Acknowledgement;
|
|
|
|
use \Icinga\Protocol\Commandpipe\Comment;
|
|
|
|
use \Icinga\Util\DateTimeFactory;
|
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-15 13:42:38 +02:00
|
|
|
$this->addElement(
|
|
|
|
new Note(
|
|
|
|
array(
|
|
|
|
'name' => 'commanddescription',
|
|
|
|
'value' => t(
|
|
|
|
'This command is used to acknowledge a host/service problem. When a problem is '
|
|
|
|
. 'acknowledged, future notifications about problems are temporarily disabled until the '
|
|
|
|
. 'host/service changes from its current state.'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
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,
|
|
|
|
'required' => true
|
2013-07-16 15:39:47 +02:00
|
|
|
)
|
|
|
|
);
|
2013-08-15 13:42:38 +02:00
|
|
|
$this->addElement(
|
|
|
|
new Note(
|
|
|
|
array(
|
|
|
|
'name' => 'commentnote',
|
|
|
|
'value' => 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-07-16 15:39:47 +02:00
|
|
|
|
|
|
|
$this->addElement(
|
|
|
|
'checkbox',
|
|
|
|
'persistent',
|
|
|
|
array(
|
|
|
|
'label' => t('Persistent comment'),
|
|
|
|
'value' => false
|
|
|
|
)
|
|
|
|
);
|
2013-08-15 13:42:38 +02:00
|
|
|
$this->addElement(
|
|
|
|
new Note(
|
|
|
|
array(
|
|
|
|
'name' => 'persistentnote',
|
|
|
|
'value' => t(
|
|
|
|
'If you would like the comment to remain once the acknowledgement is removed, '
|
|
|
|
. 'check this option.'
|
|
|
|
)
|
|
|
|
)
|
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-15 13:42:38 +02:00
|
|
|
'label' => t('Use Expire Time')
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->enableAutoSubmit(array('expire'));
|
|
|
|
$this->addElement(
|
|
|
|
new Note(
|
|
|
|
array(
|
|
|
|
'name' => 'expirenote',
|
|
|
|
'value' => t('If the acknowledgement should expire, check this option.')
|
|
|
|
)
|
2013-07-17 14:08: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(
|
|
|
|
'name' => 'expiretime',
|
|
|
|
'label' => t('Expire Time'),
|
|
|
|
'value' => $now->getTimestamp() + 3600
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->addElement(
|
|
|
|
new Note(
|
|
|
|
array(
|
|
|
|
'name' => 'expiretimenote',
|
|
|
|
'value' => t(
|
|
|
|
'Enter here the expire date/time for this acknowledgement. Icinga will '
|
|
|
|
. ' delete the acknowledgement after this time expired.'
|
|
|
|
)
|
|
|
|
)
|
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-15 13:42:38 +02:00
|
|
|
'label' => t('Sticky Acknowledgement'),
|
|
|
|
'value' => true
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->addElement(
|
|
|
|
new Note(
|
|
|
|
array(
|
|
|
|
'name' => 'stickynote',
|
|
|
|
'value' => t(
|
|
|
|
'If you want the acknowledgement to disable notifications until the host/service '
|
|
|
|
. 'recovers, check this option.'
|
|
|
|
)
|
|
|
|
)
|
2013-07-16 15:39:47 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->addElement(
|
|
|
|
'checkbox',
|
|
|
|
'notify',
|
|
|
|
array(
|
|
|
|
'label' => t('Send notification'),
|
2013-08-15 13:42:38 +02:00
|
|
|
'value' => true
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->addElement(
|
|
|
|
new Note(
|
|
|
|
array(
|
|
|
|
'name' => 'sendnotificationnote',
|
|
|
|
'value' => t(
|
|
|
|
'If you do not want an acknowledgement notification sent out to the appropriate '
|
|
|
|
. 'contacts, uncheck this option.'
|
|
|
|
)
|
|
|
|
)
|
2013-07-16 15:39:47 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->setSubmitLabel(t('Acknowledge problem'));
|
|
|
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* Create acknowledgement from request data
|
|
|
|
*
|
|
|
|
* @return \Icinga\Protocol\Commandpipe\Acknowledgement
|
|
|
|
*/
|
2013-08-01 15:15:38 +02:00
|
|
|
public function getAcknowledgement()
|
|
|
|
{
|
|
|
|
$expireTime = -1;
|
|
|
|
if ($this->getValue('expire')) {
|
2013-08-12 14:20:06 +02:00
|
|
|
$expireTime = $this->getValue('expiretime');
|
2013-08-01 15:15:38 +02:00
|
|
|
}
|
|
|
|
return new Acknowledgement(
|
|
|
|
new Comment(
|
|
|
|
$this->getAuthorName(),
|
|
|
|
$this->getValue('comment'),
|
|
|
|
$this->getValue('persistent')
|
|
|
|
),
|
|
|
|
$this->getValue('notify'),
|
|
|
|
$expireTime,
|
|
|
|
$this->getValue('sticky')
|
|
|
|
);
|
|
|
|
}
|
2013-07-17 14:08:07 +02:00
|
|
|
}
|