parent
8e60e2dcd9
commit
4964d84e78
|
@ -28,10 +28,11 @@
|
||||||
|
|
||||||
namespace Tests\Icinga\Protocol\Commandpipe;
|
namespace Tests\Icinga\Protocol\Commandpipe;
|
||||||
|
|
||||||
require_once(__DIR__.'/CommandPipeLoader.php');
|
require_once(realpath(__DIR__ . '/CommandPipeLoader.php'));
|
||||||
CommandPipeLoader::requireLibrary();
|
CommandPipeLoader::requireLibrary();
|
||||||
|
|
||||||
use Zend_Config;
|
use Zend_Config;
|
||||||
|
use PHPUnit_Framework_TestCase;
|
||||||
use Icinga\Protocol\Commandpipe\Comment;
|
use Icinga\Protocol\Commandpipe\Comment;
|
||||||
use Icinga\Protocol\Commandpipe\Commandpipe as Commandpipe;
|
use Icinga\Protocol\Commandpipe\Commandpipe as Commandpipe;
|
||||||
use Icinga\Protocol\Commandpipe\PropertyModifier as MONFLAG;
|
use Icinga\Protocol\Commandpipe\PropertyModifier as MONFLAG;
|
||||||
|
@ -44,8 +45,8 @@ use Icinga\Module\Monitoring\Command\DelayNotificationCommand;
|
||||||
use Icinga\Module\Monitoring\Command\ScheduleCheckCommand;
|
use Icinga\Module\Monitoring\Command\ScheduleCheckCommand;
|
||||||
use Icinga\Module\Monitoring\Command\SubmitPassiveCheckresultCommand;
|
use Icinga\Module\Monitoring\Command\SubmitPassiveCheckresultCommand;
|
||||||
|
|
||||||
if (!defined("EXTCMD_TEST_BIN")) {
|
if (!defined('EXTCMD_TEST_BIN')) {
|
||||||
define("EXTCMD_TEST_BIN", "./bin/extcmd_test");
|
define('EXTCMD_TEST_BIN', './bin/extcmd_test');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -53,10 +54,8 @@ if (!defined("EXTCMD_TEST_BIN")) {
|
||||||
*
|
*
|
||||||
* Uses the helper script extcmd_test, which is basically the extracted command
|
* Uses the helper script extcmd_test, which is basically the extracted command
|
||||||
* parser functions from the icinga core
|
* parser functions from the icinga core
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
class CommandPipeTest extends PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Return the path of the test pipe used in these tests
|
* Return the path of the test pipe used in these tests
|
||||||
|
@ -65,7 +64,7 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
public function getPipeName()
|
public function getPipeName()
|
||||||
{
|
{
|
||||||
return sys_get_temp_dir()."/icinga_test_pipe";
|
return sys_get_temp_dir() . '/icinga_test_pipe';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -81,8 +80,8 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$cfg = new Zend_Config(
|
$cfg = new Zend_Config(
|
||||||
array(
|
array(
|
||||||
"path" => $tmpPipe,
|
'path' => $tmpPipe,
|
||||||
"name" => "test"
|
'name' => 'test'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -90,7 +89,8 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a @see Icinga\Protocal\CommandPipe\CommandPipe instance set up for the local test pipe, but with ssh as the transport layer
|
* Return a @see Icinga\Protocal\CommandPipe\CommandPipe instance set up
|
||||||
|
* for the local test pipe, but with ssh as the transport layer
|
||||||
*
|
*
|
||||||
* @return Commandpipe
|
* @return Commandpipe
|
||||||
*/
|
*/
|
||||||
|
@ -102,12 +102,12 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$cfg = new Zend_Config(
|
$cfg = new Zend_Config(
|
||||||
array(
|
array(
|
||||||
"path" => $tmpPipe,
|
'path' => $tmpPipe,
|
||||||
"user" => "vagrant",
|
'user' => 'vagrant',
|
||||||
"password" => "vagrant",
|
'password' => 'vagrant',
|
||||||
"host" => 'localhost',
|
'host' => 'localhost',
|
||||||
"port" => 22,
|
'port' => 22,
|
||||||
"name" => "test"
|
'name' => 'test'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -116,11 +116,11 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove the testpipe if it exists
|
* Remove the testpipe if it exists
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
private function cleanup() {
|
private function cleanup() {
|
||||||
if(file_exists($this->getPipeName()))
|
if (file_exists($this->getPipeName())) {
|
||||||
unlink($this->getPipeName());
|
unlink($this->getPipeName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -137,39 +137,43 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
||||||
* (optional, leave it to just test for the return code)
|
* (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)
|
* @param bool $command The commandstring to send (optional, leave it for using the command pipe content)
|
||||||
*/
|
*/
|
||||||
private function assertCommandSucceeded($expectedString = false,$command = false) {
|
private function assertCommandSucceeded($expectedString = false, $command = false) {
|
||||||
$resultCode = null;
|
$resultCode = null;
|
||||||
$resultArr = array();
|
$resultArr = array();
|
||||||
$receivedCmd = exec(EXTCMD_TEST_BIN." ".escapeshellarg($command ? $command : file_get_contents($this->getPipeName())),$resultArr,$resultCode);
|
$receivedCmd = exec(EXTCMD_TEST_BIN . ' ' . escapeshellarg(
|
||||||
$this->assertEquals(0, $resultCode, "Submit of external command returned error : ".$receivedCmd);
|
$command ? $command : file_get_contents($this->getPipeName())),
|
||||||
if (!$expectedString)
|
$resultArr,
|
||||||
return;
|
$resultCode
|
||||||
$this->assertEquals(
|
|
||||||
$expectedString,
|
|
||||||
$receivedCmd,
|
|
||||||
'Asserting that the command icinga received matches the command we send'
|
|
||||||
);
|
);
|
||||||
|
$this->assertEquals(0, $resultCode, 'Submit of external command returned error : ' . $receivedCmd);
|
||||||
|
if ($expectedString) {
|
||||||
|
$this->assertEquals(
|
||||||
|
$expectedString,
|
||||||
|
$receivedCmd,
|
||||||
|
'Asserting that the command icinga received matches the command we send'
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test whether a single host acknowledgment is serialized and send correctly
|
* Test whether a single host acknowledgment is serialized and send correctly
|
||||||
*
|
*
|
||||||
* @throws \Exception|Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function testAcknowledgeSingleHost()
|
public function testAcknowledgeSingleHost()
|
||||||
{
|
{
|
||||||
$pipe = $this->getLocalTestPipe();
|
$pipe = $this->getLocalTestPipe();
|
||||||
try {
|
try {
|
||||||
$ack = new AcknowledgeCommand(new Comment("I can", "sends teh ack"));
|
$ack = new AcknowledgeCommand(new Comment('I can', 'sends teh ack'));
|
||||||
$pipe->sendCommand(
|
$pipe->sendCommand(
|
||||||
$ack,
|
$ack,
|
||||||
array(
|
array(
|
||||||
(object) array(
|
(object) array(
|
||||||
"host_name" => "hostA"
|
'host_name' => 'hostA'
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$this->assertCommandSucceeded("ACKNOWLEDGE_HOST_PROBLEM;hostA;0;0;0;I can;sends teh ack");
|
$this->assertCommandSucceeded('ACKNOWLEDGE_HOST_PROBLEM;hostA;0;0;0;I can;sends teh ack');
|
||||||
} catch(Exception $e) {
|
} catch(Exception $e) {
|
||||||
$this->cleanup();
|
$this->cleanup();
|
||||||
throw $e;
|
throw $e;
|
||||||
|
@ -180,37 +184,37 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
||||||
/**
|
/**
|
||||||
* Test whether multiple host and service acknowledgments are serialized and send correctly
|
* Test whether multiple host and service acknowledgments are serialized and send correctly
|
||||||
*
|
*
|
||||||
* @throws \Exception|Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function testAcknowledgeMultipleObjects()
|
public function testAcknowledgeMultipleObjects()
|
||||||
{
|
{
|
||||||
$pipe = $this->getLocalTestPipe();
|
$pipe = $this->getLocalTestPipe();
|
||||||
try {
|
try {
|
||||||
$ack = new AcknowledgeCommand(new Comment("I can", "sends teh ack"));
|
$ack = new AcknowledgeCommand(new Comment('I can', 'sends teh ack'));
|
||||||
$pipe->getTransport()->setOpenMode("a");
|
$pipe->getTransport()->setOpenMode('a');
|
||||||
$pipe->sendCommand(
|
$pipe->sendCommand(
|
||||||
$ack,
|
$ack,
|
||||||
array(
|
array(
|
||||||
(object) array(
|
(object) array(
|
||||||
"host_name" => "hostA"
|
'host_name' => 'hostA'
|
||||||
),(object) array(
|
),(object) array(
|
||||||
"host_name" => "hostB"
|
'host_name' => 'hostB'
|
||||||
),(object) array(
|
),(object) array(
|
||||||
"host_name" => "hostC"
|
'host_name' => 'hostC'
|
||||||
),(object) array(
|
),(object) array(
|
||||||
"host_name" => "hostC",
|
'host_name' => 'hostC',
|
||||||
"service_description" => "svc"
|
'service_description' => 'svc'
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$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->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;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;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_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_SVC_PROBLEM;hostC;svc;0;0;0;I can;sends teh ack', $result[3]);
|
||||||
|
|
||||||
} catch(Exception $e) {
|
} catch(Exception $e) {
|
||||||
$this->cleanup();
|
$this->cleanup();
|
||||||
|
@ -231,17 +235,17 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
||||||
$pipe->sendCommand(
|
$pipe->sendCommand(
|
||||||
new AddCommentCommand(
|
new AddCommentCommand(
|
||||||
new Comment(
|
new Comment(
|
||||||
"Autor",
|
'Autor',
|
||||||
"Comment"
|
'Comment'
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
(object) array(
|
(object) array(
|
||||||
"host_name" => "hostA"
|
'host_name' => 'hostA'
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$this->assertCommandSucceeded("ADD_HOST_COMMENT;hostA;0;Autor;Comment");
|
$this->assertCommandSucceeded('ADD_HOST_COMMENT;hostA;0;Autor;Comment');
|
||||||
} catch(Exception $e) {
|
} catch(Exception $e) {
|
||||||
$this->cleanup();
|
$this->cleanup();
|
||||||
throw $e;
|
throw $e;
|
||||||
|
@ -252,18 +256,20 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
||||||
/**
|
/**
|
||||||
* Test whether removing all hostcomments is correctly serialized and send to the command pipe
|
* Test whether removing all hostcomments is correctly serialized and send to the command pipe
|
||||||
*
|
*
|
||||||
* @throws \Exception|Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function testRemoveAllHostComment()
|
public function testRemoveAllHostComment()
|
||||||
{
|
{
|
||||||
$pipe = $this->getLocalTestPipe();
|
$pipe = $this->getLocalTestPipe();
|
||||||
try {
|
try {
|
||||||
$pipe->removeComment(array(
|
$pipe->removeComment(
|
||||||
(object) array(
|
array(
|
||||||
"host_name" => "test"
|
(object) array(
|
||||||
|
'host_name' => 'test'
|
||||||
|
)
|
||||||
)
|
)
|
||||||
));
|
);
|
||||||
$this->assertCommandSucceeded("DEL_ALL_HOST_COMMENTS;test");
|
$this->assertCommandSucceeded('DEL_ALL_HOST_COMMENTS;test');
|
||||||
} catch(Exception $e) {
|
} catch(Exception $e) {
|
||||||
$this->cleanup();
|
$this->cleanup();
|
||||||
throw $e;
|
throw $e;
|
||||||
|
@ -274,14 +280,21 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
||||||
/**
|
/**
|
||||||
* Test whether removing a single host comment is correctly serialized and send to the command pipe
|
* Test whether removing a single host comment is correctly serialized and send to the command pipe
|
||||||
*
|
*
|
||||||
* @throws \Exception|Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function testRemoveSpecificComment()
|
public function testRemoveSpecificComment()
|
||||||
{
|
{
|
||||||
$pipe = $this->getLocalTestPipe();
|
$pipe = $this->getLocalTestPipe();
|
||||||
try {
|
try {
|
||||||
$pipe->removeComment(array((object) array("comment_id"=>34,"host_name"=>"test")));
|
$pipe->removeComment(
|
||||||
$this->assertCommandSucceeded("DEL_HOST_COMMENT;34");
|
array(
|
||||||
|
(object) array(
|
||||||
|
'comment_id' => 34,
|
||||||
|
'host_name' => 'test'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->assertCommandSucceeded('DEL_HOST_COMMENT;34');
|
||||||
} catch(Exception $e) {
|
} catch(Exception $e) {
|
||||||
$this->cleanup();
|
$this->cleanup();
|
||||||
throw $e;
|
throw $e;
|
||||||
|
@ -292,7 +305,7 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
||||||
/**
|
/**
|
||||||
* Test whether a multiple reschedules for services and hosts are correctly serialized and send to the commandpipe
|
* Test whether a multiple reschedules for services and hosts are correctly serialized and send to the commandpipe
|
||||||
*
|
*
|
||||||
* @throws \Exception|Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function testScheduleChecks()
|
public function testScheduleChecks()
|
||||||
{
|
{
|
||||||
|
@ -304,10 +317,10 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
||||||
$command,
|
$command,
|
||||||
array(
|
array(
|
||||||
(object) array(
|
(object) array(
|
||||||
'host_name' => 'test'
|
'host_name' => 'test'
|
||||||
),
|
),
|
||||||
(object) array(
|
(object) array(
|
||||||
'host_name' => 'test',
|
'host_name' => 'test',
|
||||||
'service_description' => 'svc1'
|
'service_description' => 'svc1'
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -317,10 +330,10 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
||||||
$command,
|
$command,
|
||||||
array(
|
array(
|
||||||
(object) array(
|
(object) array(
|
||||||
'host_name' => 'test'
|
'host_name' => 'test'
|
||||||
),
|
),
|
||||||
(object) array(
|
(object) array(
|
||||||
'host_name' => 'test',
|
'host_name' => 'test',
|
||||||
'service_description' => 'svc1'
|
'service_description' => 'svc1'
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -353,36 +366,39 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
||||||
/**
|
/**
|
||||||
* Test whether modifying monitoringflags of a host and service is correctly serialized and send to the command pipe
|
* Test whether modifying monitoringflags of a host and service is correctly serialized and send to the command pipe
|
||||||
*
|
*
|
||||||
* @throws \Exception|Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function testObjectStateModifications()
|
public function testObjectStateModifications()
|
||||||
{
|
{
|
||||||
$pipe = $this->getLocalTestPipe();
|
$pipe = $this->getLocalTestPipe();
|
||||||
try {
|
try {
|
||||||
$pipe->getTransport()->setOpenMode("a");
|
$pipe->getTransport()->setOpenMode('a');
|
||||||
$pipe->setMonitoringProperties(array(
|
$pipe->setMonitoringProperties(
|
||||||
|
array(
|
||||||
(object) array(
|
(object) array(
|
||||||
"host_name" => "Testhost"
|
'host_name' => 'Testhost'
|
||||||
),
|
),
|
||||||
(object) array(
|
(object) array(
|
||||||
"host_name" => "host",
|
'host_name' => 'host',
|
||||||
"service_description" => "svc"
|
'service_description' => 'svc'
|
||||||
)
|
)
|
||||||
), new MONFLAG(array(
|
), new MONFLAG(
|
||||||
MONFLAG::ACTIVE => MONFLAG::STATE_DISABLE,
|
array(
|
||||||
MONFLAG::PASSIVE => MONFLAG::STATE_ENABLE,
|
MONFLAG::ACTIVE => MONFLAG::STATE_DISABLE,
|
||||||
MONFLAG::NOTIFICATIONS => MONFLAG::STATE_DISABLE,
|
MONFLAG::PASSIVE => MONFLAG::STATE_ENABLE,
|
||||||
MONFLAG::EVENTHANDLER => MONFLAG::STATE_ENABLE,
|
MONFLAG::NOTIFICATIONS => MONFLAG::STATE_DISABLE,
|
||||||
MONFLAG::FLAPPING => MONFLAG::STATE_DISABLE,
|
MONFLAG::EVENTHANDLER => MONFLAG::STATE_ENABLE,
|
||||||
MONFLAG::FRESHNESS => MONFLAG::STATE_ENABLE,
|
MONFLAG::FLAPPING => MONFLAG::STATE_DISABLE,
|
||||||
))
|
MONFLAG::FRESHNESS => MONFLAG::STATE_ENABLE,
|
||||||
|
)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$result = explode("\n",file_get_contents($this->getPipeName()));
|
$result = explode("\n", file_get_contents($this->getPipeName()));
|
||||||
array_pop($result); // remove empty last line
|
array_pop($result); // remove empty last line
|
||||||
$this->assertCount(12,$result, "Asserting a correct number of commands being written to the commandpipe");
|
$this->assertCount(12, $result, 'Asserting a correct number of commands being written to the commandpipe');
|
||||||
foreach ($result as $command) {
|
foreach ($result as $command) {
|
||||||
$this->assertCommandSucceeded(false,$command);
|
$this->assertCommandSucceeded(false, $command);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
|
@ -395,16 +411,16 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
||||||
/**
|
/**
|
||||||
* Test whether enabling and disabling global notifications are send correctly to the pipe
|
* Test whether enabling and disabling global notifications are send correctly to the pipe
|
||||||
*
|
*
|
||||||
* @throws \Exception|Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function testGlobalNotificationTrigger()
|
public function testGlobalNotificationTrigger()
|
||||||
{
|
{
|
||||||
$pipe = $this->getLocalTestPipe();
|
$pipe = $this->getLocalTestPipe();
|
||||||
try {
|
try {
|
||||||
$pipe->enableGlobalNotifications();
|
$pipe->enableGlobalNotifications();
|
||||||
$this->assertCommandSucceeded("ENABLE_NOTIFICATIONS;");
|
$this->assertCommandSucceeded('ENABLE_NOTIFICATIONS;');
|
||||||
$pipe->disableGlobalNotifications();
|
$pipe->disableGlobalNotifications();
|
||||||
$this->assertCommandSucceeded("DISABLE_NOTIFICATIONS;");
|
$this->assertCommandSucceeded('DISABLE_NOTIFICATIONS;');
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$this->cleanup();
|
$this->cleanup();
|
||||||
throw $e;
|
throw $e;
|
||||||
|
@ -503,33 +519,35 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
||||||
/**
|
/**
|
||||||
* Test whether the removal of downtimes is correctly serialized and send to the commandpipe for hosts and services
|
* Test whether the removal of downtimes is correctly serialized and send to the commandpipe for hosts and services
|
||||||
*
|
*
|
||||||
* @throws \Exception|Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function testRemoveDowntime()
|
public function testRemoveDowntime()
|
||||||
{
|
{
|
||||||
$pipe = $this->getLocalTestPipe();
|
$pipe = $this->getLocalTestPipe();
|
||||||
try {
|
try {
|
||||||
$pipe->getTransport()->setOpenMode("a");
|
$pipe->getTransport()->setOpenMode('a');
|
||||||
$pipe->removeDowntime(array(
|
$pipe->removeDowntime(
|
||||||
(object) array(
|
array(
|
||||||
"host_name" => "Testhost"
|
(object) array(
|
||||||
),
|
'host_name' => 'Testhost'
|
||||||
(object) array(
|
),
|
||||||
"host_name" => "host",
|
(object) array(
|
||||||
"service_description" => "svc"
|
'host_name' => 'host',
|
||||||
),
|
'service_description' => 'svc'
|
||||||
(object) array(
|
),
|
||||||
"host_name" => "host",
|
(object) array(
|
||||||
"service_description" => "svc",
|
'host_name' => 'host',
|
||||||
"downtime_id" => 123
|
'service_description' => 'svc',
|
||||||
|
'downtime_id' => 123
|
||||||
|
)
|
||||||
)
|
)
|
||||||
));
|
);
|
||||||
$result = explode("\n",file_get_contents($this->getPipeName()));
|
$result = explode("\n", file_get_contents($this->getPipeName()));
|
||||||
array_pop($result); // remove empty last line
|
array_pop($result); // remove empty last line
|
||||||
$this->assertCount(3,$result, "Asserting a correct number of commands being written to the commandpipe");
|
$this->assertCount(3, $result, 'Asserting a correct number of commands being written to the commandpipe');
|
||||||
$this->assertCommandSucceeded("DEL_DOWNTIME_BY_HOST_NAME;Testhost",$result[0]);
|
$this->assertCommandSucceeded('DEL_DOWNTIME_BY_HOST_NAME;Testhost', $result[0]);
|
||||||
$this->assertCommandSucceeded("DEL_DOWNTIME_BY_HOST_NAME;host;svc",$result[1]);
|
$this->assertCommandSucceeded('DEL_DOWNTIME_BY_HOST_NAME;host;svc', $result[1]);
|
||||||
$this->assertCommandSucceeded("DEL_SVC_DOWNTIME;123",$result[2]);
|
$this->assertCommandSucceeded('DEL_SVC_DOWNTIME;123', $result[2]);
|
||||||
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$this->cleanup();
|
$this->cleanup();
|
||||||
|
@ -671,26 +689,24 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
||||||
/**
|
/**
|
||||||
* Test sending of commands via SSH (currently disabled)
|
* Test sending of commands via SSH (currently disabled)
|
||||||
*
|
*
|
||||||
* @throws \Exception|Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function testSSHCommands()
|
public function testSSHCommands()
|
||||||
{
|
{
|
||||||
$this->markTestSkipped("This test assumes running in a vagrant VM with key-auth");
|
$this->markTestSkipped('This test assumes running in a vagrant VM with key-auth');
|
||||||
|
|
||||||
if (!is_dir("/vagrant")) {
|
|
||||||
}
|
|
||||||
$pipe = $this->getSSHTestPipe();
|
$pipe = $this->getSSHTestPipe();
|
||||||
try {
|
try {
|
||||||
$ack = new AcknowledgeCommand(new Comment("I can", "sends teh ack"));
|
$ack = new AcknowledgeCommand(new Comment('I can', 'sends teh ack'));
|
||||||
$pipe->sendCommand(
|
$pipe->sendCommand(
|
||||||
$ack,
|
$ack,
|
||||||
array(
|
array(
|
||||||
(object) array(
|
(object) array(
|
||||||
"host_name" => "hostA"
|
'host_name' => 'hostA'
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$this->assertCommandSucceeded("ACKNOWLEDGE_HOST_PROBLEM;hostA;0;0;0;I can;sends teh ack");
|
$this->assertCommandSucceeded('ACKNOWLEDGE_HOST_PROBLEM;hostA;0;0;0;I can;sends teh ack');
|
||||||
} catch(Exception $e) {
|
} catch(Exception $e) {
|
||||||
$this->cleanup();
|
$this->cleanup();
|
||||||
throw $e;
|
throw $e;
|
||||||
|
|
Loading…
Reference in New Issue