Re-refactor dispatch process of commands and acknowledgement handling
refs #4580
This commit is contained in:
parent
1593406f31
commit
9a476f16f4
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -139,41 +139,16 @@ class CommandPipe
|
|||
/**
|
||||
* Send a command to the icinga pipe
|
||||
*
|
||||
* @param \Icinga\Protocol\Commandpipe\Command $command
|
||||
* @param array $objects
|
||||
* @param \Icinga\Protocol\Commandpipe\CommandType $command
|
||||
* @param array $objects
|
||||
*/
|
||||
public function sendCommand(Command $command, array $objects)
|
||||
public function sendCommand(CommandType $command, array $objects)
|
||||
{
|
||||
foreach ($objects as $object) {
|
||||
if (isset($object->service_description)) {
|
||||
$command->setService($object->service_description);
|
||||
}
|
||||
$command->setHost($object->host_name);
|
||||
$this->transport->send((string) $command);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Acknowledge a set of monitoring objects
|
||||
*
|
||||
* $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
|
||||
*/
|
||||
public function acknowledge($objects, IComment $acknowledgementOrComment)
|
||||
{
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,28 +31,6 @@ namespace Icinga\Protocol\Commandpipe;
|
|||
/**
|
||||
* Interface definition for command objects processed by the CommandPipe
|
||||
*/
|
||||
interface Command
|
||||
interface CommandType
|
||||
{
|
||||
/**
|
||||
* Set the hostname for this command
|
||||
*
|
||||
* @param string $hostname
|
||||
* @return self
|
||||
*/
|
||||
public function setHost($hostname);
|
||||
|
||||
/**
|
||||
* Set the service description for this command
|
||||
*
|
||||
* @param string $service_description
|
||||
* @return self
|
||||
*/
|
||||
public function setService($service_description);
|
||||
|
||||
/**
|
||||
* Return a string representation of this command
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString();
|
||||
}
|
|
@ -162,21 +162,15 @@ class AcknowledgeForm extends CommandForm
|
|||
*/
|
||||
public function createCommand()
|
||||
{
|
||||
$command = new AcknowledgeCommand();
|
||||
$command->setComment(
|
||||
return new AcknowledgeCommand(
|
||||
new Comment(
|
||||
$this->getAuthorName(),
|
||||
$this->getValue('comment'),
|
||||
$this->getValue('persistent')
|
||||
)
|
||||
),
|
||||
$this->getValue('expire') ? $this->getValue('expire') : -1,
|
||||
$this->getValue('notify'),
|
||||
$this->getValue('sticky')
|
||||
);
|
||||
$command->setNotify($this->getValue('notify'));
|
||||
$command->setSticky($this->getValue('sticky'));
|
||||
|
||||
if ($this->getValue('expire')) {
|
||||
$command->setExpireTime($expireTime);
|
||||
}
|
||||
|
||||
return $command;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,28 +28,33 @@
|
|||
|
||||
namespace Monitoring\Command;
|
||||
|
||||
use \Icinga\Protocol\Commandpipe\Command;
|
||||
use \Icinga\Protocol\Commandpipe\CommandPipe;
|
||||
use \Icinga\Protocol\Commandpipe\Acknowledgement;
|
||||
use \Icinga\Protocol\Commandpipe\Comment;
|
||||
|
||||
class AcknowledgeCommand extends MonitoringCommand implements Command
|
||||
class AcknowledgeCommand extends BaseCommand
|
||||
{
|
||||
/**
|
||||
* When this acknowledgement should expire
|
||||
*
|
||||
* @var int
|
||||
* @var int The time as UNIX timestamp or -1 if it shouldn't expire
|
||||
*/
|
||||
private $expireTime = -1;
|
||||
|
||||
/**
|
||||
* Whether notifications are going to be sent out
|
||||
* The comment associated to this acknowledgment
|
||||
*
|
||||
* @var Comment
|
||||
*/
|
||||
protected $comment;
|
||||
|
||||
/**
|
||||
* Whether to set the notify flag of this acknowledgment
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $notify;
|
||||
|
||||
/**
|
||||
* Whether this acknowledgement is going to be stickied
|
||||
* Whether this acknowledgement is of type sticky
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
|
@ -58,65 +63,106 @@ class AcknowledgeCommand extends MonitoringCommand implements Command
|
|||
/**
|
||||
* Set the time when this acknowledgement should expire
|
||||
*
|
||||
* @param int $expireTime
|
||||
* @return self
|
||||
* @param int $expireTime The time as UNIX timestamp or -1 if it shouldn't expire
|
||||
* @return self
|
||||
*/
|
||||
public function setExpireTime($expireTime)
|
||||
public function setExpire($expireTime)
|
||||
{
|
||||
$this->expireTime = $expireTime;
|
||||
$this->expireTime = intval($expireTime);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether notifications should be sent out
|
||||
* Set the comment for this acknowledgement
|
||||
*
|
||||
* @param bool $state
|
||||
* @return self
|
||||
* @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 = $state;
|
||||
$this->notify = (bool) $state;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether this acknowledgement should be stickied
|
||||
* Set whether this acknowledgement is of type sticky
|
||||
*
|
||||
* @param bool $state
|
||||
* @return self
|
||||
* @param bool $state
|
||||
* @return self
|
||||
*/
|
||||
public function setSticky($state)
|
||||
{
|
||||
$this->sticky = $state;
|
||||
$this->sticky = (bool) $state;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the acknowledgement object
|
||||
* Initialise a new acknowledgement command object
|
||||
*
|
||||
* @return \Icinga\Protocol\Commandpipe\Acknowledgement
|
||||
* @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 createAcknowledgement()
|
||||
public function __construct(Comment $comment, $expire = -1, $notify = false, $sticky = false)
|
||||
{
|
||||
return new Acknowledgement(
|
||||
$this->comment,
|
||||
$this->notify,
|
||||
$this->expireTime,
|
||||
$this->sticky
|
||||
);
|
||||
$this->expireTime = $expire;
|
||||
$this->comment = $comment;
|
||||
$this->notify = $notify;
|
||||
$this->sticky = $sticky;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Command::__toString()
|
||||
* Return the parameters in the right order
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function __toString()
|
||||
public function getParameters()
|
||||
{
|
||||
if (isset($this->service_description)) {
|
||||
$template = $this->createAcknowledgement()->getFormatString(CommandPipe::TYPE_SERVICE);
|
||||
return sprintf($template, $this->hostname, $this->service_description);
|
||||
} else {
|
||||
$template = $this->createAcknowledgement()->getFormatString(CommandPipe::TYPE_HOST);
|
||||
return sprintf($template, $this->hostname);
|
||||
$parameters = array(
|
||||
$this->sticky ? '2' : '0',
|
||||
$this->notify ? '1' : '0',
|
||||
$this->comment->persistent ? '1' : '0',
|
||||
$this->comment->author,
|
||||
$this->comment->comment
|
||||
);
|
||||
|
||||
if ($this->expireTime > -1) {
|
||||
array_splice($parameters, 3, 0, array($this->expireTime));
|
||||
}
|
||||
|
||||
return $parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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));
|
||||
}
|
||||
|
||||
/**
|
||||
* @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));
|
||||
}
|
||||
}
|
|
@ -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 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();
|
||||
}
|
||||
}
|
|
@ -1,86 +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 Monitoring\Command;
|
||||
|
||||
use \Icinga\Protocol\Commandpipe\Command;
|
||||
use \Icinga\Protocol\Commandpipe\Comment;
|
||||
|
||||
abstract class MonitoringCommand implements Command
|
||||
{
|
||||
/**
|
||||
* The hostname for this command
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $hostname;
|
||||
|
||||
/**
|
||||
* The service description for this command
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $service_description;
|
||||
|
||||
/**
|
||||
* The comment associated to this command
|
||||
*
|
||||
* @var Comment
|
||||
*/
|
||||
protected $comment;
|
||||
|
||||
/**
|
||||
* @see Command::setHost()
|
||||
*/
|
||||
public function setHost($hostname)
|
||||
{
|
||||
$this->hostname = $hostname;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Command::setService()
|
||||
*/
|
||||
public function setService($service_description)
|
||||
{
|
||||
$this->service_description = $service_description;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the comment for this command
|
||||
*
|
||||
* @param Comment $comment
|
||||
* @return self
|
||||
*/
|
||||
public function setComment(Comment $comment)
|
||||
{
|
||||
$this->comment = $comment;
|
||||
return $this;
|
||||
}
|
||||
}
|
|
@ -2,54 +2,33 @@
|
|||
|
||||
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 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'));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,8 +18,8 @@ class CommandPipeLoader extends LibraryLoader {
|
|||
|
||||
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 +27,8 @@ 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');
|
||||
}
|
||||
}
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
|
|
@ -9,12 +9,12 @@ require_once(__DIR__.'/CommandPipeLoader.php');
|
|||
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;
|
||||
use Icinga\Protocol\Commandpipe\PropertyModifier as MONFLAG;
|
||||
use Icinga\Protocol\Ldap\Exception;
|
||||
use Monitoring\Command\AcknowledgeCommand;
|
||||
|
||||
if(!defined("EXTCMD_TEST_BIN"))
|
||||
define("EXTCMD_TEST_BIN", "./bin/extcmd_test");
|
||||
|
@ -131,12 +131,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 +157,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();
|
||||
|
@ -484,12 +490,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();
|
||||
|
|
Loading…
Reference in New Issue