Merge branch 'bugfix/commands-as-object-4580'

refs #4580
fixes #4594
fixes #4496
This commit is contained in:
Jannis Moßhammer 2013-09-04 18:13:43 +02:00
commit 355618d0e0
17 changed files with 990 additions and 349 deletions

View File

@ -4,17 +4,15 @@
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
use \DateTime;
use \Icinga\Application\Icinga;
use \Icinga\Application\Config as IcingaConfig;
use \Icinga\Application\Config;
use \Icinga\Util\DateTimeFactory;
use \Zend_Controller_Request_Http;
use \Icinga\Web\Form\Validator\DateTimeValidator;
/**
* Helper to format date and time. Utilizes DateTimeFactory to ensure time zone awareness
*
* @see \Icinga\Util\DateTimeFactory::create()
* @see DateTimeFactory::create()
*/
class Zend_View_Helper_DateFormat extends Zend_View_Helper_Abstract
{
@ -110,7 +108,7 @@ class Zend_View_Helper_DateFormat extends Zend_View_Helper_Abstract
public function getDateFormat()
{
return $this->request->getUser()->getPreferences()->get(
'dateFormat', IcingaConfig::app()->global->get('dateFormat', 'Y-m-d')
'app.dateFormat', Config::app()->global->get('dateFormat', 'd/m/Y')
);
}
@ -122,7 +120,7 @@ class Zend_View_Helper_DateFormat extends Zend_View_Helper_Abstract
public function getTimeFormat()
{
return $this->request->getUser()->getPreferences()->get(
'timeFormat', IcingaConfig::app()->global->get('timeFormat', 'H:i:s')
'app.timeFormat', Config::app()->global->get('timeFormat', 'g:i A')
);
}

View File

@ -1,136 +0,0 @@
<?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 Icinga\Protocol\Commandpipe;
use \Icinga\Protocol\Commandpipe\Exception\InvalidCommandException;
use \Icinga\Protocol\Commandpipe\Comment;
/**
* Container for a host/service Acknowledgement
*/
class Acknowledgement implements IComment
{
/**
* The expire time of this acknowledgement or -1 if no expire time is used
*
* @var int
*/
private $expireTime = -1;
/**
* Whether to set the notify flag of the acknowledgment
*
* @var bool
*/
private $notify = false;
/**
* The comment text of this acknowledgment
*
* @var Comment
*/
private $comment;
/**
* true if this is a sticky acknowledgment
*
* @var bool
*/
public $sticky;
/**
* Set the expire time of this acknowledgment to $time
*
* @param int $time The new expire time as a UNIX timestamp
*/
public function setExpireTime($time)
{
$this->expireTime = intval($time);
}
/**
* Set the notify flag of this object
*
* @param boolean $bool True if notify should be set, otherwise false
*/
public function setNotify($bool)
{
$this->notify = (bool)$bool;
}
/**
* Create a new acknowledgment container
*
* @param Comment $comment The comment to use for the acknowledgement
* @param bool $notify Whether to set the notify flag
* @param int $expire The expire time or -1 of not expiring
* @param bool $sticky Whether to set the sticky flag
*/
public function __construct(Comment $comment, $notify = false, $expire = -1, $sticky = false)
{
$this->comment = $comment;
$this->setNotify($notify);
$this->setExpireTime($expire);
$this->sticky = $sticky;
}
/**
* Return the ACKNOWLEDGE_?_PROBLEM string to be used for submitting an external icinga command
*
* @param string $type Either CommandPipe::TYPE_HOST or CommandPipe::TYPE_SERVICE
* @return string The command string to be submitted to the command pipe
* @throws InvalidCommandException
*/
public function getFormatString($type)
{
$params = ';'
. ($this->sticky ? '2' : '0')
. ';' . ($this->notify ? '1 ' : '0')
. ';' . ($this->comment->persistent ? '1' : '0');
$params .= ($this->expireTime > -1 ? ';'. $this->expireTime . ';' : ';')
. $this->comment->author . ';' . $this->comment->comment;
switch ($type) {
case CommandPipe::TYPE_HOST:
$typeVar = "HOST";
$params = ";%s" . $params;
break;
case CommandPipe::TYPE_SERVICE:
$typeVar = "SVC";
$params = ";%s;%s" . $params;
break;
default:
throw new InvalidCommandException("Acknowledgements can only apply on hosts and services ");
}
$base = "ACKNOWLEDGE_{$typeVar}_PROBLEM" . ($this->expireTime > -1 ? '_EXPIRE' : '');
return $base . $params;
}
}

View File

@ -28,8 +28,6 @@
namespace Icinga\Protocol\Commandpipe;
use Icinga\Application\Logger as IcingaLogger;
use Icinga\Protocol\Commandpipe\Transport\Transport;
use Icinga\Protocol\Commandpipe\Transport\LocalPipe;
use Icinga\Protocol\Commandpipe\Transport\SecureShell;
@ -139,26 +137,18 @@ class CommandPipe
}
/**
* Acknowledge a set of monitoring objects
* Send a command to the icinga pipe
*
* $objects can be a mixed array of host and service objects
*
* @param array $objects An array of host and service objects
* @param IComment $acknowledgementOrComment An acknowledgement or comment object to use as the comment
* @param \Icinga\Protocol\Commandpipe\CommandType $command
* @param array $objects
*/
public function acknowledge($objects, IComment $acknowledgementOrComment)
public function sendCommand(CommandType $command, array $objects)
{
if (is_a($acknowledgementOrComment, 'Icinga\Protocol\Commandpipe\Comment')) {
$acknowledgementOrComment = new Acknowledgement($acknowledgementOrComment);
}
foreach ($objects as $object) {
if (isset($object->service_description)) {
$format = $acknowledgementOrComment->getFormatString(self::TYPE_SERVICE);
$this->send(sprintf($format, $object->host_name, $object->service_description));
$this->transport->send($command->getServiceCommand($object->host_name, $object->service_description));
} else {
$format = $acknowledgementOrComment->getFormatString(self::TYPE_HOST);
$this->send(sprintf($format, $object->host_name));
$this->transport->send($command->getHostCommand($object->host_name));
}
}
}
@ -247,26 +237,6 @@ class CommandPipe
}
}
/**
* Add a comment to all submitted objects
*
* @param array $objects An array of hosts and services to add a comment for
* @param Comment $comment The comment object to add
*/
public function addComment(array $objects, Comment $comment)
{
foreach ($objects as $object) {
if (isset($object->service_description)) {
$format = $comment->getFormatString(self::TYPE_SERVICE);
$this->send(sprintf($format, $object->host_name, $object->service_description));
} else {
$format = $comment->getFormatString(self::TYPE_HOST);
$this->send(sprintf($format, $object->host_name));
}
}
}
/**
* Removes the submitted comments
*

View File

@ -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>
@ -29,9 +29,8 @@
namespace Icinga\Protocol\Commandpipe;
/**
* Interface flagging a class as being a comment
*
* Interface definition for command objects processed by the CommandPipe
*/
interface IComment
interface CommandType
{
}

View File

@ -30,70 +30,56 @@ namespace Icinga\Protocol\Commandpipe;
/**
* Container for comment information that can be send to icinga's external command pipe
*
*/
class Comment implements IComment
class Comment
{
/**
* Whether the persistent flag should be submitted with this command
* Whether this comment is persistent or not
*
* @var bool
*/
public $persistent = false;
public $persistent;
/**
* The author of this comment
* The author of this comment
*
* @var string
* @var string
*/
public $author = "";
public $author;
/**
* The comment text to use
* The text of this comment
*
* @var string
* @var string
*/
public $comment = "";
public $content;
/**
* Create a new comment object
*
* @param string $author The author name to use for this object
* @param string $comment The comment text to use
* @param bool $persistent Whether this comment should persist icinga restarts
* @param string $author The name of the comment's author
* @param string $content The text for this comment
* @param bool $persistent Whether this comment should be persistent or not
*/
public function __construct($author, $comment, $persistent = false)
public function __construct($author, $content, $persistent = false)
{
$this->author = $author;
$this->comment = $comment;
$this->content = $content;
$this->persistent = $persistent;
}
/**
* Return this comment as an ADD_?_COMMENT external command string that can directly be send to the command pipe
* Return this comment's properties as list of command parameters
*
* @param string $type either CommandPipe::TYPE_HOST or CommandPipe::TYPE_SERVICE
*
* @return string The ADD_HOST_COMMENT or ADD_SVC_COMMENT command, without the timestamp
*
* @throws InvalidCommandException When $type is unknown
* @param bool $ignorePersistentFlag Whether the persistent flag should be included or not
* @return array
*/
public function getFormatString($type)
public function getParameters($ignorePersistentFlag = false)
{
$params = ';' . ($this->persistent ? '1' : '0') . ';' . $this->author . ';' . $this->comment;
switch ($type) {
case CommandPipe::TYPE_HOST:
$typeVar = "HOST";
$params = ";%s" . $params;
break;
case CommandPipe::TYPE_SERVICE:
$typeVar = "SVC";
$params = ";%s;%s" . $params;
break;
default:
throw new InvalidCommandException("Acknowledgements can only apply on hosts and services ");
if ($ignorePersistentFlag) {
return array($this->author, $this->content);
} else {
return array($this->persistent ? '1' : '0', $this->author, $this->content);
}
return "ADD_{$typeVar}_COMMENT$params";
}
}

View File

@ -148,7 +148,7 @@ class Downtime
. $this->trigger_id . ';'
. $this->duration . ';'
. $this->comment->author . ';'
. $this->comment->comment;
. $this->comment->content;
}
/**

View File

@ -651,7 +651,7 @@ class Monitoring_CommandController extends ActionController
$this->setForm($form);
if ($form->IsSubmittedAndValid() === true) {
$this->target->addComment($this->view->objects, $form->getComment());
$this->target->sendCommand($form->createCommand(), $this->view->objects);
}
}
@ -682,11 +682,11 @@ class Monitoring_CommandController extends ActionController
$form->setRequest($this->getRequest());
$form->setConfiguration(Config::app());
$this->setForm($form);
if ($form->IsSubmittedAndValid() === true) {
$this->target->acknowledge($this->view->objects, $form->getAcknowledgement());
$this->target->sendCommand($form->createCommand(), $this->view->objects);
}
$this->setForm($form);
}
/**

View File

@ -29,9 +29,9 @@
namespace Icinga\Module\Monitoring\Form\Command;
use \Icinga\Web\Form\Element\DateTimePicker;
use \Icinga\Protocol\Commandpipe\Acknowledgement;
use \Icinga\Protocol\Commandpipe\Comment;
use \Icinga\Util\DateTimeFactory;
use \Icinga\Module\Monitoring\Command\AcknowledgeCommand;
/**
* Form for problem acknowledgements
@ -156,24 +156,20 @@ class AcknowledgeForm extends CommandForm
}
/**
* Create acknowledgement from request data
* Create the acknowledgement command object
*
* @return \Icinga\Protocol\Commandpipe\Acknowledgement
* @return AcknowledgeCommand
*/
public function getAcknowledgement()
public function createCommand()
{
$expireTime = -1;
if ($this->getValue('expire')) {
$expireTime = $this->getValue('expiretime');
}
return new Acknowledgement(
return new AcknowledgeCommand(
new Comment(
$this->getAuthorName(),
$this->getValue('comment'),
$this->getValue('persistent')
),
$this->getValue('expire') ? $this->getValue('expire') : -1,
$this->getValue('notify'),
$expireTime,
$this->getValue('sticky')
);
}

View File

@ -28,7 +28,8 @@
namespace Icinga\Module\Monitoring\Form\Command;
use \Icinga\Protocol\Commandpipe\Comment;
use Icinga\Protocol\Commandpipe\Comment;
use Icinga\Module\Monitoring\Command\AddCommentCommand;
/**
* Form for adding comment commands
@ -40,6 +41,8 @@ class CommentForm extends CommandForm
*/
protected function create()
{
$this->setName('form_CommentForm');
$this->addNote(t('This command is used to add a comment to hosts or services.'));
$this->addElement($this->createAuthorField());
@ -78,12 +81,18 @@ class CommentForm extends CommandForm
}
/**
* Create comment from request data
* Create the command object to add comments
*
* @return \Icinga\Protocol\Commandpipe\Comment
* @return AddCommentCommand
*/
public function getComment()
public function createCommand()
{
return new Comment($this->getAuthorName(), $this->getValue('comment'), $this->getValue('persistent'));
return new AddCommentCommand(
new Comment(
$this->getAuthorName(),
$this->getValue('comment'),
$this->getValue('persistent')
)
);
}
}

View File

@ -35,6 +35,7 @@ use \Icinga\Web\Form\Element\DateTimePicker;
use \Icinga\Protocol\Commandpipe\Downtime;
use \Icinga\Protocol\Commandpipe\Comment;
use \Icinga\Util\DateTimeFactory;
use \Icinga\Module\Monitoring\Backend;
/**
* Form for scheduling downtimes
@ -51,6 +52,8 @@ class ScheduleDowntimeForm extends WithChildrenCommandForm
*/
const TYPE_FLEXIBLE = 'flexible';
private $downtimes;
/**
* Initialize form
*/
@ -72,6 +75,59 @@ class ScheduleDowntimeForm extends WithChildrenCommandForm
);
}
/**
* Fetch all available downtimes from the database
*
* @return array
*/
private function getCurrentDowntimes()
{
if (isset($this->downtimes)) {
return $this->downtimes;
}
$cfg = $this->getConfiguration();
$preferences = $this->getUserPreferences();
$downtimes = Backend::getInstance($this->getRequest()->getParam('backend'))->select()
->from(
'downtime',
array(
'host_name',
'service_description',
'downtime_scheduled_start_time',
'downtime_internal_downtime_id'
)
)->fetchAll();
$options = array(
'0' => 'No Triggered Downtime '
);
foreach ($downtimes as $downtime) {
$dt = DateTimeFactory::create($downtime->downtime_scheduled_start_time);
$date_format = $preferences->get('app.dateFormat', $cfg->get('app.dateFormat', 'd/m/Y'));
$time_format = $preferences->get('app.timeFormat', $cfg->get('app.timeFormat', 'g:i A'));
$label = sprintf(
'ID %s: %s%s Starting @ %s',
$downtime->downtime_internal_downtime_id,
$downtime->host_name,
!empty($downtime->service_description) ? ' (' . $downtime->service_description . ')' : '',
$dt->format($date_format . ' ' . $time_format)
);
$options[$downtime->downtime_internal_downtime_id] = $label;
}
return $options;
}
/**
* Set the downtimes displayed by this form (used for testing)
*
* @param array $downtimes list of strings
*/
public function setCurrentDowntimes($downtimes)
{
$this->downtimes = $downtimes;
}
/**
* Create the form's elements
*/
@ -108,25 +164,12 @@ class ScheduleDowntimeForm extends WithChildrenCommandForm
*
*/
$this->addElement(
'text',
'select',
'triggered',
array(
'label' => t('Triggered by'),
'value' => 0,
'required' => true,
'validators' => array(
array(
'Digits',
true
),
array(
'GreaterThan',
true,
array(
'min' => -1
)
)
)
'label' => t('Triggered by'),
'required' => true,
'multiOptions' => $this->getCurrentDowntimes()
)
);
@ -288,7 +331,7 @@ class ScheduleDowntimeForm extends WithChildrenCommandForm
/**
* Create Downtime from request Data
*
* @return \Icinga\Protocol\Commandpipe\Downtime
* @return Downtime
*/
public function getDowntime()
{

View File

@ -0,0 +1,178 @@
<?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 Icinga\Module\Monitoring\Command;
use Icinga\Protocol\Commandpipe\Comment;
/**
* Command for acknowledging an object
*/
class AcknowledgeCommand extends BaseCommand
{
/**
* When this acknowledgement should expire
*
* @var int The time as UNIX timestamp or -1 if it shouldn't expire
*/
private $expireTime = -1;
/**
* The comment associated to this acknowledgment
*
* @var Comment
*/
private $comment;
/**
* Whether to set the notify flag of this acknowledgment
*
* @var bool
*/
private $notify;
/**
* Whether this acknowledgement is of type sticky
*
* @var bool
*/
private $sticky;
/**
* Initialise a new acknowledgement command object
*
* @param Comment $comment The comment to use for this acknowledgement
* @param int $expire The expire time or -1 of not expiring
* @param bool $notify Whether to set the notify flag
* @param bool $sticky Whether to set the sticky flag
*/
public function __construct(Comment $comment, $expire = -1, $notify = false, $sticky = false)
{
$this->expireTime = $expire;
$this->comment = $comment;
$this->notify = $notify;
$this->sticky = $sticky;
}
/**
* Set the time when this acknowledgement should expire
*
* @param int $expireTime The time as UNIX timestamp or -1 if it shouldn't expire
* @return self
*/
public function setExpire($expireTime)
{
$this->expireTime = intval($expireTime);
return $this;
}
/**
* Set the comment for this acknowledgement
*
* @param Comment $comment
* @return self
*/
public function setComment(Comment $comment)
{
$this->comment = $comment;
return $this;
}
/**
* Set whether the notify flag of this acknowledgment should be set
*
* @param bool $state
* @return self
*/
public function setNotify($state)
{
$this->notify = (bool) $state;
return $this;
}
/**
* Set whether this acknowledgement is of type sticky
*
* @param bool $state
* @return self
*/
public function setSticky($state)
{
$this->sticky = (bool) $state;
return $this;
}
/**
* Return this command's parameters properly arranged in an array
*
* @return array
*/
public function getParameters()
{
$parameters = array_merge(
array(
$this->sticky ? '2' : '0',
$this->notify ? '1' : '0'
),
$this->comment->getParameters()
);
if ($this->expireTime > -1) {
array_splice($parameters, 3, 0, array($this->expireTime));
}
return $parameters;
}
/**
* @param String $hostname The name of the host to create the command for for
*
* @return String The command string to return for the host
* @see BaseCommand::getHostCommand()
*/
public function getHostCommand($hostname)
{
$parameters = $this->getParameters();
return sprintf('ACKNOWLEDGE_HOST_PROBLEM%s;', $this->expireTime > -1 ? '_EXPIRE' : '')
. implode(';', array_merge(array($hostname), $parameters));
}
/**
* @param String $hostname The name of the host to create the command for
* @param String $servicename The name of the service to create the command for
*
* @return String The command string to return for the service
* @see BaseCommand::getServiceCommand()
*/
public function getServiceCommand($hostname, $servicename)
{
$parameters = $this->getParameters();
return sprintf('ACKNOWLEDGE_SVC_PROBLEM%s;', $this->expireTime > -1 ? '_EXPIRE' : '')
. implode(';', array_merge(array($hostname, $servicename), $parameters));
}
}

View File

@ -0,0 +1,92 @@
<?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 Icinga\Module\Monitoring\Command;
use Icinga\Protocol\Commandpipe\Comment;
/**
* Icinga Command for adding comments
*
* @see BaseCommand
*/
class AddCommentCommand extends BaseCommand
{
/**
* The comment associated to this command
*
* @var Comment
*/
private $comment;
/**
* Initialise a new command object to add comments
*
* @param Comment $comment The comment to use for this acknowledgement
*/
public function __construct(Comment $comment)
{
$this->comment = $comment;
}
/**
* Set the comment for this command
*
* @param Comment $comment
* @return self
*/
public function setComment(Comment $comment)
{
$this->comment = $comment;
return $this;
}
/**
* @param String $hostname The name of the host to create the command for for
*
* @return String The command string to return for the host
* @see BaseCommand::getHostCommand()
*/
public function getHostCommand($hostname)
{
return sprintf('ADD_HOST_COMMENT;%s;', $hostname) . implode(';', $this->comment->getParameters());
}
/**
* @param String $hostname The name of the host to create the command for
* @param String $servicename The name of the service to create the command for
*
* @return String The command string to return for the service
* @see BaseCommand::getServiceCommand()
*/
public function getServiceCommand($hostname, $servicename)
{
return sprintf('ADD_SVC_COMMENT;%s;%s;', $hostname, $servicename)
. implode(';', $this->comment->getParameters());
}
}

View File

@ -0,0 +1,96 @@
<?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 Icinga\Module\Monitoring\Command;
use Icinga\Exception\NotImplementedError;
use Icinga\Protocol\Commandpipe\CommandType;
/**
* Base class for any concrete command implementation
*
* Provides some example methods and often used routines. When implementing
* a new command one is encouraged to override one of those examples.
*/
class BaseCommand implements CommandType
{
/**
* Return the parameters in the right order for this command
*
* @return array
*/
public function getParameters()
{
throw new NotImplementedError();
}
/**
* Return the command as a string with the given host being inserted
*
* @param string $hostname The name of the host to insert
* @return string The string representation of the command
*/
public function getHostCommand($hostname)
{
throw new NotImplementedError();
}
/**
* Return the command as a string with the given host and service being inserted
*
* @param string $hostname The name of the host to insert
* @param string $servicename The name of the service to insert
* @return string The string representation of the command
*/
public function getServiceCommand($hostname, $servicename)
{
throw new NotImplementedError();
}
/**
* Return the command as a string with the given hostgroup being inserted
*
* @param string $hostgroup The name of the hostgroup to insert
* @return string The string representation of the command
*/
public function getHostgroupCommand($hostgroup)
{
throw new NotImplementedError();
}
/**
* Return the command as a string with the given servicegroup being inserted
*
* @param string $servicegroup The name of the servicegroup to insert
* @return string The string representation of the command
*/
public function getServicegroupCommand($servicegroup)
{
throw new NotImplementedError();
}
}

View File

@ -0,0 +1,409 @@
<?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 Test\Monitoring\Forms\Command;
// @codingStandardsIgnoreStart
require_once realpath(__DIR__ . '/../../../../../../../library/Icinga/Test/BaseTestCase.php');
// @codingStandardsIgnoreEnd
use Icinga\Test\BaseTestCase;
// @codingStandardsIgnoreStart
require_once 'Zend/Validate/Digits.php';
require_once 'Zend/Validate/GreaterThan.php';
require_once BaseTestCase::$libDir . '/Web/Form.php';
require_once BaseTestCase::$libDir . '/Util/DateTimeFactory.php';
require_once BaseTestCase::$libDir . '/Util/ConfigAwareFactory.php';
require_once BaseTestCase::$moduleDir . '/monitoring/application/forms/Command/ScheduleDowntimeForm.php';
// @codingStandardsIgnoreEnd
use DateTimeZone;
use Icinga\Util\DateTimeFactory;
use Icinga\Module\Monitoring\Form\Command\ScheduleDowntimeForm; // Used by constant FORM_CLASS
class ScheduleDowntimeFormTest extends BaseTestCase
{
const FORM_CLASS = 'Icinga\Module\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->createForm(self::FORM_CLASS);
$formFixed->setCurrentDowntimes(array('foo'));
$formFixed->buildForm();
$formFlexible = $this->createForm(
self::FORM_CLASS,
array(
'type' => 'flexible'
)
);
$formFlexible->setCurrentDowntimes(array('foo'));
$formFlexible->buildForm();
$form = $this->createForm(self::FORM_CLASS);
$form->setCurrentDowntimes(array('foo'));
$form->setWithChildren(true);
$form->buildForm();
}
public function testCorrectValidationWithChildrend()
{
$form = $this->createForm(
self::FORM_CLASS,
array(
'author' => 'TEST_AUTHOR',
'comment' => 'DING DING',
'triggered' => '0',
'starttime' => '17/07/2013 10:30 AM',
'endtime' => '18/07/2013 10:30 AM',
'type' => ScheduleDowntimeForm::TYPE_FIXED,
'hours' => '',
'minutes' => '',
'btn_submit' => 'foo',
)
);
$form->setWithChildren(true);
$form->setCurrentDowntimes(array('foo'));
$this->assertTrue(
$form->isSubmittedAndValid(),
'Asserting a correct fixed downtime form to be considered valid'
);
$form = $this->createForm(
self::FORM_CLASS,
array(
'author' => 'TEST_AUTHOR',
'comment' => 'DING DING',
'triggered' => '0',
'starttime' => '17/07/2013 10:30 AM',
'endtime' => '18/07/2013 10:30 AM',
'type' => ScheduleDowntimeForm::TYPE_FLEXIBLE,
'hours' => '10',
'minutes' => '10',
'btn_submit' => 'foo'
)
);
$form->setWithChildren(true);
$form->setCurrentDowntimes(array('foo'));
$this->assertTrue(
$form->isSubmittedAndValid(),
'Asserting a correct flexible downtime form to be considered valid'
);
}
public function testMissingFlexibleDurationRecognition()
{
$form = $this->createForm(
self::FORM_CLASS,
array(
'author' => 'TEST_AUTHOR',
'comment' => 'DING DING',
'triggered' => '0',
'starttime' => '17/07/2013 10:30 AM',
'endtime' => '18/07/2013 10:30 AM',
'type' => ScheduleDowntimeForm::TYPE_FLEXIBLE,
'hours' => '',
'minutes' => '',
)
);
$form->setWithChildren(true);
$form->setCurrentDowntimes(array('foo'));
$this->assertFalse(
$form->isSubmittedAndValid(),
'Assert missing hours and minutes in downtime form to cause failing validation'
);
}
public function testMissingAuthorRecognition()
{
$form = $this->createForm(
self::FORM_CLASS,
array(
'author' => '',
'comment' => 'DING DING',
'triggered' => '0',
'starttime' => '17/07/2013 10:30 AM',
'endtime' => '18/07/2013 10:30 AM',
'type' => ScheduleDowntimeForm::TYPE_FIXED,
'hours' => '',
'minutes' => '',
)
);
$form->setWithChildren(true);
$form->setCurrentDowntimes(array('foo'));
$this->assertFalse(
$form->isSubmittedAndValid(),
'Assert missing author to cause validation errors in fixed downtime'
);
}
public function testMissingCommentRecognition()
{
$form = $this->createForm(
self::FORM_CLASS,
array(
'author' => 'OK',
'comment' => '',
'triggered' => '0',
'starttime' => '17/07/2013 10:30 AM',
'endtime' => '18/07/2013 10:30 AM',
'type' => ScheduleDowntimeForm::TYPE_FIXED,
'hours' => '',
'minutes' => '',
)
);
$form->setWithChildren(true);
$form->setCurrentDowntimes(array('foo'));
$this->assertFalse(
$form->isSubmittedAndValid(),
'Assert missing comment to cause validation errors in fixed downtime'
);
}
public function testInvalidTriggeredFieldValueRecognition()
{
$form = $this->createForm(
self::FORM_CLASS,
array(
'author' => 'OK',
'comment' => 'OK',
'triggered' => 'HAHA',
'starttime' => '17/07/2013 10:30 AM',
'endtime' => '18/07/2013 10:30 AM',
'type' => ScheduleDowntimeForm::TYPE_FIXED,
'hours' => '',
'minutes' => '',
)
);
$form->setWithChildren(true);
$form->setCurrentDowntimes(array('foo'));
$this->assertFalse(
$form->isSubmittedAndValid(),
'Assert invalid trigger field to cause validation to fail'
);
}
public function testInvalidStartTimeRecognition()
{
$form = $this->createForm(
self::FORM_CLASS,
array(
'author' => 'OK',
'comment' => 'OK',
'triggered' => '0',
'starttime' => '17/07/2013',
'endtime' => '18/07/2013 10:30 AM',
'type' => ScheduleDowntimeForm::TYPE_FIXED,
'hours' => '',
'minutes' => '',
)
);
$form->setWithChildren(true);
$form->setCurrentDowntimes(array('foo'));
$this->assertFalse(
$form->isSubmittedAndValid(),
'Assert incorrect start time to cause validation errors in fixed downtime'
);
}
public function testInvalidEndTimeRecognition()
{
$form = $this->createForm(
self::FORM_CLASS,
array(
'author' => 'OK',
'comment' => 'OK',
'triggered' => '0',
'starttime' => '17/07/2013 10:30 AM',
'endtime' => 'DING',
'type' => ScheduleDowntimeForm::TYPE_FIXED,
'hours' => '',
'minutes' => '',
)
);
$form->setWithChildren(true);
$form->setCurrentDowntimes(array('foo'));
$this->assertFalse(
$form->isSubmittedAndValid(),
'Assert invalid endtime to cause validation errors in fixed downtime'
);
}
public function testInvalidHoursValueRecognitionInFlexibleDowntime()
{
$form = $this->createForm(
self::FORM_CLASS,
array(
'author' => 'OK',
'comment' => 'OK',
'triggered' => '0',
'starttime' => '17/07/2013 10:30 AM',
'endtime' => '18/07/2013 10:30 AM',
'type' => ScheduleDowntimeForm::TYPE_FLEXIBLE,
'hours' => '-1',
'minutes' => '12',
)
);
$form->setWithChildren(true);
$form->setCurrentDowntimes(array('foo'));
$this->assertFalse(
$form->isSubmittedAndValid(),
'Assert negative hours to cause validation errors in flexible downtime'
);
}
public function testInvalidMinutesValueRecognitionInFlexibleDowntime()
{
$form = $this->createForm(
self::FORM_CLASS,
array(
'author' => 'OK',
'comment' => 'OK',
'triggered' => '0',
'starttime' => '17/07/2013 10:30 AM',
'endtime' => '18/07/2013 10:30 AM',
'type' => ScheduleDowntimeForm::TYPE_FLEXIBLE,
'hours' => '12',
'minutes' => 'DING',
)
);
$form->setWithChildren(true);
$form->setCurrentDowntimes(array('foo'));
$this->assertFalse(
$form->isSubmittedAndValid(),
'Assert non numeric valud to cause validation errors in flexible downtime '
);
}
public function testCorrectScheduleDowntimeWithoutChildrenForm()
{
$form = $this->createForm(
self::FORM_CLASS,
array(
'author' => 'TEST_AUTHOR',
'comment' => 'DING DING',
'triggered' => '0',
'starttime' => '17/07/2013 10:30 AM',
'endtime' => '18/07/2013 10:30 AM',
'type' => ScheduleDowntimeForm::TYPE_FIXED,
'hours' => '',
'minutes' => '',
'btn_submit' => 'foo',
'childobjects' => '0',
)
);
$form->setWithChildren(false);
$form->setCurrentDowntimes(array('foo'));
$this->assertTrue(
$form->isSubmittedAndValid(),
'Assert a correct schedule downtime without children form to be considered valid'
);
}
public function testIncorrectChildObjectsRecognition() {
$form = $this->createForm(
self::FORM_CLASS,
array(
'author' => 'TEST_AUTHOR',
'comment' => 'DING DING',
'triggered' => '0',
'starttime' => '17/07/2013 10:30 AM',
'endtime' => '18/07/2013 10:30 AM',
'type' => ScheduleDowntimeForm::TYPE_FIXED,
'hours' => '',
'minutes' => '',
'childobjects' => 'AHA',
)
);
$form->setWithChildren(false);
$form->setCurrentDowntimes(array('foo'));
$this->assertFalse(
$form->isSubmittedAndValid(),
'Assert and incorrect (non-numeric) childobjects value to cause validation errors'
);
$form = $this->createForm(
self::FORM_CLASS,
array(
'author' => 'TEST_AUTHOR',
'comment' => 'DING DING',
'triggered' => '0',
'starttime' => '17/07/2013 10:30 AM',
'endtime' => '18/07/2013 10:30 AM',
'type' => ScheduleDowntimeForm::TYPE_FIXED,
'hours' => '',
'minutes' => '',
'childobjects' => '4',
)
);
$form->setWithChildren(false);
$form->setCurrentDowntimes(array('foo'));
$this->assertFalse(
$form->isSubmittedAndValid(),
'Assert and incorrect (numeric) childobjects value to cause validation errors'
);
}
public function testTimeRange()
{
$form = $this->createForm(self::FORM_CLASS);
$form->setCurrentDowntimes(array('foo'));
$form->buildForm();
$time1 = $form->getElement('starttime')->getValue();
$time2 = $form->getElement('endtime')->getValue();
$this->assertEquals(3600, ($time2 - $time1));
}
}

View File

@ -2,54 +2,32 @@
namespace Tests\Icinga\Protocol\Commandpipe;
use Icinga\Protocol\Commandpipe\Comment as Comment;
use Icinga\Protocol\Commandpipe\Commandpipe as Commandpipe;
use Icinga\Protocol\Commandpipe\Comment;
use Icinga\Module\Monitoring\Command\AcknowledgeCommand;
require_once("../../library/Icinga/Protocol/Commandpipe/IComment.php");
require_once("../../library/Icinga/Protocol/Commandpipe/Comment.php");
require_once("../../library/Icinga/Protocol/Commandpipe/CommandType.php");
require_once("../../library/Icinga/Protocol/Commandpipe/CommandPipe.php");
require_once("../../library/Icinga/Protocol/Commandpipe/Acknowledgement.php");
require_once("../../library/Icinga/Protocol/Commandpipe/Exception/InvalidCommandException.php");
require_once('../../modules/monitoring/library/Monitoring/Command/BaseCommand.php');
require_once('../../modules/monitoring/library/Monitoring/Command/AcknowledgeCommand.php');
class AcknowledgementTest extends \PHPUnit_Framework_TestCase
{
public function testAcknowledgeHostMessage()
{
$ack = new \Icinga\Protocol\Commandpipe\Acknowledgement(new Comment("author","commentdata"),false);
$this->assertEquals("ACKNOWLEDGE_HOST_PROBLEM;%s;0;0;0;author;commentdata",$ack->getFormatString(CommandPipe::TYPE_HOST));
$ack = new AcknowledgeCommand(new Comment("author", "commentdata"));
$this->assertEquals("ACKNOWLEDGE_HOST_PROBLEM;foo;0;0;0;author;commentdata", $ack->getHostCommand('foo'));
$ack->setExpireTime(1000);
$this->assertEquals("ACKNOWLEDGE_HOST_PROBLEM_EXPIRE;%s;0;0;0;1000;author;commentdata",$ack->getFormatString(CommandPipe::TYPE_HOST));
$ack->setExpire(1000);
$this->assertEquals("ACKNOWLEDGE_HOST_PROBLEM_EXPIRE;bar;0;0;0;1000;author;commentdata", $ack->getHostCommand('bar'));
}
public function testAcknowledgeServiceMessage()
{
$ack = new \Icinga\Protocol\Commandpipe\Acknowledgement(new Comment("author","commentdata"),false);
$this->assertEquals("ACKNOWLEDGE_SVC_PROBLEM;%s;%s;0;0;0;author;commentdata",$ack->getFormatString(CommandPipe::TYPE_SERVICE));
$ack->setExpireTime(1000);
$this->assertEquals("ACKNOWLEDGE_SVC_PROBLEM_EXPIRE;%s;%s;0;0;0;1000;author;commentdata",$ack->getFormatString(CommandPipe::TYPE_SERVICE));
}
/**
* @expectedException \Icinga\Protocol\Commandpipe\Exception\InvalidCommandException
*/
public function testInvalidServicegroupAcknowledgement()
{
$ack = new \Icinga\Protocol\Commandpipe\Acknowledgement(new Comment("author","commentdata"),false);
$ack->getFormatString(CommandPipe::TYPE_SERVICEGROUP);
}
/**
* @expectedException \Icinga\Protocol\Commandpipe\Exception\InvalidCommandException
*/
public function testInvalidHostgroupAcknowledgement()
{
$ack = new \Icinga\Protocol\Commandpipe\Acknowledgement(new Comment("author","commentdata"),false);
$ack->getFormatString(CommandPipe::TYPE_HOSTGROUP);
$ack = new AcknowledgeCommand(new Comment("author", "commentdata"));
$this->assertEquals("ACKNOWLEDGE_SVC_PROBLEM;foo;bar;0;0;0;author;commentdata", $ack->getServiceCommand('foo', 'bar'));
$ack->setExpire(1000);
$this->assertEquals("ACKNOWLEDGE_SVC_PROBLEM_EXPIRE;bar;foo;0;0;0;1000;author;commentdata", $ack->getServiceCommand('bar', 'foo'));
}
}

View File

@ -16,10 +16,9 @@ class CommandPipeLoader extends LibraryLoader {
require_once("Zend/Log.php");
require_once("../../library/Icinga/Application/Logger.php");
require_once("../../library/Icinga/Protocol/Commandpipe/IComment.php");
require_once("../../library/Icinga/Protocol/Commandpipe/Comment.php");
require_once("../../library/Icinga/Protocol/Commandpipe/CommandType.php");
require_once("../../library/Icinga/Protocol/Commandpipe/CommandPipe.php");
require_once("../../library/Icinga/Protocol/Commandpipe/Acknowledgement.php");
require_once("../../library/Icinga/Protocol/Commandpipe/Downtime.php");
require_once("../../library/Icinga/Protocol/Commandpipe/PropertyModifier.php");
require_once("../../library/Icinga/Protocol/Commandpipe/Exception/InvalidCommandException.php");
@ -27,6 +26,9 @@ class CommandPipeLoader extends LibraryLoader {
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');
require_once('../../modules/monitoring/library/Monitoring/Command/BaseCommand.php');
require_once('../../modules/monitoring/library/Monitoring/Command/AcknowledgeCommand.php');
require_once('../../modules/monitoring/library/Monitoring/Command/AddCommentCommand.php');
}
}
// @codingStandardsIgnoreEnd

View File

@ -8,13 +8,15 @@ namespace Tests\Icinga\Protocol\Commandpipe;
require_once(__DIR__.'/CommandPipeLoader.php');
CommandPipeLoader::requireLibrary();
use Icinga\Protocol\Commandpipe\Comment as Comment;
use Icinga\Protocol\Commandpipe\Acknowledgement as Acknowledgement;
use Zend_Config;
use Icinga\Protocol\Commandpipe\Comment;
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;
use Icinga\Protocol\Commandpipe\PropertyModifier as MONFLAG;
use Icinga\Protocol\Ldap\Exception;
use Icinga\Module\Monitoring\Command\AcknowledgeCommand;
use Icinga\Module\Monitoring\Command\AddCommentCommand;
if(!defined("EXTCMD_TEST_BIN"))
define("EXTCMD_TEST_BIN", "./bin/extcmd_test");
@ -50,14 +52,14 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
$this->cleanup();
touch($tmpPipe);
$cfg = new \Zend_Config(array(
"path" => $tmpPipe,
"name" => "test"
));
$comment = new Comment("Autor","Comment");
$pipe = new Commandpipe($cfg);
$cfg = new Zend_Config(
array(
"path" => $tmpPipe,
"name" => "test"
)
);
return $pipe;
return new Commandpipe($cfg);
}
/**
@ -71,18 +73,18 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
$this->cleanup();
touch($tmpPipe);
$cfg = new \Zend_Config(array(
"path" => $tmpPipe,
"user" => "vagrant",
"password" => "vagrant",
"host" => 'localhost',
"port" => 22,
"name" => "test"
));
$comment = new Comment("Autor","Comment");
$pipe = new Commandpipe($cfg);
$cfg = new Zend_Config(
array(
"path" => $tmpPipe,
"user" => "vagrant",
"password" => "vagrant",
"host" => 'localhost',
"port" => 22,
"name" => "test"
)
);
return $pipe;
return new Commandpipe($cfg);
}
/**
@ -131,12 +133,15 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
{
$pipe = $this->getLocalTestPipe();
try {
$ack = new Acknowledgement(new Comment("I can","sends teh ack"));
$pipe->acknowledge(array(
(object) array(
"host_name" => "hostA"
$ack = new AcknowledgeCommand(new Comment("I can", "sends teh ack"));
$pipe->sendCommand(
$ack,
array(
(object) array(
"host_name" => "hostA"
)
)
),$ack);
);
$this->assertCommandSucceeded("ACKNOWLEDGE_HOST_PROBLEM;hostA;0;0;0;I can;sends teh ack");
} catch(Exception $e) {
$this->cleanup();
@ -154,28 +159,31 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
{
$pipe = $this->getLocalTestPipe();
try {
$ack = new Comment("I can","sends teh ack");
$ack = new AcknowledgeCommand(new Comment("I can", "sends teh ack"));
$pipe->getTransport()->setOpenMode("a");
$pipe->acknowledge(array(
(object) array(
"host_name" => "hostA"
),(object) array(
"host_name" => "hostB"
),(object) array(
"host_name" => "hostC"
),(object) array(
"host_name" => "hostC",
"service_description" => "svc"
$pipe->sendCommand(
$ack,
array(
(object) array(
"host_name" => "hostA"
),(object) array(
"host_name" => "hostB"
),(object) array(
"host_name" => "hostC"
),(object) array(
"host_name" => "hostC",
"service_description" => "svc"
)
)
),$ack);
);
$result = explode("\n",file_get_contents($this->getPipeName()));
$result = explode("\n", file_get_contents($this->getPipeName()));
$this->assertCount(5, $result, "Asserting the correct number of commands being written to the command pipe");
$this->assertCommandSucceeded("ACKNOWLEDGE_HOST_PROBLEM;hostA;0;0;0;I can;sends teh ack",$result[0]);
$this->assertCommandSucceeded("ACKNOWLEDGE_HOST_PROBLEM;hostB;0;0;0;I can;sends teh ack",$result[1]);
$this->assertCommandSucceeded("ACKNOWLEDGE_HOST_PROBLEM;hostC;0;0;0;I can;sends teh ack",$result[2]);
$this->assertCommandSucceeded("ACKNOWLEDGE_SVC_PROBLEM;hostC;svc;0;0;0;I can;sends teh ack",$result[3]);
$this->assertCommandSucceeded("ACKNOWLEDGE_HOST_PROBLEM;hostA;0;0;0;I can;sends teh ack", $result[0]);
$this->assertCommandSucceeded("ACKNOWLEDGE_HOST_PROBLEM;hostB;0;0;0;I can;sends teh ack", $result[1]);
$this->assertCommandSucceeded("ACKNOWLEDGE_HOST_PROBLEM;hostC;0;0;0;I can;sends teh ack", $result[2]);
$this->assertCommandSucceeded("ACKNOWLEDGE_SVC_PROBLEM;hostC;svc;0;0;0;I can;sends teh ack", $result[3]);
} catch(Exception $e) {
$this->cleanup();
@ -187,14 +195,24 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
/**
* Test whether a single host comment is correctly serialized and send to the command pipe
*
* @throws \Exception|Exception
* @throws Exception
*/
public function testAddHostComment()
{
$pipe = $this->getLocalTestPipe();
try {
$pipe->addComment(array((object) array("host_name" => "hostA")),
new Comment("Autor","Comment")
$pipe->sendCommand(
new AddCommentCommand(
new Comment(
"Autor",
"Comment"
)
),
array(
(object) array(
"host_name" => "hostA"
)
)
);
$this->assertCommandSucceeded("ADD_HOST_COMMENT;hostA;0;Autor;Comment");
} catch(Exception $e) {
@ -358,7 +376,7 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
{
$pipe = $this->getLocalTestPipe();
try {
$downtime = new Downtime(25,26,new Comment("me","test"));
$downtime = new Downtime(25, 26, new Comment("me", "test"));
$pipe->scheduleDowntime(array(
(object) array(
"host_name" => "Testhost"
@ -484,12 +502,15 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
}
$pipe = $this->getSSHTestPipe();
try {
$ack = new Acknowledgement(new Comment("I can","sends teh ack"));
$pipe->acknowledge(array(
(object) array(
"host_name" => "hostA"
$ack = new AcknowledgeCommand(new Comment("I can", "sends teh ack"));
$pipe->sendCommand(
$ack,
array(
(object) array(
"host_name" => "hostA"
)
)
),$ack);
);
$this->assertCommandSucceeded("ACKNOWLEDGE_HOST_PROBLEM;hostA;0;0;0;I can;sends teh ack");
} catch(Exception $e) {
$this->cleanup();