2013-06-03 15:34:57 +02:00
|
|
|
<?php
|
2013-08-15 15:35:17 +02:00
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
2013-09-05 14:00:38 +02:00
|
|
|
/**
|
|
|
|
* 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>
|
|
|
|
*/
|
2013-08-15 15:35:17 +02:00
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
|
2013-06-03 15:34:57 +02:00
|
|
|
namespace Tests\Icinga\Protocol\Commandpipe;
|
|
|
|
|
2013-07-31 14:17:40 +02:00
|
|
|
require_once(__DIR__.'/CommandPipeLoader.php');
|
|
|
|
CommandPipeLoader::requireLibrary();
|
|
|
|
|
2013-09-04 16:21:44 +02:00
|
|
|
use Zend_Config;
|
|
|
|
use Icinga\Protocol\Commandpipe\Comment;
|
2013-06-03 15:34:57 +02:00
|
|
|
use Icinga\Protocol\Commandpipe\Commandpipe as Commandpipe;
|
2013-09-04 10:50:00 +02:00
|
|
|
use Icinga\Protocol\Commandpipe\PropertyModifier as MONFLAG;
|
2013-08-01 15:15:38 +02:00
|
|
|
use Icinga\Protocol\Ldap\Exception;
|
2013-09-04 16:21:44 +02:00
|
|
|
use Icinga\Module\Monitoring\Command\AcknowledgeCommand;
|
|
|
|
use Icinga\Module\Monitoring\Command\AddCommentCommand;
|
2013-09-05 10:55:32 +02:00
|
|
|
use Icinga\Module\Monitoring\Command\ScheduleDowntimeCommand;
|
2013-09-05 13:30:43 +02:00
|
|
|
use Icinga\Module\Monitoring\Command\CustomNotificationCommand;
|
2013-09-05 14:00:38 +02:00
|
|
|
use Icinga\Module\Monitoring\Command\DelayNotificationCommand;
|
2013-09-05 16:02:09 +02:00
|
|
|
use Icinga\Module\Monitoring\Command\ScheduleCheckCommand;
|
2013-06-03 15:34:57 +02:00
|
|
|
|
2013-09-05 14:00:38 +02:00
|
|
|
if (!defined("EXTCMD_TEST_BIN")) {
|
2013-06-03 15:34:57 +02:00
|
|
|
define("EXTCMD_TEST_BIN", "./bin/extcmd_test");
|
2013-09-05 14:00:38 +02:00
|
|
|
}
|
2013-06-03 15:34:57 +02:00
|
|
|
|
2013-07-31 14:17:40 +02:00
|
|
|
/**
|
|
|
|
* Several tests for the command pipe component
|
|
|
|
*
|
|
|
|
* Uses the helper script extcmd_test, which is basically the extracted command
|
|
|
|
* parser functions from the icinga core
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2013-06-03 15:34:57 +02:00
|
|
|
class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
2013-07-31 14:17:40 +02:00
|
|
|
/**
|
|
|
|
* Return the path of the test pipe used in these tests
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2013-06-03 15:34:57 +02:00
|
|
|
public function getPipeName()
|
|
|
|
{
|
|
|
|
return sys_get_temp_dir()."/icinga_test_pipe";
|
|
|
|
}
|
2013-07-31 14:17:40 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a @see Icinga\Protocal\CommandPipe\CommandPipe instance set up for the local test pipe
|
|
|
|
*
|
|
|
|
* @return Commandpipe
|
|
|
|
*/
|
|
|
|
private function getLocalTestPipe()
|
|
|
|
{
|
|
|
|
$tmpPipe = $this->getPipeName();
|
|
|
|
$this->cleanup();
|
|
|
|
touch($tmpPipe);
|
|
|
|
|
2013-09-04 16:21:44 +02:00
|
|
|
$cfg = new Zend_Config(
|
|
|
|
array(
|
|
|
|
"path" => $tmpPipe,
|
|
|
|
"name" => "test"
|
|
|
|
)
|
|
|
|
);
|
2013-07-31 14:17:40 +02:00
|
|
|
|
2013-09-04 16:21:44 +02:00
|
|
|
return new Commandpipe($cfg);
|
2013-07-31 14:17:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a @see Icinga\Protocal\CommandPipe\CommandPipe instance set up for the local test pipe, but with ssh as the transport layer
|
|
|
|
*
|
|
|
|
* @return Commandpipe
|
|
|
|
*/
|
|
|
|
private function getSSHTestPipe()
|
2013-06-03 15:34:57 +02:00
|
|
|
{
|
|
|
|
$tmpPipe = $this->getPipeName();
|
|
|
|
$this->cleanup();
|
|
|
|
touch($tmpPipe);
|
|
|
|
|
2013-09-04 16:21:44 +02:00
|
|
|
$cfg = new Zend_Config(
|
|
|
|
array(
|
|
|
|
"path" => $tmpPipe,
|
|
|
|
"user" => "vagrant",
|
|
|
|
"password" => "vagrant",
|
|
|
|
"host" => 'localhost',
|
|
|
|
"port" => 22,
|
|
|
|
"name" => "test"
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
return new Commandpipe($cfg);
|
2013-06-03 15:34:57 +02:00
|
|
|
}
|
|
|
|
|
2013-07-31 14:17:40 +02:00
|
|
|
/**
|
|
|
|
* Remove the testpipe if it exists
|
|
|
|
*
|
|
|
|
*/
|
2013-06-03 15:34:57 +02:00
|
|
|
private function cleanup() {
|
|
|
|
if(file_exists($this->getPipeName()))
|
|
|
|
unlink($this->getPipeName());
|
|
|
|
}
|
|
|
|
|
2013-07-31 14:17:40 +02:00
|
|
|
/**
|
|
|
|
* Query the extcmd_test script with $command or the command pipe and test whether the result is $exceptedString and
|
|
|
|
* has a return code of 0.
|
|
|
|
*
|
|
|
|
* Note:
|
|
|
|
* - if no string is given, only the return code is tested
|
|
|
|
* - if no command is given, the content of the test commandpipe is used
|
|
|
|
*
|
|
|
|
* This helps testing whether commandpipe serialization works correctly
|
|
|
|
*
|
|
|
|
* @param bool $expectedString The string that is expected to be returned from the extcmd_test binary
|
|
|
|
* (optional, leave it to just test for the return code)
|
|
|
|
* @param bool $command The commandstring to send (optional, leave it for using the command pipe content)
|
|
|
|
*/
|
2013-06-03 15:34:57 +02:00
|
|
|
private function assertCommandSucceeded($expectedString = false,$command = false) {
|
|
|
|
$resultCode = null;
|
|
|
|
$resultArr = array();
|
|
|
|
$receivedCmd = exec(EXTCMD_TEST_BIN." ".escapeshellarg($command ? $command : file_get_contents($this->getPipeName())),$resultArr,$resultCode);
|
2013-07-31 14:17:40 +02:00
|
|
|
$this->assertEquals(0, $resultCode, "Submit of external command returned error : ".$receivedCmd);
|
2013-06-03 15:34:57 +02:00
|
|
|
if (!$expectedString)
|
|
|
|
return;
|
|
|
|
$this->assertEquals(
|
|
|
|
$expectedString,
|
2013-07-31 14:17:40 +02:00
|
|
|
$receivedCmd,
|
|
|
|
'Asserting that the command icinga received matches the command we send'
|
2013-06-03 15:34:57 +02:00
|
|
|
);
|
|
|
|
}
|
2013-07-31 14:17:40 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test whether a single host acknowledgment is serialized and send correctly
|
|
|
|
*
|
|
|
|
* @throws \Exception|Exception
|
|
|
|
*/
|
2013-06-03 15:34:57 +02:00
|
|
|
public function testAcknowledgeSingleHost()
|
|
|
|
{
|
2013-07-31 14:17:40 +02:00
|
|
|
$pipe = $this->getLocalTestPipe();
|
2013-06-03 15:34:57 +02:00
|
|
|
try {
|
2013-09-04 16:21:44 +02:00
|
|
|
$ack = new AcknowledgeCommand(new Comment("I can", "sends teh ack"));
|
2013-09-04 10:50:00 +02:00
|
|
|
$pipe->sendCommand(
|
|
|
|
$ack,
|
|
|
|
array(
|
|
|
|
(object) array(
|
|
|
|
"host_name" => "hostA"
|
|
|
|
)
|
2013-06-03 15:34:57 +02:00
|
|
|
)
|
2013-09-04 10:50:00 +02:00
|
|
|
);
|
2013-06-03 15:34:57 +02:00
|
|
|
$this->assertCommandSucceeded("ACKNOWLEDGE_HOST_PROBLEM;hostA;0;0;0;I can;sends teh ack");
|
|
|
|
} catch(Exception $e) {
|
|
|
|
$this->cleanup();
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
$this->cleanup();
|
|
|
|
}
|
|
|
|
|
2013-07-31 14:17:40 +02:00
|
|
|
/**
|
|
|
|
* Test whether multiple host and service acknowledgments are serialized and send correctly
|
|
|
|
*
|
|
|
|
* @throws \Exception|Exception
|
|
|
|
*/
|
2013-06-03 15:34:57 +02:00
|
|
|
public function testAcknowledgeMultipleObjects()
|
|
|
|
{
|
2013-07-31 14:17:40 +02:00
|
|
|
$pipe = $this->getLocalTestPipe();
|
2013-06-03 15:34:57 +02:00
|
|
|
try {
|
2013-09-04 16:21:44 +02:00
|
|
|
$ack = new AcknowledgeCommand(new Comment("I can", "sends teh ack"));
|
2013-07-31 14:17:40 +02:00
|
|
|
$pipe->getTransport()->setOpenMode("a");
|
2013-09-04 10:50:00 +02:00
|
|
|
$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"
|
|
|
|
)
|
2013-06-03 15:34:57 +02:00
|
|
|
)
|
2013-09-04 10:50:00 +02:00
|
|
|
);
|
2013-06-03 15:34:57 +02:00
|
|
|
|
2013-09-04 10:50:00 +02:00
|
|
|
$result = explode("\n", file_get_contents($this->getPipeName()));
|
2013-07-31 14:17:40 +02:00
|
|
|
$this->assertCount(5, $result, "Asserting the correct number of commands being written to the command pipe");
|
2013-06-03 15:34:57 +02:00
|
|
|
|
2013-09-04 10:50:00 +02:00
|
|
|
$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]);
|
2013-06-03 15:34:57 +02:00
|
|
|
|
|
|
|
} catch(Exception $e) {
|
|
|
|
$this->cleanup();
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
$this->cleanup();
|
|
|
|
}
|
|
|
|
|
2013-07-31 14:17:40 +02:00
|
|
|
/**
|
|
|
|
* Test whether a single host comment is correctly serialized and send to the command pipe
|
|
|
|
*
|
2013-09-04 16:21:44 +02:00
|
|
|
* @throws Exception
|
2013-07-31 14:17:40 +02:00
|
|
|
*/
|
2013-06-03 15:34:57 +02:00
|
|
|
public function testAddHostComment()
|
|
|
|
{
|
2013-07-31 14:17:40 +02:00
|
|
|
$pipe = $this->getLocalTestPipe();
|
2013-06-03 15:34:57 +02:00
|
|
|
try {
|
2013-09-04 16:21:44 +02:00
|
|
|
$pipe->sendCommand(
|
|
|
|
new AddCommentCommand(
|
|
|
|
new Comment(
|
|
|
|
"Autor",
|
|
|
|
"Comment"
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
(object) array(
|
|
|
|
"host_name" => "hostA"
|
|
|
|
)
|
|
|
|
)
|
2013-06-03 15:34:57 +02:00
|
|
|
);
|
|
|
|
$this->assertCommandSucceeded("ADD_HOST_COMMENT;hostA;0;Autor;Comment");
|
|
|
|
} catch(Exception $e) {
|
|
|
|
$this->cleanup();
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
$this->cleanup();
|
|
|
|
}
|
|
|
|
|
2013-07-31 14:17:40 +02:00
|
|
|
/**
|
|
|
|
* Test whether removing all hostcomments is correctly serialized and send to the command pipe
|
|
|
|
*
|
|
|
|
* @throws \Exception|Exception
|
|
|
|
*/
|
2013-06-03 15:34:57 +02:00
|
|
|
public function testRemoveAllHostComment()
|
|
|
|
{
|
2013-07-31 14:17:40 +02:00
|
|
|
$pipe = $this->getLocalTestPipe();
|
2013-06-03 15:34:57 +02:00
|
|
|
try {
|
|
|
|
$pipe->removeComment(array(
|
|
|
|
(object) array(
|
|
|
|
"host_name" => "test"
|
|
|
|
)
|
|
|
|
));
|
|
|
|
$this->assertCommandSucceeded("DEL_ALL_HOST_COMMENTS;test");
|
|
|
|
} catch(Exception $e) {
|
|
|
|
$this->cleanup();
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
$this->cleanup();
|
|
|
|
}
|
|
|
|
|
2013-07-31 14:17:40 +02:00
|
|
|
/**
|
|
|
|
* Test whether removing a single host comment is correctly serialized and send to the command pipe
|
|
|
|
*
|
|
|
|
* @throws \Exception|Exception
|
|
|
|
*/
|
2013-06-03 15:34:57 +02:00
|
|
|
public function testRemoveSpecificComment()
|
|
|
|
{
|
2013-07-31 14:17:40 +02:00
|
|
|
$pipe = $this->getLocalTestPipe();
|
2013-06-03 15:34:57 +02:00
|
|
|
try {
|
|
|
|
$pipe->removeComment(array((object) array("comment_id"=>34,"host_name"=>"test")));
|
|
|
|
$this->assertCommandSucceeded("DEL_HOST_COMMENT;34");
|
|
|
|
} catch(Exception $e) {
|
|
|
|
$this->cleanup();
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
$this->cleanup();
|
|
|
|
}
|
|
|
|
|
2013-07-31 14:17:40 +02:00
|
|
|
/**
|
|
|
|
* Test whether a multiple reschedules for services and hosts are correctly serialized and send to the commandpipe
|
|
|
|
*
|
|
|
|
* @throws \Exception|Exception
|
|
|
|
*/
|
2013-06-03 15:34:57 +02:00
|
|
|
public function testScheduleChecks()
|
|
|
|
{
|
2013-07-31 14:17:40 +02:00
|
|
|
$pipe = $this->getLocalTestPipe();
|
2013-06-03 15:34:57 +02:00
|
|
|
try {
|
2013-09-05 16:02:09 +02:00
|
|
|
$pipe->getTransport()->setOpenMode('a'); // append so we have multiple results
|
|
|
|
$command = new ScheduleCheckCommand(5000);
|
|
|
|
$pipe->sendCommand(
|
|
|
|
$command,
|
|
|
|
array(
|
|
|
|
(object) array(
|
|
|
|
'host_name' => 'test'
|
|
|
|
),
|
|
|
|
(object) array(
|
|
|
|
'host_name' => 'test',
|
|
|
|
'service_description' => 'svc1'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$command->setForced(true);
|
|
|
|
$pipe->sendCommand(
|
|
|
|
$command,
|
|
|
|
array(
|
|
|
|
(object) array(
|
|
|
|
'host_name' => 'test'
|
|
|
|
),
|
|
|
|
(object) array(
|
|
|
|
'host_name' => 'test',
|
|
|
|
'service_description' => 'svc1'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$command->excludeHost();
|
|
|
|
$pipe->sendCommand(
|
|
|
|
$command,
|
|
|
|
array(
|
|
|
|
(object) array(
|
|
|
|
'host_name' => 'test'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2013-06-03 15:34:57 +02:00
|
|
|
|
2013-09-05 16:02:09 +02:00
|
|
|
$result = explode("\n", file_get_contents($this->getPipeName()));
|
|
|
|
$this->assertCount(6, $result, 'Asserting a correct number of commands being written to the commandpipe');
|
2013-06-03 15:34:57 +02:00
|
|
|
|
2013-09-05 16:02:09 +02:00
|
|
|
$this->assertCommandSucceeded('SCHEDULE_HOST_CHECK;test;5000', $result[0]);
|
|
|
|
$this->assertCommandSucceeded('SCHEDULE_SVC_CHECK;test;svc1;5000', $result[1]);
|
|
|
|
$this->assertCommandSucceeded('SCHEDULE_FORCED_HOST_CHECK;test;5000', $result[2]);
|
|
|
|
$this->assertCommandSucceeded('SCHEDULE_FORCED_SVC_CHECK;test;svc1;5000', $result[3]);
|
|
|
|
$this->assertCommandSucceeded('SCHEDULE_FORCED_HOST_SVC_CHECKS;test;5000', $result[4]);
|
2013-06-03 15:34:57 +02:00
|
|
|
} catch(Exception $e) {
|
|
|
|
$this->cleanup();
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
$this->cleanup();
|
|
|
|
}
|
|
|
|
|
2013-07-31 14:17:40 +02:00
|
|
|
/**
|
|
|
|
* Test whether modifying monitoringflags of a host and service is correctly serialized and send to the command pipe
|
|
|
|
*
|
|
|
|
* @throws \Exception|Exception
|
|
|
|
*/
|
2013-06-03 15:34:57 +02:00
|
|
|
public function testObjectStateModifications()
|
|
|
|
{
|
2013-07-31 14:17:40 +02:00
|
|
|
$pipe = $this->getLocalTestPipe();
|
2013-06-03 15:34:57 +02:00
|
|
|
try {
|
2013-07-31 14:17:40 +02:00
|
|
|
$pipe->getTransport()->setOpenMode("a");
|
2013-06-03 15:34:57 +02:00
|
|
|
$pipe->setMonitoringProperties(array(
|
|
|
|
(object) array(
|
|
|
|
"host_name" => "Testhost"
|
|
|
|
),
|
|
|
|
(object) array(
|
|
|
|
"host_name" => "host",
|
|
|
|
"service_description" => "svc"
|
|
|
|
)
|
|
|
|
), new MONFLAG(array(
|
|
|
|
MONFLAG::ACTIVE => MONFLAG::STATE_DISABLE,
|
|
|
|
MONFLAG::PASSIVE => MONFLAG::STATE_ENABLE,
|
|
|
|
MONFLAG::NOTIFICATIONS => MONFLAG::STATE_DISABLE,
|
|
|
|
MONFLAG::EVENTHANDLER => MONFLAG::STATE_ENABLE,
|
|
|
|
MONFLAG::FLAPPING => MONFLAG::STATE_DISABLE,
|
|
|
|
MONFLAG::FRESHNESS => MONFLAG::STATE_ENABLE,
|
|
|
|
))
|
|
|
|
);
|
|
|
|
|
|
|
|
$result = explode("\n",file_get_contents($this->getPipeName()));
|
|
|
|
array_pop($result); // remove empty last line
|
2013-07-31 14:17:40 +02:00
|
|
|
$this->assertCount(12,$result, "Asserting a correct number of commands being written to the commandpipe");
|
2013-06-03 15:34:57 +02:00
|
|
|
foreach ($result as $command) {
|
|
|
|
$this->assertCommandSucceeded(false,$command);
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
$this->cleanup();
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
$this->cleanup();
|
|
|
|
}
|
|
|
|
|
2013-07-31 14:17:40 +02:00
|
|
|
/**
|
|
|
|
* Test whether enabling and disabling global notifications are send correctly to the pipe
|
|
|
|
*
|
|
|
|
* @throws \Exception|Exception
|
|
|
|
*/
|
2013-06-03 15:34:57 +02:00
|
|
|
public function testGlobalNotificationTrigger()
|
|
|
|
{
|
2013-07-31 14:17:40 +02:00
|
|
|
$pipe = $this->getLocalTestPipe();
|
2013-06-03 15:34:57 +02:00
|
|
|
try {
|
|
|
|
$pipe->enableGlobalNotifications();
|
|
|
|
$this->assertCommandSucceeded("ENABLE_NOTIFICATIONS;");
|
|
|
|
$pipe->disableGlobalNotifications();
|
|
|
|
$this->assertCommandSucceeded("DISABLE_NOTIFICATIONS;");
|
|
|
|
} catch (Exception $e) {
|
|
|
|
$this->cleanup();
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
$this->cleanup();
|
|
|
|
}
|
|
|
|
|
2013-07-31 14:17:40 +02:00
|
|
|
/**
|
|
|
|
* Test whether host and servicedowntimes are correctly scheduled
|
|
|
|
*
|
2013-09-05 10:55:32 +02:00
|
|
|
* @throws Exception
|
2013-07-31 14:17:40 +02:00
|
|
|
*/
|
2013-06-03 15:34:57 +02:00
|
|
|
public function testScheduleDowntime()
|
|
|
|
{
|
2013-07-31 14:17:40 +02:00
|
|
|
$pipe = $this->getLocalTestPipe();
|
2013-06-03 15:34:57 +02:00
|
|
|
try {
|
2013-09-05 10:55:32 +02:00
|
|
|
$downtime = new ScheduleDowntimeCommand(25, 26, new Comment("me", "test"));
|
|
|
|
$pipe->sendCommand(
|
|
|
|
$downtime,
|
|
|
|
array(
|
|
|
|
(object) array(
|
|
|
|
"host_name" => "Testhost"
|
|
|
|
)
|
2013-06-03 15:34:57 +02:00
|
|
|
)
|
2013-09-05 10:55:32 +02:00
|
|
|
);
|
2013-08-01 17:48:36 +02:00
|
|
|
$this->assertCommandSucceeded("SCHEDULE_HOST_DOWNTIME;Testhost;25;26;1;0;0;me;test");
|
2013-06-03 15:34:57 +02:00
|
|
|
|
2013-09-05 10:55:32 +02:00
|
|
|
$pipe->sendCommand(
|
|
|
|
$downtime,
|
|
|
|
array(
|
|
|
|
(object) array(
|
|
|
|
"host_name" => "Testhost",
|
|
|
|
"service_description" => "svc"
|
|
|
|
)
|
2013-06-03 15:34:57 +02:00
|
|
|
)
|
2013-09-05 10:55:32 +02:00
|
|
|
);
|
2013-08-01 17:48:36 +02:00
|
|
|
$this->assertCommandSucceeded("SCHEDULE_SVC_DOWNTIME;Testhost;svc;25;26;1;0;0;me;test");
|
2013-06-03 15:34:57 +02:00
|
|
|
} catch (Exception $e) {
|
|
|
|
$this->cleanup();
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
$this->cleanup();
|
|
|
|
}
|
|
|
|
|
2013-07-31 14:17:40 +02:00
|
|
|
/**
|
|
|
|
* Test whether the removal of downtimes is correctly serialized and send to the commandpipe for hosts and services
|
|
|
|
*
|
|
|
|
* @throws \Exception|Exception
|
|
|
|
*/
|
2013-06-03 15:34:57 +02:00
|
|
|
public function testRemoveDowntime()
|
|
|
|
{
|
2013-07-31 14:17:40 +02:00
|
|
|
$pipe = $this->getLocalTestPipe();
|
2013-06-03 15:34:57 +02:00
|
|
|
try {
|
2013-07-31 14:17:40 +02:00
|
|
|
$pipe->getTransport()->setOpenMode("a");
|
2013-06-03 15:34:57 +02:00
|
|
|
$pipe->removeDowntime(array(
|
|
|
|
(object) array(
|
|
|
|
"host_name" => "Testhost"
|
|
|
|
),
|
|
|
|
(object) array(
|
|
|
|
"host_name" => "host",
|
|
|
|
"service_description" => "svc"
|
|
|
|
),
|
|
|
|
(object) array(
|
|
|
|
"host_name" => "host",
|
|
|
|
"service_description" => "svc",
|
|
|
|
"downtime_id" => 123
|
|
|
|
)
|
|
|
|
));
|
|
|
|
$result = explode("\n",file_get_contents($this->getPipeName()));
|
|
|
|
array_pop($result); // remove empty last line
|
2013-07-31 14:17:40 +02:00
|
|
|
$this->assertCount(3,$result, "Asserting a correct number of commands being written to the commandpipe");
|
2013-06-03 15:34:57 +02:00
|
|
|
$this->assertCommandSucceeded("DEL_DOWNTIME_BY_HOST_NAME;Testhost",$result[0]);
|
|
|
|
$this->assertCommandSucceeded("DEL_DOWNTIME_BY_HOST_NAME;host;svc",$result[1]);
|
|
|
|
$this->assertCommandSucceeded("DEL_SVC_DOWNTIME;123",$result[2]);
|
|
|
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
$this->cleanup();
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
$this->cleanup();
|
|
|
|
}
|
|
|
|
|
2013-08-01 15:15:38 +02:00
|
|
|
/**
|
|
|
|
* Test whether custom servicenotifications are correctly send to the commandpipe without options
|
|
|
|
*
|
2013-09-05 13:30:43 +02:00
|
|
|
* @throws Exception
|
2013-08-01 15:15:38 +02:00
|
|
|
*/
|
|
|
|
public function testSendCustomServiceNotification()
|
|
|
|
{
|
|
|
|
$pipe = $this->getLocalTestPipe();
|
|
|
|
try {
|
2013-09-05 13:30:43 +02:00
|
|
|
$notification = new CustomNotificationCommand(new Comment('Author', 'Comment'));
|
|
|
|
$pipe->sendCommand(
|
|
|
|
$notification,
|
|
|
|
array(
|
|
|
|
(object) array(
|
|
|
|
'host_name' => 'Host',
|
|
|
|
'service_description' => 'Service'
|
|
|
|
)
|
2013-08-01 15:15:38 +02:00
|
|
|
)
|
|
|
|
);
|
2013-09-05 13:30:43 +02:00
|
|
|
$this->assertCommandSucceeded('SEND_CUSTOM_SVC_NOTIFICATION;Host;Service;0;Author;Comment');
|
2013-08-01 15:15:38 +02:00
|
|
|
} catch (Exception $e) {
|
|
|
|
$this->cleanup();
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
$this->cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test whether custom hostnotifications are correctly send to the commandpipe with a varlist of options
|
|
|
|
*
|
2013-09-05 13:30:43 +02:00
|
|
|
* @throws Exception
|
2013-08-01 15:15:38 +02:00
|
|
|
*/
|
|
|
|
public function testSendCustomHostNotificationWithOptions()
|
|
|
|
{
|
|
|
|
$pipe = $this->getLocalTestPipe();
|
|
|
|
try {
|
2013-09-05 13:30:43 +02:00
|
|
|
$notification = new CustomNotificationCommand(new Comment('Author', 'Comment'), true, true);
|
|
|
|
$pipe->sendCommand(
|
|
|
|
$notification,
|
|
|
|
array(
|
|
|
|
(object) array(
|
|
|
|
'host_name' => 'Host',
|
|
|
|
'service_description' => 'Service'
|
|
|
|
)
|
2013-08-01 15:15:38 +02:00
|
|
|
)
|
|
|
|
);
|
2013-09-05 13:30:43 +02:00
|
|
|
$this->assertCommandSucceeded('SEND_CUSTOM_SVC_NOTIFICATION;Host;Service;3;Author;Comment');
|
2013-08-01 15:15:38 +02:00
|
|
|
} catch (Exception $e) {
|
|
|
|
$this->cleanup();
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
$this->cleanup();
|
|
|
|
}
|
|
|
|
|
2013-09-05 14:00:38 +02:00
|
|
|
/**
|
|
|
|
* Test whether commands to delay notifications are being sent to the commandpipe
|
|
|
|
*
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
public function testDelayNotification()
|
|
|
|
{
|
|
|
|
$pipe = $this->getLocalTestPipe();
|
|
|
|
try {
|
|
|
|
$delay = new DelayNotificationCommand(300);
|
|
|
|
$pipe->sendCommand(
|
|
|
|
$delay,
|
|
|
|
array(
|
|
|
|
(object) array(
|
|
|
|
'host_name' => 'Host',
|
|
|
|
'service_description' => 'Service'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->assertCommandSucceeded('DELAY_SVC_NOTIFICATION;Host;Service;300');
|
|
|
|
|
|
|
|
$pipe->sendCommand(
|
|
|
|
$delay,
|
|
|
|
array(
|
|
|
|
(object) array(
|
|
|
|
'host_name' => 'Host'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->assertCommandSucceeded('DELAY_HOST_NOTIFICATION;Host;300');
|
|
|
|
} catch (Exception $e) {
|
|
|
|
$this->cleanup();
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
$this->cleanup();
|
|
|
|
}
|
|
|
|
|
2013-07-31 14:17:40 +02:00
|
|
|
/**
|
|
|
|
* Test sending of commands via SSH (currently disabled)
|
|
|
|
*
|
|
|
|
* @throws \Exception|Exception
|
|
|
|
*/
|
|
|
|
public function testSSHCommands()
|
|
|
|
{
|
|
|
|
$this->markTestSkipped("This test assumes running in a vagrant VM with key-auth");
|
|
|
|
|
|
|
|
if (!is_dir("/vagrant")) {
|
|
|
|
}
|
|
|
|
$pipe = $this->getSSHTestPipe();
|
|
|
|
try {
|
2013-09-04 16:21:44 +02:00
|
|
|
$ack = new AcknowledgeCommand(new Comment("I can", "sends teh ack"));
|
2013-09-04 10:50:00 +02:00
|
|
|
$pipe->sendCommand(
|
|
|
|
$ack,
|
|
|
|
array(
|
|
|
|
(object) array(
|
|
|
|
"host_name" => "hostA"
|
|
|
|
)
|
2013-07-31 14:17:40 +02:00
|
|
|
)
|
2013-09-04 10:50:00 +02:00
|
|
|
);
|
2013-07-31 14:17:40 +02:00
|
|
|
$this->assertCommandSucceeded("ACKNOWLEDGE_HOST_PROBLEM;hostA;0;0;0;I can;sends teh ack");
|
|
|
|
} catch(Exception $e) {
|
|
|
|
$this->cleanup();
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
$this->cleanup();
|
|
|
|
}
|
2013-06-03 15:34:57 +02:00
|
|
|
}
|