Merge branch 'bugfix/command-forms-lack-help-messages-4524'
fixes #4524
This commit is contained in:
commit
6928a806ab
|
@ -2,24 +2,24 @@
|
|||
// {{{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>
|
||||
|
@ -648,31 +648,31 @@ class CommandPipe
|
|||
}
|
||||
|
||||
/**
|
||||
* Send a custom host or service notification
|
||||
* Send custom host and/or service notifications
|
||||
*
|
||||
* @param $objects monitoring objects to send this notification to
|
||||
* @param Comment $comment comment to use in the notification
|
||||
* @param int [$...] Optional list of Notification flags which will be used as the option parameter
|
||||
* @param array $objects Affected monitoring objects
|
||||
* @param CustomNotification $notification
|
||||
*/
|
||||
public function sendCustomNotification($objects, Comment $comment, $optionsVarList = 0/*, ...*/)
|
||||
public function sendCustomNotification(array $objects, CustomNotification $notification)
|
||||
{
|
||||
$args = func_get_args();
|
||||
// logical OR for all notification options
|
||||
for ($i = 3; $i < count($args); $i++) {
|
||||
$optionsVarList |= $args[$i];
|
||||
}
|
||||
|
||||
foreach ($objects as $object) {
|
||||
$type = $this->getObjectType($object);
|
||||
$msg = 'SEND_CUSTOM_'.(($type == self::TYPE_SERVICE) ? 'SVC' : 'HOST' ).'_NOTIFICATION';
|
||||
$msg .= ';'.$object->host_name;
|
||||
if ($type == self::TYPE_SERVICE) {
|
||||
$msg .= ';'.$object->service_description;
|
||||
foreach ($objects as $hostOrService) {
|
||||
if (isset($hostOrService->service_description) && isset($hostOrService->host_name)) {
|
||||
// Assume service
|
||||
$command = sprintf(
|
||||
$notification->getFormatString(self::TYPE_SERVICE),
|
||||
$hostOrService->host_name,
|
||||
$hostOrService->service_description
|
||||
);
|
||||
} elseif (isset($hostOrService->host_name)) {
|
||||
// Assume host
|
||||
$command = sprintf(
|
||||
$notification->getFormatString(self::TYPE_HOST),
|
||||
$hostOrService->host_name
|
||||
);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
$msg .= ';'.$optionsVarList;
|
||||
$msg .= ';'.$comment->author;
|
||||
$msg .= ';'.$comment->comment;
|
||||
$this->send($msg);
|
||||
$this->send($command);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,109 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Protocol\Commandpipe;
|
||||
|
||||
/**
|
||||
* Custom notification about hosts or services sent to Icinga's command pipe
|
||||
*/
|
||||
class CustomNotification
|
||||
{
|
||||
/**
|
||||
* Notification comment
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $comment;
|
||||
|
||||
/**
|
||||
* Notification author
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $author;
|
||||
|
||||
/**
|
||||
* Whether to force the notification to be sent out, regardless of the time restrictions, whether or not
|
||||
* notifications are enabled, etc.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $forced;
|
||||
|
||||
/**
|
||||
* Whether the notification is sent out to all normal (non-escalated) and escalated contacts
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $broadcast;
|
||||
|
||||
/**
|
||||
* 1 = Broadcast (send notification to all normal and all escalated contacts for the host)
|
||||
*/
|
||||
const NOTIFY_BROADCAST = 1;
|
||||
|
||||
/**
|
||||
* 2 = Forced (notification is sent out regardless of current time, whether or not notifications are enabled, etc.)
|
||||
*/
|
||||
const NOTIFY_FORCED = 2;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $author Notification author
|
||||
* @param string $comment Notification comment
|
||||
* @param bool $forced Whether to force the notification to be sent out, regardless of the time
|
||||
* restrictions, whether or not notifications are enabled, etc.
|
||||
* @param bool $broadcast Whether the notification is sent out to all normal (non-escalated) and escalated
|
||||
* contacts
|
||||
*/
|
||||
public function __construct($author, $comment, $forced = false, $broadcast = false)
|
||||
{
|
||||
$this->author = $author;
|
||||
$this->comment = $comment;
|
||||
$this->forced = $forced;
|
||||
$this->broadcast = $broadcast;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Custom Notification command format string according to if its sent to a host or a service
|
||||
*
|
||||
* @param string $type Identifier for either host or service
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws InvalidCommandException When the given type is unknown
|
||||
* @see \Icinga\Protocol\Commandpipe\CommandPipe::TYPE_HOST
|
||||
* @see \Icinga\Protocol\Commandpipe\CommandPipe::TYPE_SERVICE
|
||||
*/
|
||||
public function getFormatString($type)
|
||||
{
|
||||
switch ($type) {
|
||||
case CommandPipe::TYPE_HOST:
|
||||
$format = '%s';
|
||||
break;
|
||||
case CommandPipe::TYPE_SERVICE:
|
||||
$format = '%s;%s';
|
||||
break;
|
||||
default:
|
||||
throw new InvalidCommandException('Custom Notifications can only apply on hosts and services');
|
||||
}
|
||||
|
||||
$options = 0;
|
||||
if ($this->forced) {
|
||||
$options |= self::NOTIFY_FORCED;
|
||||
}
|
||||
if ($this->broadcast) {
|
||||
$options |= self::NOTIFY_BROADCAST;
|
||||
}
|
||||
|
||||
// Build the command
|
||||
$command = 'SEND_CUSTOM_' . $type . '_NOTIFICATION;'
|
||||
. $format . ';'
|
||||
. $options . ';'
|
||||
. $this->author . ';'
|
||||
. $this->comment;
|
||||
return $command;
|
||||
}
|
||||
}
|
|
@ -431,12 +431,7 @@ class Monitoring_CommandController extends ModuleActionController
|
|||
$this->setForm($form);
|
||||
|
||||
if ($form->IsSubmittedAndValid() === true) {
|
||||
$author = $this->getRequest()->getUser()->getUsername();
|
||||
$this->target->sendCustomNotification(
|
||||
$this->view->objects,
|
||||
new Comment($author, $form->getComment()),
|
||||
$form->getOptions()
|
||||
);
|
||||
$this->target->sendCustomNotification($this->view->objects, $form->getCustomNotification());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,30 +28,35 @@
|
|||
|
||||
namespace Monitoring\Form\Command;
|
||||
|
||||
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;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Form for problem acknowledgements
|
||||
*/
|
||||
class AcknowledgeForm extends CommandForm
|
||||
{
|
||||
/**
|
||||
* Initialize form
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
$this->setName('AcknowledgeForm');
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the form's elements
|
||||
*/
|
||||
protected function create()
|
||||
{
|
||||
$this->addElement(
|
||||
new Note(
|
||||
array(
|
||||
'name' => 'commanddescription',
|
||||
'value' => 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.'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement($this->createAuthorField());
|
||||
|
||||
$this->addElement(
|
||||
|
@ -63,66 +68,96 @@ class AcknowledgeForm extends CommandForm
|
|||
'required' => true
|
||||
)
|
||||
);
|
||||
$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.'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'checkbox',
|
||||
'persistent',
|
||||
array(
|
||||
'label' => t('Persistent comment'),
|
||||
'label' => t('Persistent Comment'),
|
||||
'value' => false
|
||||
)
|
||||
);
|
||||
|
||||
$expireNote = new Note(
|
||||
array(
|
||||
'name' => 'expirenote',
|
||||
'value' => t('If the acknowledgement should expire, check the box and enter an expiration timestamp.')
|
||||
)
|
||||
);
|
||||
|
||||
$expireCheck = $this->createElement(
|
||||
'checkbox',
|
||||
'expire',
|
||||
array(
|
||||
'label' => t('Use expire time')
|
||||
)
|
||||
);
|
||||
|
||||
if ($this->getRequest()->getPost('expire', '0') === '1') {
|
||||
$now = DateTimeFactory::create();
|
||||
$expireTime = new DateTimePicker(
|
||||
$this->addElement(
|
||||
new Note(
|
||||
array(
|
||||
'name' => 'expiretime',
|
||||
'label' => t('Expire time'),
|
||||
'value' => $now->getTimestamp() + 3600
|
||||
'name' => 'persistentnote',
|
||||
'value' => t(
|
||||
'If you would like the comment to remain even when the acknowledgement is removed, '
|
||||
. 'check this option.'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElements(array($expireNote, $expireCheck, $expireTime));
|
||||
} else {
|
||||
$this->addElements(array($expireNote, $expireCheck));
|
||||
}
|
||||
|
||||
$this->enableAutoSubmit(array('expire'));
|
||||
|
||||
$this->addDisplayGroup(
|
||||
array(
|
||||
'expirenote',
|
||||
'expire',
|
||||
'expiretime'
|
||||
),
|
||||
'expire_group',
|
||||
array(
|
||||
'legend' => t('Expire acknowledgement')
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'checkbox',
|
||||
'expire',
|
||||
array(
|
||||
'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.')
|
||||
)
|
||||
)
|
||||
);
|
||||
if ($this->getRequest()->getPost('expire', '0') === '1') {
|
||||
$now = DateTimeFactory::create();
|
||||
$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 the expire date/time for this acknowledgement here. Icinga will '
|
||||
. ' delete the acknowledgement after this date expired.'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$this->addElement(
|
||||
'checkbox',
|
||||
'sticky',
|
||||
array(
|
||||
'label' => t('Sticky acknowledgement'),
|
||||
'value' => false
|
||||
'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.'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -130,12 +165,23 @@ class AcknowledgeForm extends CommandForm
|
|||
'checkbox',
|
||||
'notify',
|
||||
array(
|
||||
'label' => t('Send notification'),
|
||||
'value' => false
|
||||
'label' => t('Send Notification'),
|
||||
'value' => true
|
||||
)
|
||||
);
|
||||
$this->addElement(
|
||||
new Note(
|
||||
array(
|
||||
'name' => 'sendnotificationnote',
|
||||
'value' => t(
|
||||
'If you do not want an acknowledgement notification to be sent out to the appropriate '
|
||||
. 'contacts, uncheck this option.'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->setSubmitLabel(t('Acknowledge problem'));
|
||||
$this->setSubmitLabel(t('Acknowledge Problem'));
|
||||
|
||||
parent::create();
|
||||
}
|
||||
|
@ -143,7 +189,8 @@ class AcknowledgeForm extends CommandForm
|
|||
/**
|
||||
* Add validator for dependent fields
|
||||
*
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
*
|
||||
* @see \Icinga\Web\Form::preValidation()
|
||||
*/
|
||||
protected function preValidation(array $data)
|
||||
|
@ -154,6 +201,11 @@ class AcknowledgeForm extends CommandForm
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create acknowledgement from request data
|
||||
*
|
||||
* @return \Icinga\Protocol\Commandpipe\Acknowledgement
|
||||
*/
|
||||
public function getAcknowledgement()
|
||||
{
|
||||
$expireTime = -1;
|
||||
|
@ -170,6 +222,5 @@ class AcknowledgeForm extends CommandForm
|
|||
$expireTime,
|
||||
$this->getValue('sticky')
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,19 +38,9 @@ use \Zend_Validate_Date;
|
|||
*/
|
||||
class CommandForm extends Form
|
||||
{
|
||||
/**
|
||||
* Default date format
|
||||
*/
|
||||
const DEFAULT_DATE_FORMAT = 'Y-m-d H:i:s';
|
||||
|
||||
/**
|
||||
* Default format for validation
|
||||
*/
|
||||
const DEFAULT_DATE_VALIDATION = 'yyyy-MM-dd hh:ii:ss';
|
||||
|
||||
/**
|
||||
* Array of messages
|
||||
*
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
private $notes = array();
|
||||
|
@ -142,7 +132,7 @@ class CommandForm extends Form
|
|||
$authorField = new Zend_Form_Element_Hidden(
|
||||
array(
|
||||
'name' => 'author',
|
||||
'label' => t('Author name'),
|
||||
'label' => t('Author (Your Name)'),
|
||||
'value' => $authorName,
|
||||
'required' => true
|
||||
)
|
||||
|
@ -159,34 +149,4 @@ class CommandForm extends Form
|
|||
|
||||
return $authorField;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for date format
|
||||
* TODO(mh): Should be user preferences
|
||||
* @return string
|
||||
*/
|
||||
protected function getDateFormat()
|
||||
{
|
||||
return self::DEFAULT_DATE_FORMAT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for date validation format
|
||||
* @return string
|
||||
*/
|
||||
protected function getDateValidationFormat()
|
||||
{
|
||||
return self::DEFAULT_DATE_VALIDATION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new date validator
|
||||
* @return Zend_Validate_Date
|
||||
*/
|
||||
protected function createDateTimeValidator()
|
||||
{
|
||||
$validator = new Zend_Validate_Date();
|
||||
$validator->setFormat($this->getDateValidationFormat());
|
||||
return $validator;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ class CommandWithIdentifierForm extends CommandForm
|
|||
{
|
||||
/**
|
||||
* Identifier for data field
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $fieldName = 'objectid';
|
||||
|
@ -52,6 +53,7 @@ class CommandWithIdentifierForm extends CommandForm
|
|||
|
||||
/**
|
||||
* Setter for field label
|
||||
*
|
||||
* @param string $fieldLabel
|
||||
*/
|
||||
public function setFieldLabel($fieldLabel)
|
||||
|
@ -61,6 +63,7 @@ class CommandWithIdentifierForm extends CommandForm
|
|||
|
||||
/**
|
||||
* Getter for field label
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFieldLabel()
|
||||
|
@ -70,6 +73,7 @@ class CommandWithIdentifierForm extends CommandForm
|
|||
|
||||
/**
|
||||
* Setter for field name
|
||||
*
|
||||
* @param string $fieldName
|
||||
*/
|
||||
public function setFieldName($fieldName)
|
||||
|
@ -79,6 +83,7 @@ class CommandWithIdentifierForm extends CommandForm
|
|||
|
||||
/**
|
||||
* Getter for field name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFieldName()
|
||||
|
|
|
@ -28,18 +28,28 @@
|
|||
|
||||
namespace Monitoring\Form\Command;
|
||||
|
||||
use Icinga\Protocol\Commandpipe\Comment;
|
||||
use \Icinga\Web\Form\Element\Note;
|
||||
use \Icinga\Protocol\Commandpipe\Comment;
|
||||
|
||||
/**
|
||||
* Form for adding comment commands
|
||||
*/
|
||||
class CommentForm extends CommandForm
|
||||
{
|
||||
/**
|
||||
* Interface method to build the form
|
||||
* @see CommandForm::create
|
||||
* Create the form's elements
|
||||
*/
|
||||
protected function create()
|
||||
{
|
||||
$this->addElement(
|
||||
new Note(
|
||||
array(
|
||||
'name' => 'commanddescription',
|
||||
'value' => t('This command is used to add a comment to hosts or services.')
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement($this->createAuthorField());
|
||||
|
||||
$this->addElement(
|
||||
|
@ -51,13 +61,36 @@ class CommentForm extends CommandForm
|
|||
'required' => true
|
||||
)
|
||||
);
|
||||
$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.'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'checkbox',
|
||||
'persistent',
|
||||
array(
|
||||
'label' => t('Persistent'),
|
||||
'value' => false
|
||||
'value' => true
|
||||
)
|
||||
);
|
||||
$this->addElement(
|
||||
new Note(
|
||||
array(
|
||||
'name' => 'persistentnote',
|
||||
'value' => t(
|
||||
'If you uncheck this option, the comment will automatically be deleted the next time '
|
||||
. 'Icinga is restarted.'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -66,6 +99,11 @@ class CommentForm extends CommandForm
|
|||
parent::create();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create comment from request data
|
||||
*
|
||||
* @return \Icinga\Protocol\Commandpipe\Comment
|
||||
*/
|
||||
public function getComment()
|
||||
{
|
||||
return new Comment($this->getAuthorName(), $this->getValue('comment'), $this->getValue('persistent'));
|
||||
|
|
|
@ -28,7 +28,8 @@
|
|||
|
||||
namespace Monitoring\Form\Command;
|
||||
|
||||
use Zend_Form_Element_Hidden;
|
||||
use \Icinga\Web\Form\Element\Note;
|
||||
use \Icinga\Protocol\Commandpipe\CustomNotification;
|
||||
|
||||
/**
|
||||
* For for command CustomNotification
|
||||
|
@ -36,11 +37,23 @@ use Zend_Form_Element_Hidden;
|
|||
class CustomNotificationForm extends CommandForm
|
||||
{
|
||||
/**
|
||||
* Interface method to build the form
|
||||
* @see CommandForm::create
|
||||
* Create the form's elements
|
||||
*/
|
||||
protected function create()
|
||||
{
|
||||
$this->addElement(
|
||||
new Note(
|
||||
array(
|
||||
'name' => 'commanddescription',
|
||||
'value' => t(
|
||||
'This command is used to send a custom notification about hosts or services. Useful in '
|
||||
. 'emergencies when you need to notify admins of an issue regarding a monitored system or '
|
||||
. 'service.'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement($this->createAuthorField());
|
||||
|
||||
$this->addElement(
|
||||
|
@ -52,14 +65,38 @@ class CustomNotificationForm extends CommandForm
|
|||
'required' => true
|
||||
)
|
||||
);
|
||||
$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.'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'checkbox',
|
||||
'force',
|
||||
'forced',
|
||||
array(
|
||||
'label' => t('Forced')
|
||||
)
|
||||
);
|
||||
$this->addElement(
|
||||
new Note(
|
||||
array(
|
||||
'name' => 'forcenote',
|
||||
'value' => t(
|
||||
'Custom notifications normally follow the regular notification logic in Icinga. Selecting this '
|
||||
. 'option will force the notification to be sent out, regardless of time restrictions, '
|
||||
. 'whether or not notifications are enabled, etc.'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'checkbox',
|
||||
|
@ -68,26 +105,36 @@ class CustomNotificationForm extends CommandForm
|
|||
'label' => t('Broadcast')
|
||||
)
|
||||
);
|
||||
$this->addElement(
|
||||
new Note(
|
||||
array(
|
||||
'name' => 'broadcastnote',
|
||||
'value' => t(
|
||||
'Selecting this option causes the notification to be sent out to all normal (non-escalated) '
|
||||
. ' and escalated contacts. These options allow you to override the normal notification logic '
|
||||
. 'if you need to get an important message out.'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->setSubmitLabel(t('Send custom notification'));
|
||||
$this->setSubmitLabel(t('Send Custom Notification'));
|
||||
|
||||
parent::create();
|
||||
}
|
||||
|
||||
public function getComment()
|
||||
/**
|
||||
* Create Custom Notification from request data
|
||||
*
|
||||
* @return \Icinga\Protocol\Commandpipe\CustomNotification
|
||||
*/
|
||||
public function getCustomNotification()
|
||||
{
|
||||
return $this->getValue('comment');
|
||||
}
|
||||
|
||||
public function getOptions()
|
||||
{
|
||||
$value = 0;
|
||||
if ($this->getValue('force')) {
|
||||
$value |= 2;
|
||||
}
|
||||
if ($this->getValue('broadcast')) {
|
||||
$value |= 1;
|
||||
}
|
||||
return $value;
|
||||
return new CustomNotification(
|
||||
$this->getAuthorName(),
|
||||
$this->getValue('comment'),
|
||||
$this->getValue('forced'),
|
||||
$this->getValue('broadcast')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
|
||||
namespace Monitoring\Form\Command;
|
||||
|
||||
use \Icinga\Web\Form\Element\Note;
|
||||
|
||||
/**
|
||||
* Form for the delay notification command
|
||||
*/
|
||||
|
@ -40,11 +42,17 @@ class DelayNotificationForm extends CommandForm
|
|||
|
||||
/**
|
||||
* Create the form's elements
|
||||
*
|
||||
* @see CommandForm::create()
|
||||
*/
|
||||
protected function create()
|
||||
{
|
||||
$this->addElement(
|
||||
new Note(
|
||||
array(
|
||||
'name' => 'commanddescription',
|
||||
'value' => t('This command is used to delay the next problem notification that is sent out.')
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->addElement(
|
||||
'text',
|
||||
'minutes',
|
||||
|
@ -65,12 +73,10 @@ class DelayNotificationForm extends CommandForm
|
|||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->addNote(
|
||||
t(
|
||||
'Delay the next problem notification. The notification delay will be '
|
||||
. 'disregarded if the host/service changes state before the next notification is '
|
||||
. 'scheduled to be sent out.'
|
||||
'The notification delay will be disregarded if the host/service changes state before the next '
|
||||
. 'notification is scheduled to be sent out.'
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -79,8 +85,13 @@ class DelayNotificationForm extends CommandForm
|
|||
parent::create();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the currently set delay time in seconds
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getDelayTime()
|
||||
{
|
||||
return $this->getValue('minutes')*60;
|
||||
return $this->getValue('minutes') * 60;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,13 +28,13 @@
|
|||
|
||||
namespace Monitoring\Form\Command;
|
||||
|
||||
use \DateTime;
|
||||
use \Zend_Form_Element_Checkbox;
|
||||
use \Icinga\Web\Form\Element\DateTimePicker;
|
||||
use \Icinga\Util\DateTimeFactory;
|
||||
use \Icinga\Web\Form\Element\Note;
|
||||
|
||||
/**
|
||||
* Form for RescheduleNextCheck
|
||||
* Form for scheduling checks
|
||||
*/
|
||||
class RescheduleNextCheckForm extends WithChildrenCommandForm
|
||||
{
|
||||
|
@ -43,37 +43,76 @@ class RescheduleNextCheckForm extends WithChildrenCommandForm
|
|||
*/
|
||||
protected function create()
|
||||
{
|
||||
$now = DateTimeFactory::create();
|
||||
$dateElement = new DateTimePicker(
|
||||
array(
|
||||
'name' => 'checktime',
|
||||
'label' => t('Check time'),
|
||||
'value' => $now->getTimestamp()
|
||||
)
|
||||
);
|
||||
$this->addElement($dateElement);
|
||||
|
||||
$checkBox = new Zend_Form_Element_Checkbox(
|
||||
array(
|
||||
'name' => 'forcecheck',
|
||||
'label' => t('Force check'),
|
||||
'value' => true
|
||||
$this->addElement(
|
||||
new Note(
|
||||
array(
|
||||
'name' => 'commanddescription',
|
||||
'value' => t(
|
||||
'This command is used to schedule the next check of hosts/services. Icinga will re-queue the '
|
||||
. 'check at the time you specify.'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement($checkBox);
|
||||
$this->addElement(
|
||||
new DateTimePicker(
|
||||
array(
|
||||
'name' => 'checktime',
|
||||
'label' => t('Check Time'),
|
||||
'value' => DateTimeFactory::create()->getTimestamp(),
|
||||
'required' => !$this->getRequest()->getPost('forcecheck')
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->addElement(
|
||||
new Note(
|
||||
array(
|
||||
'name' => 'checktimenote',
|
||||
'value' => t('Set the date/time when this check should be executed.')
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
new Zend_Form_Element_Checkbox(
|
||||
array(
|
||||
'name' => 'forcecheck',
|
||||
'label' => t('Force Check'),
|
||||
'value' => true
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->addElement(
|
||||
new Note(
|
||||
array(
|
||||
'name' => 'forcechecknote',
|
||||
'value' => t(
|
||||
'If you select this option, Icinga will force a check regardless of both what time the '
|
||||
. 'scheduled check occurs and whether or not checks are enabled.'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// TODO: As of the time of writing it's possible to set hosts AND services as affected by this command but
|
||||
// with children only makes sense on hosts
|
||||
if ($this->getWithChildren() === true) {
|
||||
$this->addNote(t('Reschedule next check for this host and its services.'));
|
||||
$this->addNote(t('TODO: Help message when with children is enabled'));
|
||||
} else {
|
||||
$this->addNote(t('Reschedule next check for this object.'));
|
||||
$this->addNote(t('TODO: Help message when with children is disabled'));
|
||||
}
|
||||
|
||||
$this->setSubmitLabel(t('Reschedule check'));
|
||||
$this->setSubmitLabel(t('Reschedule Check'));
|
||||
|
||||
parent::create();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether this is a forced check (force is checked)
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isForced()
|
||||
{
|
||||
return $this->getValue('forcecheck') == true;
|
||||
|
|
|
@ -31,13 +31,14 @@ namespace Monitoring\Form\Command;
|
|||
use \Zend_Form_Element_Text;
|
||||
use \Zend_Validate_GreaterThan;
|
||||
use \Zend_Validate_Digits;
|
||||
use Icinga\Web\Form\Element\DateTimePicker;
|
||||
use Icinga\Protocol\Commandpipe\Downtime;
|
||||
use Icinga\Protocol\Commandpipe\Comment;
|
||||
use Icinga\Util\DateTimeFactory;
|
||||
use \Icinga\Web\Form\Element\DateTimePicker;
|
||||
use \Icinga\Protocol\Commandpipe\Downtime;
|
||||
use \Icinga\Protocol\Commandpipe\Comment;
|
||||
use \Icinga\Util\DateTimeFactory;
|
||||
use \Icinga\Web\Form\Element\Note;
|
||||
|
||||
/**
|
||||
* Form for any ScheduleDowntime command
|
||||
* Form for scheduling downtimes
|
||||
*/
|
||||
class ScheduleDowntimeForm extends WithChildrenCommandForm
|
||||
{
|
||||
|
@ -73,12 +74,24 @@ class ScheduleDowntimeForm extends WithChildrenCommandForm
|
|||
}
|
||||
|
||||
/**
|
||||
* Interface method to build the form
|
||||
*
|
||||
* @see CommandForm::create
|
||||
* Create the form's elements
|
||||
*/
|
||||
protected function create()
|
||||
{
|
||||
$this->addElement(
|
||||
new Note(
|
||||
array(
|
||||
'name' => 'commanddescription',
|
||||
'value' => t(
|
||||
'This command is used to schedule downtime for hosts/services. During the specified downtime, '
|
||||
. 'Icinga will not send notifications out about the affected objects. When the scheduled '
|
||||
. 'downtime expires, Icinga will send out notifications as it normally would. Scheduled '
|
||||
. 'downtimes are preserved across program shutdowns and restarts.'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement($this->createAuthorField());
|
||||
|
||||
$this->addElement(
|
||||
|
@ -90,6 +103,18 @@ class ScheduleDowntimeForm extends WithChildrenCommandForm
|
|||
'required' => true
|
||||
)
|
||||
);
|
||||
$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.'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* @TODO: Display downtime list (Bug #4496)
|
||||
|
@ -119,30 +144,49 @@ class ScheduleDowntimeForm extends WithChildrenCommandForm
|
|||
);
|
||||
|
||||
$now = DateTimeFactory::create();
|
||||
$dateTimeStart = new DateTimePicker(
|
||||
array(
|
||||
'name' => 'starttime',
|
||||
'label' => t('Start time'),
|
||||
'value' => $now->getTimestamp()
|
||||
$this->addElement(
|
||||
new DateTimePicker(
|
||||
array(
|
||||
'name' => 'starttime',
|
||||
'label' => t('Start Time'),
|
||||
'value' => $now->getTimestamp()
|
||||
)
|
||||
)
|
||||
);
|
||||
$dateTimeEnd = new DateTimePicker(
|
||||
array(
|
||||
'name' => 'endtime',
|
||||
'label' => t('End time'),
|
||||
'value' => $now->getTimestamp() + 3600
|
||||
$this->addElement(
|
||||
new Note(
|
||||
array(
|
||||
'name' => 'stattimenote',
|
||||
'value' => t('Set the start date/time for the downtime.')
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->addElement(
|
||||
new DateTimePicker(
|
||||
array(
|
||||
'name' => 'endtime',
|
||||
'label' => t('End Time'),
|
||||
'value' => $now->getTimestamp() + 3600
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->addElement(
|
||||
new Note(
|
||||
array(
|
||||
'name' => 'endtimenote',
|
||||
'value' => t('Set the end date/time for the downtime.')
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->addElements(array($dateTimeStart, $dateTimeEnd));
|
||||
|
||||
$this->addElement(
|
||||
'select',
|
||||
'type',
|
||||
array(
|
||||
'label' => t('Downtime type'),
|
||||
'multiOptions' => $this->getDowntimeTypeOptions(),
|
||||
'required' => true,
|
||||
'validators' => array(
|
||||
'label' => t('Downtime Type'),
|
||||
'multiOptions' => $this->getDowntimeTypeOptions(),
|
||||
'required' => true,
|
||||
'validators' => array(
|
||||
array(
|
||||
'InArray',
|
||||
true,
|
||||
|
@ -153,12 +197,25 @@ class ScheduleDowntimeForm extends WithChildrenCommandForm
|
|||
)
|
||||
)
|
||||
);
|
||||
$this->addElement(
|
||||
new Note(
|
||||
array(
|
||||
'name' => 'typenote',
|
||||
'value' => t(
|
||||
'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 service enters a non-OK state '
|
||||
. '(sometime between the start and end times you specified) and lasts as long as the duration '
|
||||
. 'of time you enter. The duration fields do not apply for fixed downtime.'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->enableAutoSubmit(array('type'));
|
||||
|
||||
|
||||
if ($this->getRequest()->getPost('type') === self::TYPE_FLEXIBLE) {
|
||||
$hoursText = new Zend_Form_Element_Text('hours');
|
||||
$hoursText->setLabel(t('Flexible duration'));
|
||||
$hoursText->setLabel(t('Flexible Duration'));
|
||||
$hoursText->setAttrib('style', 'width: 40px;');
|
||||
$hoursText->setValue(1);
|
||||
$hoursText->addDecorator('HtmlTag', array('tag' => 'dd', 'openOnly' => true));
|
||||
|
@ -170,7 +227,6 @@ class ScheduleDowntimeForm extends WithChildrenCommandForm
|
|||
}
|
||||
)
|
||||
);
|
||||
|
||||
$minutesText = new Zend_Form_Element_Text('minutes');
|
||||
$minutesText->setLabel(t('Minutes'));
|
||||
$minutesText->setAttrib('style', 'width: 40px;');
|
||||
|
@ -185,19 +241,30 @@ class ScheduleDowntimeForm extends WithChildrenCommandForm
|
|||
}
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElements(array($hoursText, $minutesText));
|
||||
$this->addElement(
|
||||
new Note(
|
||||
array(
|
||||
'name' => 'flexiblenote',
|
||||
'value' => t(
|
||||
'Enter here the duration of the downtime. Icinga will automatically delete the downtime '
|
||||
. 'after this time expired.'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: As of the time of writing it's possible to set hosts AND services as affected by this command but
|
||||
// with children only makes sense on hosts
|
||||
if ($this->getWithChildren() === true) {
|
||||
$this->addNote(t('Schedule downtime for host and its services.'));
|
||||
$this->addNote(t('TODO: Help message when with children is enabled'));
|
||||
} else {
|
||||
|
||||
$this->addElement(
|
||||
'select',
|
||||
'childobjects',
|
||||
array(
|
||||
'label' => t('Child objects'),
|
||||
'label' => t('Child Objects'),
|
||||
'required' => true,
|
||||
'multiOptions' => array(
|
||||
0 => t('Do nothing with child objects'),
|
||||
|
@ -219,11 +286,10 @@ class ScheduleDowntimeForm extends WithChildrenCommandForm
|
|||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->addNote(t('Schedule downtime for this object.'));
|
||||
$this->addNote(t('TODO: Help message when with children is disabled'));
|
||||
}
|
||||
|
||||
$this->setSubmitLabel(t('Schedule downtime'));
|
||||
$this->setSubmitLabel(t('Schedule Downtime'));
|
||||
|
||||
parent::create();
|
||||
}
|
||||
|
@ -256,9 +322,9 @@ class ScheduleDowntimeForm extends WithChildrenCommandForm
|
|||
}
|
||||
|
||||
/**
|
||||
* Return the downtime submitted in this form
|
||||
* Create Downtime from request Data
|
||||
*
|
||||
* @return Downtime
|
||||
* @return \Icinga\Protocol\Commandpipe\Downtime
|
||||
*/
|
||||
public function getDowntime()
|
||||
{
|
||||
|
@ -269,7 +335,7 @@ class ScheduleDowntimeForm extends WithChildrenCommandForm
|
|||
);
|
||||
$duration = 0;
|
||||
if ($this->getValue('type') === self::TYPE_FLEXIBLE) {
|
||||
$duration = ($this->getValue('hours')*3600) + ($this->getValue('minutes')*60);
|
||||
$duration = ($this->getValue('hours') * 3600) + ($this->getValue('minutes') * 60);
|
||||
}
|
||||
$starttime = $this->getValue('starttime');
|
||||
$endtime = $this->getValue('endtime');
|
||||
|
@ -281,7 +347,7 @@ class ScheduleDowntimeForm extends WithChildrenCommandForm
|
|||
$duration,
|
||||
$this->getValue('triggered')
|
||||
);
|
||||
if (! $this->getWithChildren()) {
|
||||
if (!$this->getWithChildren()) {
|
||||
switch ($this->getValue('childobjects')) {
|
||||
case 1:
|
||||
$downtime->setType(Downtime::TYPE_WITH_CHILDREN_TRIGGERED);
|
||||
|
|
|
@ -28,7 +28,8 @@
|
|||
|
||||
namespace Monitoring\Form\Command;
|
||||
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
use \Icinga\Exception\ProgrammingError;
|
||||
use \Icinga\Web\Form\Element\Note;
|
||||
|
||||
/**
|
||||
* Form for submitting passive check results
|
||||
|
@ -59,6 +60,7 @@ class SubmitPassiveCheckResultForm extends CommandForm
|
|||
|
||||
/**
|
||||
* Setup plugin states
|
||||
*
|
||||
* @see Zend_Form::init
|
||||
*/
|
||||
public function init()
|
||||
|
@ -85,6 +87,7 @@ class SubmitPassiveCheckResultForm extends CommandForm
|
|||
|
||||
/**
|
||||
* Setter for type
|
||||
*
|
||||
* @param string $type
|
||||
*/
|
||||
public function setType($type)
|
||||
|
@ -94,6 +97,7 @@ class SubmitPassiveCheckResultForm extends CommandForm
|
|||
|
||||
/**
|
||||
* Getter for type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
|
@ -103,6 +107,7 @@ class SubmitPassiveCheckResultForm extends CommandForm
|
|||
|
||||
/**
|
||||
* Return array of options
|
||||
*
|
||||
* @return array
|
||||
* @throws \Icinga\Exception\ProgrammingError
|
||||
*/
|
||||
|
@ -117,20 +122,30 @@ class SubmitPassiveCheckResultForm extends CommandForm
|
|||
|
||||
/**
|
||||
* Create the form's elements
|
||||
*
|
||||
* @see CommandForm::create()
|
||||
*/
|
||||
protected function create()
|
||||
{
|
||||
$this->addElement(
|
||||
new Note(
|
||||
array(
|
||||
'name' => 'commanddescription',
|
||||
'value' => t(
|
||||
'This command is used to submit a passive check result for particular hosts/services. It is '
|
||||
. 'particularly useful for resetting security-related objects to OK states once they have been '
|
||||
. 'dealt with.'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'select',
|
||||
'pluginstate',
|
||||
array(
|
||||
'label' => t('Plugin state'),
|
||||
'multiOptions' => $this->getOptions(),
|
||||
'required' => true,
|
||||
'validators' => array(
|
||||
'label' => t('Check Result'),
|
||||
'multiOptions' => $this->getOptions(),
|
||||
'required' => true,
|
||||
'validators' => array(
|
||||
array(
|
||||
'Digits',
|
||||
true
|
||||
|
@ -145,14 +160,30 @@ class SubmitPassiveCheckResultForm extends CommandForm
|
|||
)
|
||||
)
|
||||
);
|
||||
$this->addElement(
|
||||
new Note(
|
||||
array(
|
||||
'name' => 'checkresultnote',
|
||||
'value' => t('Set the state which should be send to Icinga for this objects.')
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'textarea',
|
||||
'checkoutput',
|
||||
array(
|
||||
'label' => t('Check output'),
|
||||
'rows' => 2,
|
||||
'required' => true
|
||||
'label' => t('Check Output'),
|
||||
'rows' => 2,
|
||||
'required' => true
|
||||
)
|
||||
);
|
||||
$this->addElement(
|
||||
new Note(
|
||||
array(
|
||||
'name' => 'checkoutputnote',
|
||||
'value' => t('Fill in the check output string which should be send to Icinga.')
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -160,26 +191,49 @@ class SubmitPassiveCheckResultForm extends CommandForm
|
|||
'textarea',
|
||||
'performancedata',
|
||||
array(
|
||||
'label' => t('Performance data'),
|
||||
'label' => t('Performance Data'),
|
||||
'rows' => 2
|
||||
)
|
||||
);
|
||||
$this->addElement(
|
||||
new Note(
|
||||
array(
|
||||
'name' => 'performancedatanote',
|
||||
'value' => t('Fill in the performance data string which should be send to Icinga.')
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->setSubmitLabel(t('Submit passive check result'));
|
||||
$this->setSubmitLabel(t('Submit Passive Check Result'));
|
||||
|
||||
parent::create();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the entered object state as an integer
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getState()
|
||||
{
|
||||
return intval($this->getValue('pluginstate'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the entered check output as a string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getOutput()
|
||||
{
|
||||
return $this->getValue('checkoutput');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the entered performance data as a string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPerformancedata()
|
||||
{
|
||||
return $this->getValue('performancedata');
|
||||
|
|
|
@ -1,24 +1,22 @@
|
|||
<?php
|
||||
// @codingStandardsIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Test\Monitoring\Forms\Command;
|
||||
|
||||
require_once __DIR__.'/BaseFormTest.php';
|
||||
$base = __DIR__.'/../../../../../../../';
|
||||
require_once $base.'modules/monitoring/application/forms/Command/CommandForm.php';
|
||||
require_once $base . 'library/Icinga/Util/ConfigAwareFactory.php';
|
||||
require_once $base . 'library/Icinga/Util/DateTimeFactory.php';
|
||||
require_once realpath($base.'modules/monitoring/application/forms/Command/WithChildrenCommandForm.php');
|
||||
require_once realpath($base.'modules/monitoring/application/forms/Command/AcknowledgeForm.php');
|
||||
require_once realpath(__DIR__ . '/BaseFormTest.php');
|
||||
require_once realpath(__DIR__ . '/../../../../../../../modules/monitoring/application/forms/Command/AcknowledgeForm.php');
|
||||
require_once realpath(__DIR__ . '/../../../../../../../library/Icinga/Util/ConfigAwareFactory.php');
|
||||
require_once realpath(__DIR__ . '/../../../../../../../library/Icinga/Util/DateTimeFactory.php');
|
||||
|
||||
use \DateTimeZone;
|
||||
use \Zend_View;
|
||||
use \Zend_Test_PHPUnit_ControllerTestCase;
|
||||
use Monitoring\Form\Command\AcknowledgeForm;
|
||||
use Icinga\Util\DateTimeFactory;
|
||||
use \Monitoring\Form\Command\AcknowledgeForm; // Used by constant FORMCLASS
|
||||
use \Icinga\Util\DateTimeFactory;
|
||||
|
||||
class AcknowledgeFormTest extends BaseFormTest
|
||||
{
|
||||
const FORMCLASS = "Monitoring\Form\Command\AcknowledgeForm";
|
||||
const FORMCLASS = 'Monitoring\Form\Command\AcknowledgeForm';
|
||||
|
||||
/**
|
||||
* Set up the default time zone
|
||||
|
@ -33,105 +31,93 @@ class AcknowledgeFormTest extends BaseFormTest
|
|||
DateTimeFactory::setConfig(array('timezone' => new DateTimeZone('UTC')));
|
||||
}
|
||||
|
||||
public function testForm()
|
||||
{
|
||||
$formWithoutExpiration = $this->getRequestForm(array(), self::FORMCLASS);
|
||||
$formWithoutExpiration->buildForm();
|
||||
$formWithExpiration = $this->getRequestForm(array(
|
||||
'expire' => '1'
|
||||
), self::FORMCLASS);
|
||||
$formWithExpiration->buildForm();
|
||||
|
||||
$this->assertCount(10, $formWithoutExpiration->getElements());
|
||||
$this->assertCount(11, $formWithExpiration->getElements());
|
||||
}
|
||||
|
||||
public function testValidateCorrectForm()
|
||||
public function testFormValid()
|
||||
{
|
||||
$form = $this->getRequestForm(array(
|
||||
'author' => 'test1',
|
||||
'comment' => 'test comment',
|
||||
'persistent' => '0',
|
||||
'expire' => '0',
|
||||
'sticky' => '0',
|
||||
'notify' => '0',
|
||||
'btn_submit' => 'foo'
|
||||
'author' => 'Author',
|
||||
'comment' => 'Comment',
|
||||
'persistent' => '0',
|
||||
'expire' => '0',
|
||||
'sticky' => '0',
|
||||
'notify' => '0',
|
||||
'btn_submit' => 'Submit'
|
||||
), self::FORMCLASS);
|
||||
|
||||
$this->assertTrue(
|
||||
$form->isSubmittedAndValid(),
|
||||
"Asserting a correct form to be validated correctly"
|
||||
'Legal request data without expire time must be considered valid'
|
||||
);
|
||||
}
|
||||
|
||||
public function testDetectMissingAcknowledgementComment()
|
||||
{
|
||||
$form = $this->getRequestForm(array(
|
||||
'author' => 'test1',
|
||||
'comment' => '',
|
||||
'persistent' => '0',
|
||||
'expire' => '0',
|
||||
'sticky' => '0',
|
||||
'notify' => '0',
|
||||
'btn_submit' => 'foo'
|
||||
$formWithExpireTime = $this->getRequestForm(array(
|
||||
'author' => 'Author',
|
||||
'comment' => 'Comment',
|
||||
'persistent' => '0',
|
||||
'expire' => '1',
|
||||
'expiretime' => '2013-07-10 17:32:16',
|
||||
'sticky' => '0',
|
||||
'notify' => '0',
|
||||
'btn_submit' => 'Submit'
|
||||
), self::FORMCLASS);
|
||||
$this->assertFalse(
|
||||
$form->isSubmittedAndValid(),
|
||||
"Asserting a missing comment text to cause validation errors"
|
||||
);
|
||||
}
|
||||
|
||||
public function testValidateMissingExpireTime()
|
||||
{
|
||||
$form = $this->getRequestForm(array(
|
||||
'author' => 'test1',
|
||||
'comment' => 'test comment',
|
||||
'persistent' => '0',
|
||||
'expire' => '1',
|
||||
'expiretime' => '',
|
||||
'sticky' => '0',
|
||||
'notify' => '0',
|
||||
'btn_submit' => 'foo'
|
||||
), self::FORMCLASS);
|
||||
$this->assertFalse(
|
||||
$form->isSubmittedAndValid(),
|
||||
"Asserting a missing expire time to cause validation errors when expire is 1"
|
||||
);
|
||||
}
|
||||
|
||||
public function testValidateIncorrectExpireTime()
|
||||
{
|
||||
$form = $this->getRequestForm(array(
|
||||
'author' => 'test1',
|
||||
'comment' => 'test comment',
|
||||
'persistent' => '0',
|
||||
'expire' => '1',
|
||||
'expiretime' => 'NOT A DATE',
|
||||
'sticky' => '0',
|
||||
'notify' => '0',
|
||||
'btn_submit' => 'foo'
|
||||
), self::FORMCLASS);
|
||||
$this->assertFalse(
|
||||
$form->isSubmittedAndValid(),
|
||||
"Assert incorrect dates to be recognized when validating expiretime"
|
||||
);
|
||||
}
|
||||
|
||||
public function testValidateCorrectAcknowledgementWithExpireTime()
|
||||
{
|
||||
$form = $this->getRequestForm(array(
|
||||
'author' => 'test1',
|
||||
'comment' => 'test comment',
|
||||
'persistent' => '0',
|
||||
'expire' => '1',
|
||||
'expiretime' => '2013-07-10 17:32:16',
|
||||
'sticky' => '0',
|
||||
'notify' => '0',
|
||||
'btn_submit' => 'foo'
|
||||
), self::FORMCLASS);
|
||||
$this->assertTrue(
|
||||
$formWithExpireTime->isSubmittedAndValid(),
|
||||
'Legal request data with expire time must be considered valid'
|
||||
);
|
||||
}
|
||||
|
||||
public function testFormInvalidWhenCommentMissing()
|
||||
{
|
||||
$form = $this->getRequestForm(array(
|
||||
'author' => 'Author',
|
||||
'comment' => '',
|
||||
'persistent' => '0',
|
||||
'expire' => '0',
|
||||
'sticky' => '0',
|
||||
'notify' => '0',
|
||||
'btn_submit' => 'Submit'
|
||||
), self::FORMCLASS);
|
||||
|
||||
$this->assertFalse(
|
||||
$form->isSubmittedAndValid(),
|
||||
"Assert that correct expire time acknowledgement is considered valid"
|
||||
'Missing comment must be considered not valid'
|
||||
);
|
||||
}
|
||||
|
||||
public function testFormInvalidWhenExpireTimeMissingAndExpireSet()
|
||||
{
|
||||
$form = $this->getRequestForm(array(
|
||||
'author' => 'Author',
|
||||
'comment' => 'Comment',
|
||||
'persistent' => '0',
|
||||
'expire' => '1',
|
||||
'sticky' => '0',
|
||||
'notify' => '0',
|
||||
'btn_submit' => 'Submit'
|
||||
), self::FORMCLASS);
|
||||
|
||||
$this->assertFalse(
|
||||
$form->isSubmittedAndValid(),
|
||||
'If expire is set and expire time is missing, the form must not be valid'
|
||||
);
|
||||
}
|
||||
|
||||
public function testFormInvalidWhenExpireTimeIsIncorrectAndExpireSet()
|
||||
{
|
||||
$form = $this->getRequestForm(array(
|
||||
'author' => 'Author',
|
||||
'comment' => 'Comment',
|
||||
'persistent' => '0',
|
||||
'expire' => '1',
|
||||
'expiretime' => 'Not a date',
|
||||
'sticky' => '0',
|
||||
'notify' => '0',
|
||||
'btn_submit' => 'Submit'
|
||||
), self::FORMCLASS);
|
||||
|
||||
$this->assertFalse(
|
||||
$form->isSubmittedAndValid(),
|
||||
'If expire is set and expire time is incorrect, the form must not be valid'
|
||||
);
|
||||
}
|
||||
}
|
||||
// @codingStandardsIgnoreStop
|
||||
|
|
|
@ -30,6 +30,8 @@ namespace Test\Monitoring\Forms\Command {
|
|||
require_once realpath($base.'library/Icinga/Web/Form/InvalidCSRFTokenException.php');
|
||||
require_once realpath($base.'library/Icinga/Web/Form/Element/Note.php');
|
||||
require_once realpath($base.'library/Icinga/Web/Form/Element/DateTimePicker.php');
|
||||
require_once realpath($base . 'modules/monitoring/application/forms/Command/CommandForm.php');
|
||||
require_once realpath($base . 'modules/monitoring/application/forms/Command/WithChildrenCommandForm.php');
|
||||
|
||||
use \Zend_View;
|
||||
use \Zend_Form;
|
||||
|
|
|
@ -1,68 +1,63 @@
|
|||
<?php
|
||||
// @codingStandardsIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Test\Monitoring\Forms\Command;
|
||||
|
||||
require_once realpath(__DIR__ . '/BaseFormTest.php');
|
||||
require_once realpath(__DIR__ . '/../../../../../../../modules/monitoring/application/forms/Command/CommentForm.php');
|
||||
|
||||
require_once __DIR__.'/BaseFormTest.php';
|
||||
require_once __DIR__. '/../../../../../application/forms/Command/CommandForm.php';
|
||||
require_once __DIR__. '/../../../../../application/forms/Command/WithChildrenCommandForm.php';
|
||||
require_once __DIR__. '/../../../../../application/forms/Command/CommentForm.php';
|
||||
|
||||
use Monitoring\Form\Command\CommentForm;
|
||||
use \Zend_View;
|
||||
|
||||
use \Monitoring\Form\Command\CommentForm; // Used by constant FORMCLASS
|
||||
|
||||
class CommentFormTest extends BaseFormTest
|
||||
{
|
||||
const FORMCLASS = "Monitoring\Form\Command\CommentForm";
|
||||
public function testForm()
|
||||
{
|
||||
$form = new CommentForm();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->buildForm();
|
||||
|
||||
$this->assertCount(6, $form->getElements());
|
||||
}
|
||||
|
||||
const FORMCLASS = 'Monitoring\Form\Command\CommentForm';
|
||||
|
||||
public function testCorrectCommentValidation()
|
||||
{
|
||||
$form = $this->getRequestForm(array(
|
||||
'author' => 'test1',
|
||||
'comment' => 'test2',
|
||||
'sticky' => '0',
|
||||
'btn_submit' => 'foo'
|
||||
'author' => 'Author',
|
||||
'comment' => 'Comment',
|
||||
'sticky' => '0',
|
||||
'btn_submit' => 'Submit'
|
||||
), self::FORMCLASS);
|
||||
|
||||
$this->assertTrue(
|
||||
$form->isSubmittedAndValid(),
|
||||
"Asserting correct comment form to be considered valid"
|
||||
'Legal request data must be considered valid'
|
||||
);
|
||||
}
|
||||
|
||||
public function testRecognizeMissingCommentText()
|
||||
public function testFormInvalidWhenCommentMissing()
|
||||
{
|
||||
$form = $this->getRequestForm(array(
|
||||
'author' => 'test1',
|
||||
'comment' => '',
|
||||
'sticky' => '0'
|
||||
'author' => 'Author',
|
||||
'comment' => '',
|
||||
'sticky' => '0',
|
||||
'btn_submit' => 'Submit'
|
||||
|
||||
), self::FORMCLASS);
|
||||
|
||||
$this->assertFalse(
|
||||
$form->isSubmittedAndValid(),
|
||||
"Asserting missing comment text in comment form to cause validation errors"
|
||||
'Missing comment must be considered not valid'
|
||||
);
|
||||
}
|
||||
|
||||
public function testRecognizeMissingCommentAuthor()
|
||||
public function testFormInvalidWhenAuthorMissing()
|
||||
{
|
||||
$form = $this->getRequestForm(array(
|
||||
'author' => '',
|
||||
'comment' => 'test2',
|
||||
'sticky' => '0'
|
||||
'author' => '',
|
||||
'comment' => 'Comment',
|
||||
'sticky' => '0',
|
||||
'btn_submit' => 'Submit'
|
||||
), self::FORMCLASS);
|
||||
|
||||
$this->assertFalse(
|
||||
$form->isSubmittedAndValid(),
|
||||
"Asserting missing comment author to cause validation errors"
|
||||
'Missing author must be considered not valid'
|
||||
);
|
||||
}
|
||||
}
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
|
|
@ -1,28 +1,31 @@
|
|||
<?php
|
||||
// @codingStandardsIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Test\Monitoring\Forms\Command;
|
||||
|
||||
require_once __DIR__. '/BaseFormTest.php';
|
||||
require_once __DIR__. '/../../../../../application/forms/Command/CommandForm.php';
|
||||
require_once __DIR__. '/../../../../../application/forms/Command/CustomNotificationForm.php';
|
||||
require_once realpath(__DIR__ . '/BaseFormTest.php');
|
||||
require_once realpath(__DIR__ . '/../../../../../application/forms/Command/CustomNotificationForm.php');
|
||||
|
||||
|
||||
use Monitoring\Form\Command\CustomNotificationForm;
|
||||
use \Zend_View;
|
||||
use \Zend_Test_PHPUnit_ControllerTestCase;
|
||||
use \Monitoring\Form\Command\CustomNotificationForm; // Used by constant FORM_CLASS
|
||||
|
||||
class CustomNotificationFormTest extends BaseFormTest
|
||||
{
|
||||
public function testForm1()
|
||||
const FORM_CLASS = 'Monitoring\Form\Command\CustomNotificationForm';
|
||||
|
||||
public function testFormInvalidWhenCommentMissing()
|
||||
{
|
||||
$form = $this->getRequestForm(array(
|
||||
'comment' => 'TEST COMMENT',
|
||||
'author' => 'LAOLA',
|
||||
'btn_submit' => 'foo'
|
||||
), "Monitoring\Form\Command\CustomNotificationForm");
|
||||
$form->buildForm();
|
||||
'author' => 'Author',
|
||||
'comment' => '',
|
||||
'btn_submit' => 'Submit'
|
||||
), self::FORM_CLASS);
|
||||
|
||||
$this->assertCount(7, $form->getElements());
|
||||
$this->assertTrue($form->isSubmittedAndValid());
|
||||
$this->assertFalse(
|
||||
$form->isSubmittedAndValid(),
|
||||
'Missing comment must be considered not valid'
|
||||
);
|
||||
}
|
||||
}
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
|
|
@ -1,57 +1,56 @@
|
|||
<?php
|
||||
// @codingStandardsIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Test\Monitoring\Forms\Command;
|
||||
|
||||
require_once __DIR__. '/BaseFormTest.php';
|
||||
require_once __DIR__. '/../../../../../application/forms/Command/CommandForm.php';
|
||||
require_once __DIR__. '/../../../../../application/forms/Command/DelayNotificationForm.php';
|
||||
require_once realpath(__DIR__ . '/BaseFormTest.php');
|
||||
require_once realpath(__DIR__ . '/../../../../../application/forms/Command/DelayNotificationForm.php');
|
||||
|
||||
use \Monitoring\Form\Command\DelayNotificationForm; // Used by constant FORM_CLASS
|
||||
|
||||
use \Zend_View;
|
||||
use \Zend_Test_PHPUnit_ControllerTestCase;
|
||||
use Monitoring\Form\Command\DelayNotificationForm;
|
||||
|
||||
class DelayNotificationFormFormTest extends BaseFormTest
|
||||
class DelayNotificationFormTest extends BaseFormTest
|
||||
{
|
||||
public function testValidForm()
|
||||
const FORM_CLASS = 'Monitoring\Form\Command\DelayNotificationForm';
|
||||
|
||||
public function testFormInvalidWhenNotificationDelayMissing()
|
||||
{
|
||||
$form = $this->getRequestForm(array(
|
||||
'minutes' => 12,
|
||||
'btn_submit' => 'foo'
|
||||
), 'Monitoring\Form\Command\DelayNotificationForm');
|
||||
|
||||
$form->buildForm();
|
||||
$this->assertCount(5, $form->getElements());
|
||||
|
||||
$element = $form->getElement('minutes');
|
||||
$this->assertInstanceOf('Zend_Form_Element_Text', $element);
|
||||
$this->assertEquals('0', $element->getValue(), "Assert a correct default value in minutes");
|
||||
$this->assertTrue($element->isRequired(), "Assert minutes to be declared as required");
|
||||
|
||||
$this->assertTrue(
|
||||
$form->isSubmittedAndValid(),
|
||||
"Assert a correct DelayNotificationForm to be considered valid"
|
||||
);
|
||||
|
||||
$this->assertEquals('12', $form->getValue('minutes'), "Assert the minutes field to be correctly populated");
|
||||
}
|
||||
|
||||
public function testInvalidMinuteValue()
|
||||
{
|
||||
$form = $this->getRequestForm(array(
|
||||
'minutes' => 'SCHAHH-LAHH-LAHH',
|
||||
'btn_submit' => 'foo'
|
||||
), 'Monitoring\Form\Command\DelayNotificationForm');
|
||||
|
||||
$form->buildForm();
|
||||
'minutes' => '',
|
||||
'btn_submit' => 'Submit'
|
||||
), self::FORM_CLASS);
|
||||
|
||||
$this->assertFalse(
|
||||
$form->isSubmittedAndValid(),
|
||||
"Asserting invalid minutes (NaN) to cause validation errors"
|
||||
'Missing notification delay must be considered invalid'
|
||||
);
|
||||
}
|
||||
|
||||
$errors = $form->getErrors('minutes');
|
||||
$this->assertCount(1, $errors, "Asserting an error to be added when the minutes value is invalid");
|
||||
$this->assertEquals('notBetween', $errors[0], "Assert correct error message");
|
||||
public function testFormInvalidWhenNotificationDelayNaN()
|
||||
{
|
||||
$form = $this->getRequestForm(array(
|
||||
'minutes' => 'A String',
|
||||
'btn_submit' => 'Submit'
|
||||
), self::FORM_CLASS);
|
||||
|
||||
$this->assertFalse(
|
||||
$form->isSubmittedAndValid(),
|
||||
'Incorrect notification delay, i.e. NaN must be considered invalid'
|
||||
);
|
||||
}
|
||||
|
||||
public function testFormInvalidWhenNotificationDelayOverflows()
|
||||
{
|
||||
$form = $this->getRequestForm(array(
|
||||
'minutes' => DelayNotificationForm::MAX_DELAY + 1,
|
||||
'btn_submit' => 'Submit'
|
||||
), self::FORM_CLASS);
|
||||
|
||||
$this->assertFalse(
|
||||
$form->isSubmittedAndValid(),
|
||||
'Notification delay bigger than constant "DelayNotificationForm::MAX_DELAY" must be considered invalid'
|
||||
);
|
||||
}
|
||||
}
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
|
|
@ -1,102 +1,70 @@
|
|||
<?php
|
||||
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Test\Monitoring\Forms\Command;
|
||||
|
||||
require_once realpath(__DIR__ . '/BaseFormTest.php');
|
||||
require_once realpath(__DIR__ . '/../../../../../application/forms/Command/RescheduleNextCheckForm.php');
|
||||
require_once realpath(__DIR__ . '/../../../../../../../library/Icinga/Util/ConfigAwareFactory.php');
|
||||
require_once realpath(__DIR__ . '/../../../../../../../library/Icinga/Util/DateTimeFactory.php');
|
||||
|
||||
require_once __DIR__. '/BaseFormTest.php';
|
||||
require_once __DIR__. '/../../../../../application/forms/Command/CommandForm.php';
|
||||
require_once __DIR__. '/../../../../../application/forms/Command/WithChildrenCommandForm.php';
|
||||
require_once __DIR__. '/../../../../../application/forms/Command/RescheduleNextCheckForm.php';
|
||||
|
||||
|
||||
use Monitoring\Form\Command\RescheduleNextCheckForm;
|
||||
use \Zend_View;
|
||||
use \Zend_Test_PHPUnit_ControllerTestCase;
|
||||
use \Monitoring\Form\Command\RescheduleNextCheckForm; // Used by constant FORM_CLASS
|
||||
use \DateTimeZone;
|
||||
use \Icinga\Util\DateTimeFactory;
|
||||
|
||||
class RescheduleNextCheckFormTest extends BaseFormTest
|
||||
{
|
||||
const FORM_CLASS = 'Monitoring\Form\Command\RescheduleNextCheckForm';
|
||||
|
||||
const FORMCLASS = 'Monitoring\Form\Command\RescheduleNextCheckForm';
|
||||
|
||||
public function testValidRescheduleSubmissions()
|
||||
/**
|
||||
* Set up the default time zone
|
||||
*
|
||||
* Utilizes singleton DateTimeFactory
|
||||
*
|
||||
* @backupStaticAttributes enabled
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
|
||||
$form = $this->getRequestForm(array(
|
||||
'checktime' => '2013-10-19 17:30:00',
|
||||
'forcecheck' => 1,
|
||||
'btn_submit' => 'foo'
|
||||
), self::FORMCLASS);
|
||||
$form->buildForm();
|
||||
|
||||
$this->assertCount(6, $form->getElements());
|
||||
|
||||
$this->assertTrue(
|
||||
$form->isSubmittedAndValid(),
|
||||
'Asserting a reschedule form with correct time and forececheck=1 to be valid'
|
||||
);
|
||||
$form = $this->getRequestForm(array(
|
||||
'checktime' => '2013-10-19 17:30:00',
|
||||
'forcecheck' => 0,
|
||||
'btn_submit' => 'foo'
|
||||
), self::FORMCLASS);
|
||||
|
||||
$this->assertTrue(
|
||||
$form->isSubmittedAndValid(),
|
||||
'Asserting a reschedule form with correct time and forecheck=0 to be valid'
|
||||
);
|
||||
date_default_timezone_set('UTC');
|
||||
DateTimeFactory::setConfig(array('timezone' => new DateTimeZone('UTC')));
|
||||
}
|
||||
|
||||
public function testInValidRescheduleChecktimeSubmissions()
|
||||
public function testFormInvalidWhenChecktimeIsIncorrect()
|
||||
{
|
||||
$form = $this->getRequestForm(array(
|
||||
'checktime' => '2013-24-12 17:30:00',
|
||||
'forcecheck' => 1
|
||||
), self::FORMCLASS);
|
||||
'checktime' => '2013-24-12 17:30:00',
|
||||
'forcecheck' => 0,
|
||||
'btn_submit' => 'Submit'
|
||||
), self::FORM_CLASS);
|
||||
|
||||
$this->assertFalse(
|
||||
$form->isSubmittedAndValid(),
|
||||
'Asserting an logically invalid checktime to be considered as invalid reschedule data'
|
||||
'Asserting a logically incorrect checktime as invalid'
|
||||
);
|
||||
|
||||
$form = $this->getRequestForm(array(
|
||||
'checktime' => 'AHAHA',
|
||||
'forcecheck' => 1
|
||||
), self::FORMCLASS);
|
||||
|
||||
$form2 = $this->getRequestForm(array(
|
||||
'checktime' => 'Captain Morgan',
|
||||
'forcecheck' => 1,
|
||||
'btn_submit' => 'Submit'
|
||||
), self::FORM_CLASS);
|
||||
|
||||
$this->assertFalse(
|
||||
$form->isSubmittedAndValid(),
|
||||
'Asserting an invalid non-numeric checktime to be considered as invalid reschedule data'
|
||||
$form2->isSubmittedAndValid(),
|
||||
'Providing arbitrary strings as checktime must be considered invalid'
|
||||
);
|
||||
}
|
||||
|
||||
public function testChildrenFlag()
|
||||
{
|
||||
$form3 = $this->getRequestForm(array(
|
||||
'checktime' => '',
|
||||
'forcecheck' => 0,
|
||||
'btn_submit' => 'Submit'
|
||||
), self::FORM_CLASS);
|
||||
|
||||
$form = new RescheduleNextCheckForm();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->setWithChildren(true);
|
||||
$form->buildForm();
|
||||
$notes1 = $form->getNotes();
|
||||
$form = null;
|
||||
|
||||
$form = new RescheduleNextCheckForm();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->setWithChildren(false);
|
||||
$form->buildForm();
|
||||
$notes2 = $form->getNotes();
|
||||
$form = null;
|
||||
|
||||
$form = new RescheduleNextCheckForm();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->setWithChildren();
|
||||
$form->buildForm();
|
||||
$notes3 = $form->getNotes();
|
||||
$form = null;
|
||||
|
||||
$this->assertEquals($notes1, $notes3);
|
||||
$this->assertNotEquals($notes1, $notes2);
|
||||
$this->assertFalse(
|
||||
$form3->isSubmittedAndValid(),
|
||||
'Missing checktime must be considered invalid'
|
||||
);
|
||||
}
|
||||
}
|
||||
// @codingStandardsIgnoreStop
|
||||
|
|
|
@ -1,39 +1,50 @@
|
|||
<?php
|
||||
// @codingStandardsIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Test\Monitoring\Forms\Command;
|
||||
|
||||
require_once __DIR__. '/BaseFormTest.php';
|
||||
require_once __DIR__. '/../../../../../application/forms/Command/CommandForm.php';
|
||||
require_once __DIR__. '/../../../../../application/forms/Command/WithChildrenCommandForm.php';
|
||||
require_once __DIR__. '/../../../../../application/forms/Command/ScheduleDowntimeForm.php';
|
||||
require_once realpath(__DIR__ . '/BaseFormTest.php');
|
||||
require_once realpath(__DIR__ . '/../../../../../../../modules/monitoring/application/forms/Command/ScheduleDowntimeForm.php');
|
||||
require_once realpath(__DIR__ . '/../../../../../../../library/Icinga/Util/ConfigAwareFactory.php');
|
||||
require_once realpath(__DIR__ . '/../../../../../../../library/Icinga/Util/DateTimeFactory.php');
|
||||
|
||||
use Monitoring\Form\Command\ScheduleDowntimeForm;
|
||||
use \Zend_View;
|
||||
use \Zend_Test_PHPUnit_ControllerTestCase;
|
||||
use \Monitoring\Form\Command\ScheduleDowntimeForm; // Used by constant FORM_CLASS
|
||||
use \DateTimeZone;
|
||||
use \Icinga\Util\DateTimeFactory;
|
||||
|
||||
class ScheduleDowntimeFormTest extends BaseFormTest
|
||||
{
|
||||
const FORMCLASS = 'Monitoring\Form\Command\ScheduleDowntimeForm';
|
||||
const FORM_CLASS = 'Monitoring\Form\Command\ScheduleDowntimeForm';
|
||||
|
||||
/**
|
||||
* Set up the default time zone
|
||||
*
|
||||
* Utilizes singleton DateTimeFactory
|
||||
*
|
||||
* @backupStaticAttributes enabled
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
date_default_timezone_set('UTC');
|
||||
DateTimeFactory::setConfig(array('timezone' => new DateTimeZone('UTC')));
|
||||
}
|
||||
|
||||
public function testCorrectFormElementCreation()
|
||||
{
|
||||
$formFixed = $this->getRequestForm(array(), self::FORMCLASS);
|
||||
$formFixed = $this->getRequestForm(array(), self::FORM_CLASS);
|
||||
$formFixed->buildForm();
|
||||
$formFlexible = $this->getRequestForm(array(
|
||||
'type' => 'flexible'
|
||||
), self::FORMCLASS);
|
||||
), self::FORM_CLASS);
|
||||
$formFlexible->buildForm();
|
||||
|
||||
$this->assertCount(11, $formFixed->getElements());
|
||||
$this->assertCount(13, $formFlexible->getElements());
|
||||
|
||||
$form = $this->getRequestForm(array(), self::FORMCLASS);
|
||||
$form = $this->getRequestForm(array(), self::FORM_CLASS);
|
||||
$form->setWithChildren(true);
|
||||
$form->buildForm();
|
||||
|
||||
$this->assertCount(12, $form->getElements());
|
||||
}
|
||||
|
||||
|
||||
public function testCorrectValidationWithChildrend()
|
||||
{
|
||||
$form = $this->getRequestForm(array(
|
||||
|
@ -47,8 +58,7 @@ class ScheduleDowntimeFormTest extends BaseFormTest
|
|||
'minutes' => '',
|
||||
'btn_submit' => 'foo',
|
||||
// 'childobjects' => '',
|
||||
), self::FORMCLASS);
|
||||
|
||||
), self::FORM_CLASS);
|
||||
|
||||
$form->setWithChildren(true);
|
||||
|
||||
|
@ -67,14 +77,13 @@ class ScheduleDowntimeFormTest extends BaseFormTest
|
|||
'minutes' => '10',
|
||||
'btn_submit' => 'foo'
|
||||
// 'childobjects' => '',
|
||||
), self::FORMCLASS);
|
||||
), self::FORM_CLASS);
|
||||
$form->setWithChildren(true);
|
||||
|
||||
$this->assertTrue(
|
||||
$form->isSubmittedAndValid(),
|
||||
'Asserting a correct flexible downtime form to be considered valid'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public function testMissingFlexibleDurationRecognition()
|
||||
|
@ -89,7 +98,7 @@ class ScheduleDowntimeFormTest extends BaseFormTest
|
|||
'hours' => '',
|
||||
'minutes' => '',
|
||||
// 'childobjects' => '',
|
||||
), self::FORMCLASS);
|
||||
), self::FORM_CLASS);
|
||||
$form->setWithChildren(true);
|
||||
|
||||
$this->assertFalse(
|
||||
|
@ -100,7 +109,6 @@ class ScheduleDowntimeFormTest extends BaseFormTest
|
|||
|
||||
public function testMissingAuthorRecognition()
|
||||
{
|
||||
|
||||
$form = $this->getRequestForm(array(
|
||||
'author' => '',
|
||||
'comment' => 'DING DING',
|
||||
|
@ -111,7 +119,7 @@ class ScheduleDowntimeFormTest extends BaseFormTest
|
|||
'hours' => '',
|
||||
'minutes' => '',
|
||||
// 'childobjects' => '',
|
||||
), self::FORMCLASS);
|
||||
), self::FORM_CLASS);
|
||||
$form->setWithChildren(true);
|
||||
|
||||
|
||||
|
@ -133,7 +141,7 @@ class ScheduleDowntimeFormTest extends BaseFormTest
|
|||
'hours' => '',
|
||||
'minutes' => '',
|
||||
// 'childobjects' => '',
|
||||
), self::FORMCLASS);
|
||||
), self::FORM_CLASS);
|
||||
$form->setWithChildren(true);
|
||||
|
||||
|
||||
|
@ -155,7 +163,7 @@ class ScheduleDowntimeFormTest extends BaseFormTest
|
|||
'hours' => '',
|
||||
'minutes' => '',
|
||||
// 'childobjects' => '',
|
||||
), self::FORMCLASS);
|
||||
), self::FORM_CLASS);
|
||||
$form->setWithChildren(true);
|
||||
|
||||
$this->assertFalse(
|
||||
|
@ -176,7 +184,7 @@ class ScheduleDowntimeFormTest extends BaseFormTest
|
|||
'hours' => '',
|
||||
'minutes' => '',
|
||||
// 'childobjects' => '',
|
||||
), self::FORMCLASS);
|
||||
), self::FORM_CLASS);
|
||||
$form->setWithChildren(true);
|
||||
|
||||
$this->assertFalse(
|
||||
|
@ -187,7 +195,6 @@ class ScheduleDowntimeFormTest extends BaseFormTest
|
|||
|
||||
public function testInvalidEndTimeRecognition()
|
||||
{
|
||||
|
||||
$form = $this->getRequestForm(array(
|
||||
'author' => 'OK',
|
||||
'comment' => 'OK',
|
||||
|
@ -198,7 +205,7 @@ class ScheduleDowntimeFormTest extends BaseFormTest
|
|||
'hours' => '',
|
||||
'minutes' => '',
|
||||
// 'childobjects' => '',
|
||||
), self::FORMCLASS);
|
||||
), self::FORM_CLASS);
|
||||
$form->setWithChildren(true);
|
||||
|
||||
$this->assertFalse(
|
||||
|
@ -220,7 +227,7 @@ class ScheduleDowntimeFormTest extends BaseFormTest
|
|||
'hours' => '-1',
|
||||
'minutes' => '12',
|
||||
// 'childobjects' => '',
|
||||
), self::FORMCLASS);
|
||||
), self::FORM_CLASS);
|
||||
$form->setWithChildren(true);
|
||||
|
||||
$this->assertFalse(
|
||||
|
@ -241,7 +248,7 @@ class ScheduleDowntimeFormTest extends BaseFormTest
|
|||
'hours' => '12',
|
||||
'minutes' => 'DING',
|
||||
// 'childobjects' => '',
|
||||
), self::FORMCLASS);
|
||||
), self::FORM_CLASS);
|
||||
$form->setWithChildren(true);
|
||||
|
||||
$this->assertFalse(
|
||||
|
@ -264,13 +271,13 @@ class ScheduleDowntimeFormTest extends BaseFormTest
|
|||
'minutes' => '',
|
||||
'btn_submit' => 'foo',
|
||||
'childobjects' => '0',
|
||||
), self::FORMCLASS);
|
||||
), self::FORM_CLASS);
|
||||
$form->setWithChildren(false);
|
||||
|
||||
|
||||
$this->assertTrue(
|
||||
$form->isSubmittedAndValid(),
|
||||
"Assert a correct schedule downtime without children form to be considered valid"
|
||||
'Assert a correct schedule downtime without children form to be considered valid'
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -285,12 +292,12 @@ class ScheduleDowntimeFormTest extends BaseFormTest
|
|||
'hours' => '',
|
||||
'minutes' => '',
|
||||
'childobjects' => 'AHA',
|
||||
), self::FORMCLASS);
|
||||
), self::FORM_CLASS);
|
||||
$form->setWithChildren(false);
|
||||
|
||||
$this->assertFalse(
|
||||
$form->isSubmittedAndValid(),
|
||||
"Assert and incorrect (non-numeric) childobjects value to cause validation errors"
|
||||
'Assert and incorrect (non-numeric) childobjects value to cause validation errors'
|
||||
);
|
||||
|
||||
$form = $this->getRequestForm(array(
|
||||
|
@ -303,18 +310,18 @@ class ScheduleDowntimeFormTest extends BaseFormTest
|
|||
'hours' => '',
|
||||
'minutes' => '',
|
||||
'childobjects' => '4',
|
||||
), self::FORMCLASS);
|
||||
), self::FORM_CLASS);
|
||||
$form->setWithChildren(false);
|
||||
|
||||
$this->assertFalse(
|
||||
$form->isSubmittedAndValid(),
|
||||
"Assert and incorrect (numeric) childobjects value to cause validation errors"
|
||||
'Assert and incorrect (numeric) childobjects value to cause validation errors'
|
||||
);
|
||||
}
|
||||
|
||||
public function testTimeRange()
|
||||
{
|
||||
$form = $this->getRequestForm(array(), self::FORMCLASS);
|
||||
$form = $this->getRequestForm(array(), self::FORM_CLASS);
|
||||
$form->buildForm();
|
||||
|
||||
$time1 = $form->getElement('starttime')->getValue();
|
||||
|
@ -323,3 +330,4 @@ class ScheduleDowntimeFormTest extends BaseFormTest
|
|||
$this->assertEquals(3600, ($time2 - $time1));
|
||||
}
|
||||
}
|
||||
// @codingStandardsIgnoreStop
|
||||
|
|
|
@ -1,38 +1,37 @@
|
|||
<?php
|
||||
// @codingStandardsIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Test\Monitoring\Forms\Command;
|
||||
|
||||
require_once __DIR__. '/BaseFormTest.php';
|
||||
require_once __DIR__. '/../../../../../application/forms/Command/CommandForm.php';
|
||||
require_once __DIR__. '/../../../../../application/forms/Command/WithChildrenCommandForm.php';
|
||||
require_once __DIR__. '/../../../../../application/forms/Command/SubmitPassiveCheckResultForm.php';
|
||||
require_once realpath(__DIR__ . '/BaseFormTest.php');
|
||||
require_once realpath(__DIR__ . '/../../../../../application/forms/Command/SubmitPassiveCheckResultForm.php');
|
||||
|
||||
|
||||
use \Zend_View;
|
||||
use \Zend_Test_PHPUnit_ControllerTestCase;
|
||||
use Monitoring\Form\Command\SubmitPassiveCheckResultForm;
|
||||
use \Monitoring\Form\Command\SubmitPassiveCheckResultForm; // Used by constant FORM_CLASS
|
||||
|
||||
class SubmitPassiveCheckResultFormTest extends BaseFormTest
|
||||
{
|
||||
const FORMCLASS = "Monitoring\Form\Command\SubmitPassiveCheckResultForm";
|
||||
const FORM_CLASS = 'Monitoring\Form\Command\SubmitPassiveCheckResultForm';
|
||||
|
||||
public function testStateTypes()
|
||||
{
|
||||
$form = $this->getRequestForm(array(), self::FORMCLASS);
|
||||
$form = $this->getRequestForm(array(), self::FORM_CLASS);
|
||||
|
||||
$form->setType(SubmitPassiveCheckResultForm::TYPE_SERVICE);
|
||||
$options = $form->getOptions();
|
||||
$this->assertCount(4, $options, "Assert correct number of states in service passive checks form");
|
||||
$this->assertEquals('OK', $options[0], "Assert OK state to be available in service passive check form");
|
||||
$this->assertEquals('WARNING', $options[1], "Assert WARNING state to be available in service passive check form");
|
||||
$this->assertEquals('CRITICAL', $options[2], "Assert CRITICAL state to be available in service passive check form");
|
||||
$this->assertEquals('UNKNOWN', $options[3], "Assert UNKNOWN state to be available in service passive check form");
|
||||
$this->assertCount(4, $options, 'Assert correct number of states in service passive checks form');
|
||||
$this->assertEquals('OK', $options[0], 'Assert OK state to be available in service passive check form');
|
||||
$this->assertEquals('WARNING', $options[1], 'Assert WARNING state to be available in service passive check form');
|
||||
$this->assertEquals('CRITICAL', $options[2], 'Assert CRITICAL state to be available in service passive check form');
|
||||
$this->assertEquals('UNKNOWN', $options[3], 'Assert UNKNOWN state to be available in service passive check form');
|
||||
|
||||
$form->setType(SubmitPassiveCheckResultForm::TYPE_HOST);
|
||||
$options = $form->getOptions();
|
||||
$this->assertCount(3, $options, "Assert correct number of states in host passive checks form");
|
||||
$this->assertEquals('UP', $options[0], "Assert UP state to be available in host passive check form");
|
||||
$this->assertEquals('DOWN', $options[1], "Assert DOWN state to be available in host passive check form");
|
||||
$this->assertEquals('UNREACHABLE', $options[2], "Assert UNREACHABLE state to be available in host passive check form");
|
||||
$this->assertCount(3, $options, 'Assert correct number of states in host passive checks form');
|
||||
$this->assertEquals('UP', $options[0], 'Assert UP state to be available in host passive check form');
|
||||
$this->assertEquals('DOWN', $options[1], 'Assert DOWN state to be available in host passive check form');
|
||||
$this->assertEquals('UNREACHABLE', $options[2], 'Assert UNREACHABLE state to be available in host passive check form');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -41,17 +40,15 @@ class SubmitPassiveCheckResultFormTest extends BaseFormTest
|
|||
*/
|
||||
public function testMissingTypeThrowingException()
|
||||
{
|
||||
$form = $this->getRequestForm(array(), self::FORMCLASS);
|
||||
$form = $this->getRequestForm(array(), self::FORM_CLASS);
|
||||
$form->buildForm();
|
||||
}
|
||||
|
||||
public function testCorrectFormCreation()
|
||||
{
|
||||
$form = $this->getRequestForm(array(), self::FORMCLASS);
|
||||
$form = $this->getRequestForm(array(), self::FORM_CLASS);
|
||||
$form->setType(SubmitPassiveCheckResultForm::TYPE_SERVICE);
|
||||
$form->buildForm();
|
||||
|
||||
$this->assertCount(6, $form->getElements(), "Assert correct number of elements in form");
|
||||
}
|
||||
|
||||
public function testCorrectServicePassiveCheckSubmission()
|
||||
|
@ -61,13 +58,13 @@ class SubmitPassiveCheckResultFormTest extends BaseFormTest
|
|||
'checkoutput' => 'DING',
|
||||
'performancedata' => '',
|
||||
'btn_submit' => 'foo'
|
||||
), self::FORMCLASS);
|
||||
), self::FORM_CLASS);
|
||||
|
||||
$form->setType(SubmitPassiveCheckResultForm::TYPE_SERVICE);
|
||||
|
||||
$this->assertTrue(
|
||||
$form->isSubmittedAndValid(),
|
||||
"Assert a correct passive service check form to pass form validation"
|
||||
'Assert a correct passive service check form to pass form validation'
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -77,12 +74,12 @@ class SubmitPassiveCheckResultFormTest extends BaseFormTest
|
|||
'pluginstate' => 0,
|
||||
'checkoutput' => '',
|
||||
'performancedata' => ''
|
||||
), self::FORMCLASS);
|
||||
), self::FORM_CLASS);
|
||||
$form->setType(SubmitPassiveCheckResultForm::TYPE_SERVICE);
|
||||
|
||||
$this->assertFalse(
|
||||
$form->isSubmittedAndValid(),
|
||||
"Assert empty checkoutput to cause validation errors in passive service check "
|
||||
'Assert empty checkoutput to cause validation errors in passive service check '
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -92,12 +89,12 @@ class SubmitPassiveCheckResultFormTest extends BaseFormTest
|
|||
'pluginstate' => 'LA',
|
||||
'checkoutput' => 'DING',
|
||||
'performancedata' => ''
|
||||
), self::FORMCLASS);
|
||||
), self::FORM_CLASS);
|
||||
$form->setType(SubmitPassiveCheckResultForm::TYPE_SERVICE);
|
||||
|
||||
$this->assertFalse(
|
||||
$form->isSubmittedAndValid(),
|
||||
"Assert invalid (non-numeric) state to cause validation errors in passive service check"
|
||||
'Assert invalid (non-numeric) state to cause validation errors in passive service check'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
<?php
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* User: moja
|
||||
* Date: 7/31/13
|
||||
* Time: 1:29 PM
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
// @codingStandardsIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Tests\Icinga\Protocol\Commandpipe;
|
||||
|
||||
|
@ -30,5 +26,7 @@ class CommandPipeLoader extends LibraryLoader {
|
|||
require_once("../../library/Icinga/Protocol/Commandpipe/Transport/Transport.php");
|
||||
require_once("../../library/Icinga/Protocol/Commandpipe/Transport/SecureShell.php");
|
||||
require_once("../../library/Icinga/Protocol/Commandpipe/Transport/LocalPipe.php");
|
||||
require_once('../../library/Icinga/Protocol/Commandpipe/CustomNotification.php');
|
||||
}
|
||||
}
|
||||
}
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
<?php
|
||||
// @codingStandardsIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Tests\Icinga\Protocol\Commandpipe;
|
||||
|
||||
require_once(__DIR__.'/CommandPipeLoader.php');
|
||||
|
@ -6,6 +10,7 @@ CommandPipeLoader::requireLibrary();
|
|||
|
||||
use Icinga\Protocol\Commandpipe\Comment as Comment;
|
||||
use Icinga\Protocol\Commandpipe\Acknowledgement as Acknowledgement;
|
||||
use Icinga\Protocol\Commandpipe\CustomNotification;
|
||||
use Icinga\Protocol\Commandpipe\Downtime as Downtime;
|
||||
use Icinga\Protocol\Commandpipe\Commandpipe as Commandpipe;
|
||||
use \Icinga\Protocol\Commandpipe\PropertyModifier as MONFLAG;
|
||||
|
@ -423,15 +428,15 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
$pipe = $this->getLocalTestPipe();
|
||||
try {
|
||||
$comment = new Comment("author", "commenttext");
|
||||
$notification = new CustomNotification('Author', 'Comment');
|
||||
$pipe->sendCustomNotification(array(
|
||||
(object) array(
|
||||
"host_name" => "host1",
|
||||
"service_description" => "service1"
|
||||
'host_name' => 'Host',
|
||||
'service_description' => 'Service'
|
||||
)
|
||||
), $comment);
|
||||
), $notification);
|
||||
$this->assertCommandSucceeded(
|
||||
"SEND_CUSTOM_SVC_NOTIFICATION;host1;service1;0;author;commenttext"
|
||||
'SEND_CUSTOM_SVC_NOTIFICATION;Host;Service;0;Author;Comment'
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
$this->cleanup();
|
||||
|
@ -449,15 +454,15 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
$pipe = $this->getLocalTestPipe();
|
||||
try {
|
||||
$comment = new Comment('author', 'commenttext');
|
||||
$notification = new CustomNotification('Author', 'Comment', true, true);
|
||||
$pipe->sendCustomNotification(array(
|
||||
(object) array(
|
||||
'host_name' => 'host'
|
||||
'host_name' => 'Host',
|
||||
'service_description' => 'Service'
|
||||
)
|
||||
), $comment, Commandpipe::NOTIFY_FORCED, Commandpipe::NOTIFY_BROADCAST, Commandpipe::NOTIFY_INCREMENT);
|
||||
|
||||
), $notification);
|
||||
$this->assertCommandSucceeded(
|
||||
'SEND_CUSTOM_HOST_NOTIFICATION;host;7;author;commenttext'
|
||||
'SEND_CUSTOM_SVC_NOTIFICATION;Host;Service;3;Author;Comment'
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
$this->cleanup();
|
||||
|
@ -493,3 +498,4 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
|||
$this->cleanup();
|
||||
}
|
||||
}
|
||||
// @codingStandardsIgnoreStop
|
||||
|
|
Loading…
Reference in New Issue