parent
34822d9a02
commit
746cc4b5d9
|
@ -27,20 +27,10 @@
|
|||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Tests\Icinga\Authentication;
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once realpath(__DIR__ . '/../../../../../library/Icinga/Test/BaseTestCase.php');
|
||||
// @codingStandardsIgnoreEnd
|
||||
namespace Icinga\Test\Authentication;
|
||||
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once 'Zend/Config.php';
|
||||
require_once BaseTestCase::$libDir . '/Authentication/Credential.php';
|
||||
require_once BaseTestCase::$libDir . '/Authentication/UserBackend.php';
|
||||
require_once BaseTestCase::$libDir . '/User.php';
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
use \Zend_Config;
|
||||
use \Icinga\Authentication\Credential;
|
|
@ -27,20 +27,10 @@
|
|||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Tests\Icinga\Authentication;
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once realpath(__DIR__ . '/../../../../../library/Icinga/Test/BaseTestCase.php');
|
||||
// @codingStandardsIgnoreEnd
|
||||
namespace Icinga\Test\Authentication;
|
||||
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once 'Zend/Config.php';
|
||||
require_once BaseTestCase::$libDir . '/Authentication/Credential.php';
|
||||
require_once BaseTestCase::$libDir . '/Authentication/UserBackend.php';
|
||||
require_once BaseTestCase::$libDir . '/User.php';
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
use \Exception;
|
||||
use \Zend_Config;
|
|
@ -27,10 +27,7 @@
|
|||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Tests\Icinga\Authentication;
|
||||
|
||||
require_once("../../library/Icinga/Session/SessionNamespace.php");
|
||||
require_once("../../library/Icinga/Session/Session.php");
|
||||
namespace Icinga\Test\Authentication;
|
||||
|
||||
use Icinga\Web\Session\Session;
|
||||
|
|
@ -1,103 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Icinga\Modules\Monitoring\Test\Application\Controllers\ListController;
|
||||
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
use Test\Monitoring\Testlib\MonitoringControllerTest;
|
||||
use Test\Monitoring\Testlib\Datasource\TestFixture;
|
||||
use Test\Monitoring\Testlib\Datasource\ObjectFlags;
|
||||
|
||||
class ListControllerHostMySQLTest extends MonitoringControllerTest
|
||||
{
|
||||
|
||||
public function testHostListMySQL()
|
||||
{
|
||||
$this->executeHostListTestFor("mysql");
|
||||
}
|
||||
|
||||
public function testHostListPgSQL()
|
||||
{
|
||||
$this->executeHostListTestFor("pgsql");
|
||||
}
|
||||
|
||||
public function testHostListStatus()
|
||||
{
|
||||
$this->executeHostListTestFor("statusdat");
|
||||
}
|
||||
|
||||
public function executeHostListTestFor($backend)
|
||||
{
|
||||
date_default_timezone_set('UTC');
|
||||
$checkTime = (string)(time()-2000);
|
||||
$fixture = new TestFixture();
|
||||
$firstHostFlags = ObjectFlags::PASSIVE_ONLY();
|
||||
$firstHostFlags->acknowledged = 1;
|
||||
$firstHostFlags->in_downtime = 1;
|
||||
$firstHostFlags->has_been_checked = 1;
|
||||
$firstHostFlags->notifications = 0;
|
||||
$firstHostFlags->flapping = 1;
|
||||
$firstHostFlags->time = $checkTime;
|
||||
|
||||
$fixture->addHost('host1', 1, $firstHostFlags, array(
|
||||
"address" => "10.92.1.5",
|
||||
"has_been_checked" => 1,
|
||||
"icon_image" => "myIcon.png",
|
||||
"notes_url" => "note1.html",
|
||||
"action_url" => "action.html"))->
|
||||
addToHostgroup('router')->
|
||||
addComment('author', 'host comment text')->
|
||||
addService('svc1', 2)->
|
||||
addService('svc2', 2)->
|
||||
addService('svc3', 2, ObjectFlags::ACKNOWLEDGED())->
|
||||
addService('svc4', 0);
|
||||
$fixture->addHost('host2', 1)->
|
||||
addService('svc1', 2);
|
||||
$fixture->addHost('host3', 0)->
|
||||
addService('svc1', 0);
|
||||
$fixture->addHost('host4', 0)->
|
||||
addService('svc1', 0);
|
||||
$fixture->addHost('host5', 2, ObjectFlags::ACKNOWLEDGED())->
|
||||
addService('svc1', 3)->addComment('author','svc comment');
|
||||
|
||||
try {
|
||||
$this->setupFixture($fixture, $backend);
|
||||
} catch (\PDOException $e) {
|
||||
echo $e->getMessage();
|
||||
$this->markTestSkipped('Could not setup fixture for backends '.$backend.' :'.$e->getMessage());
|
||||
return null;
|
||||
}
|
||||
$controller = $this->requireController('ListController', $backend);
|
||||
$controller->hostsAction();
|
||||
$result = $controller->view->hosts;
|
||||
|
||||
$this->assertEquals(5, $result->getTotalItemCount(), 'Testing correct result count for '.$backend);
|
||||
|
||||
$result = $result->getAdapter()->getItems(0,6);
|
||||
for($i=1;$i<=5;$i++) {
|
||||
$this->assertEquals('host'.$i, $result[$i-1]->host_name, "Asserting correct host names for backend ".$backend);
|
||||
}
|
||||
|
||||
$hostToTest = $result[0];
|
||||
$persistedLastCheck = explode("+", $hostToTest->host_last_check);
|
||||
$persistedLastCheck = $persistedLastCheck[0];
|
||||
$this->assertEquals("10.92.1.5", $hostToTest->host_address, "Testing for correct host address field (backend ".$backend.")");
|
||||
// commented out due to failing tests when delay is too long
|
||||
// $this->assertEquals(date("Y-m-d H:i:s", intval($checkTime)), $persistedLastCheck, "Testing for correct last check time format (backend ".$backend.")");
|
||||
//$this->assertEquals($checkTime, $hostToTest->host_last_state_change, "Testing for correct last state change (backend ".$backend.")");
|
||||
$this->assertEquals("Plugin output for host host1", $hostToTest->host_output, "Testing correct output for host (backend ".$backend.")");
|
||||
$this->assertEquals("Long plugin output for host host1", $hostToTest->host_long_output, "Testing correct long output for host (backend ".$backend.")");
|
||||
$this->assertEquals(0, $hostToTest->host_notifications_enabled, "Testing for disabled notifications (backend ".$backend.')');
|
||||
$this->assertEquals(1, $hostToTest->host_acknowledged, "Testing for host being acknowledged (backend ".$backend.')');
|
||||
$this->assertEquals(1, $hostToTest->host_in_downtime, "Testing for host being in downtime (backend ".$backend.')');
|
||||
$this->assertEquals(1, $hostToTest->host_is_flapping, "Testing for host being flapping (backend ".$backend.')');
|
||||
$this->assertEquals(1, $hostToTest->host_last_comment, 'Testing correct comment count for first host (backend '.$backend.')');
|
||||
$this->assertEquals(0, $hostToTest->host_state_type, 'Testing for soft state');
|
||||
$this->assertEquals(1, $hostToTest->host_handled, 'Testing for handled host (backend '.$backend.')');
|
||||
$this->assertEquals("myIcon.png", $hostToTest->host_icon_image, 'Testing for icon image (backend '.$backend.')');
|
||||
$this->assertEquals("note1.html", $hostToTest->host_notes_url, 'Testing for notes url (backend '.$backend.')');
|
||||
$this->assertEquals("action.html", $hostToTest->host_action_url, 'Testing for action url (backend '.$backend.')');
|
||||
$this->assertEquals(2, $hostToTest->host_unhandled_service_count, 'Testing correct open problems count (backend '.$backend.')');
|
||||
}
|
||||
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Test\Monitoring\Application\Controllers\ListController;
|
||||
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
require_once realpath(__DIR__ . '/../../../../../../library/Icinga/Test/BaseTestCase.php');
|
||||
|
||||
require_once(realpath(BaseTestCase::$moduleDir . '/monitoring/test/php/testlib/MonitoringControllerTest.php'));
|
||||
require_once(realpath(BaseTestCase::$libDir . '/Data/Db/TreeToSqlParser.php'));
|
||||
require_once(realpath(BaseTestCase::$moduleDir . '/monitoring/library/Monitoring/DataView/DataView.php'));
|
||||
require_once(realpath(BaseTestCase::$moduleDir . '/monitoring/library/Monitoring/DataView/ServiceStatus.php'));
|
||||
require_once(realpath(BaseTestCase::$moduleDir . '/monitoring/library/Monitoring/DataView/Notification.php'));
|
||||
require_once(realpath(BaseTestCase::$moduleDir . '/monitoring/library/Monitoring/DataView/Downtime.php'));
|
||||
|
||||
use Test\Monitoring\Testlib\MonitoringControllerTest;
|
||||
use Test\Monitoring\Testlib\Datasource\TestFixture;
|
||||
use Test\Monitoring\Testlib\Datasource\ObjectFlags;
|
||||
|
||||
class ListControllerServiceMySQLTest extends MonitoringControllerTest
|
||||
{
|
||||
|
||||
public function testServiceListMySQL()
|
||||
{
|
||||
$this->executeServiceListTestFor("mysql");
|
||||
}
|
||||
|
||||
public function testServiceListPgSQL()
|
||||
{
|
||||
$this->executeServiceListTestFor("pgsql");
|
||||
}
|
||||
|
||||
// public function testServiceListStatusdat()
|
||||
// {
|
||||
// $this->executeServiceListTestFor("statusdat");
|
||||
// }
|
||||
|
||||
public function executeServiceListTestFor($backend)
|
||||
{
|
||||
date_default_timezone_set('UTC');
|
||||
$checkTime = time()-2000;
|
||||
$fixture = new TestFixture();
|
||||
$fixture->addHost('host1', 0)->
|
||||
addService("svc1", 0, new ObjectFlags(2000), array(
|
||||
"notes_url" => "notes.url",
|
||||
"action_url" => "action.url",
|
||||
"icon_image" => "svcIcon.png"
|
||||
))->
|
||||
addService("svcDown", 2) -> addComment("author", "Comment text")->
|
||||
addService("svcFlapping", 1, ObjectFlags::FLAPPING())->addToServicegroup("Warning")->
|
||||
addService("svcNotifDisabled", 2, ObjectFlags::DISABLE_NOTIFICATIONS())->
|
||||
addService("svcPending", 0, ObjectFlags::PENDING());
|
||||
$fixture->addHost('host2', 1)->
|
||||
addService("svcPassive", 1, ObjectFlags::PASSIVE_ONLY())->addToServicegroup("Warning")->
|
||||
addService("svcDisabled", 1, ObjectFlags::DISABLED())->addToServicegroup("Warning")->
|
||||
addService("svcDowntime", 2, ObjectFlags::IN_DOWNTIME())->
|
||||
addService("svcAcknowledged", 1, ObjectFlags::ACKNOWLEDGED())->addToServicegroup("Warning");
|
||||
try {
|
||||
$this->setupFixture($fixture, $backend);
|
||||
} catch (\PDOException $e) {
|
||||
echo $e->getMessage();
|
||||
$this->markTestSkipped('Could not setup fixture for backends '.$backend.' :'.$e->getMessage());
|
||||
return null;
|
||||
}
|
||||
|
||||
$controller = $this->requireController('ListController', $backend);
|
||||
$controller->servicesAction();
|
||||
|
||||
$result = $controller->view->services;
|
||||
|
||||
$this->assertEquals(9, $result->getTotalItemCount(), "Testing for correct service count");
|
||||
$result = $result->getAdapter()->getItems(0,1);
|
||||
$this->assertEquals("notes.url", $result[0]->service_notes_url, "Testing for correct notes_url");
|
||||
$this->assertEquals("action.url", $result[0]->service_action_url, "Testing for correct action_url");
|
||||
$this->assertEquals(0, $result[0]->service_state, "Testing for correct Service state");
|
||||
}
|
||||
|
||||
}
|
|
@ -1,310 +0,0 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - 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\Testlib;
|
||||
|
||||
require_once 'Zend/View.php';
|
||||
require_once 'Zend/Test/PHPUnit/ControllerTestCase.php';
|
||||
|
||||
use \Zend_View;
|
||||
use \Zend_Config;
|
||||
use \Zend_Test_PHPUnit_ControllerTestCase;
|
||||
use \Icinga\Protocol\Statusdat\Reader;
|
||||
use \Icinga\Web\Controller\ActionController;
|
||||
use \Test\Monitoring\Testlib\DataSource\TestFixture;
|
||||
use \Test\Monitoring\Testlib\DataSource\DataSourceTestSetup;
|
||||
use Icinga\Module\Monitoring\Backend;
|
||||
use Icinga\Data\ResourceFactory;
|
||||
|
||||
/**
|
||||
* Base class for monitoring controllers that loads required dependencies
|
||||
* and allows easier setup of tests
|
||||
*
|
||||
* Example:
|
||||
* <code>
|
||||
*
|
||||
* class MyControllerTest extends MonitoringControllerTest
|
||||
* {
|
||||
* public function testSomething()
|
||||
* {
|
||||
* // Create a test fixture
|
||||
* $fixture = new TestFixture()
|
||||
* $fixture->addHost('host', 0)->addService(...)->..->;
|
||||
*
|
||||
* $this->setupFixture($fixture, "mysql"); // setup the fixture
|
||||
* $controller = $this->requireController('MyController', 'mysql');
|
||||
* // controller is now the Zend controller instance, perform an action
|
||||
* $controller->myAction();
|
||||
* $result = $controller->view->hosts->fetchAll();
|
||||
* // assert stuff
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
abstract class MonitoringControllerTest extends Zend_Test_PHPUnit_ControllerTestCase
|
||||
{
|
||||
/**
|
||||
* The module directory for requiring modules (is relative to the source file)
|
||||
* @var string
|
||||
*/
|
||||
private $moduleDir = "";
|
||||
|
||||
/**
|
||||
* The application directory for requirying library files (is relative to the source file)
|
||||
* @var string
|
||||
*/
|
||||
private $appDir = "";
|
||||
|
||||
/**
|
||||
* Require necessary libraries on test creation
|
||||
*
|
||||
* This is called for every test and assures that all required libraries for the controllers
|
||||
* are loaded. If you need additional dependencies you should overwrite this method, call the parent
|
||||
* and then require your classes
|
||||
*
|
||||
* @backupStaticAttributes enabled
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
$this->moduleDir = dirname(__FILE__) . '/../../../';
|
||||
$this->appDir = $this->moduleDir.'../../library/Icinga/';
|
||||
$module = $this->moduleDir;
|
||||
$app = $this->appDir;
|
||||
set_include_path(get_include_path().':'.$module);
|
||||
set_include_path(get_include_path().':'.$app);
|
||||
|
||||
require_once('Zend/Config.php');
|
||||
require_once('Zend/Db.php');
|
||||
require_once(dirname(__FILE__) . '/datasource/DataSourceTestSetup.php');
|
||||
|
||||
$this->requireBase();
|
||||
$this->requireViews();
|
||||
|
||||
ResourceFactory::setConfig(
|
||||
new Zend_Config(array(
|
||||
'statusdat-unittest' => array(
|
||||
'type' => 'statusdat',
|
||||
'status_file' => '/tmp/teststatus.dat',
|
||||
'object_file' => '/tmp/testobjects.cache',
|
||||
'no_cache' => true
|
||||
),
|
||||
'ido-mysql-unittest' => array(
|
||||
'type' => 'db',
|
||||
'db' => 'mysql',
|
||||
'host' => 'localhost',
|
||||
'username' => 'icinga_unittest',
|
||||
'password' => 'icinga_unittest',
|
||||
'dbname' => 'icinga_unittest'
|
||||
),
|
||||
'ido-pgsql-unittest' => array(
|
||||
'type' => 'db',
|
||||
'db' => 'mysql',
|
||||
'host' => 'localhost',
|
||||
'username' => 'icinga_unittest',
|
||||
'password' => 'icinga_unittest',
|
||||
'dbname' => 'icinga_unittest'
|
||||
)
|
||||
))
|
||||
);
|
||||
Backend::setConfig(
|
||||
new Zend_Config(array(
|
||||
'statusdat-unittest' => array(
|
||||
'type' => 'statusdat',
|
||||
'resource' => 'statusdat-unittest'
|
||||
),
|
||||
'ido-mysql-unittest' => array(
|
||||
'type' => 'ido',
|
||||
'resource' => 'ido-mysql-unittest'
|
||||
),
|
||||
'ido-pgsql-unittest' => array(
|
||||
'type' => 'ido',
|
||||
'resource' => 'ido-pgsql-unittest'
|
||||
)
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Require base application and data retrieval classes from the Icinga Library
|
||||
*
|
||||
*/
|
||||
private function requireBase()
|
||||
{
|
||||
require_once('Application/Benchmark.php');
|
||||
require_once('Data/BaseQuery.php');
|
||||
require_once('Data/DatasourceInterface.php');
|
||||
require_once('Data/Db/Connection.php');
|
||||
require_once('Data/Db/Query.php');
|
||||
require_once('Exception/ProgrammingError.php');
|
||||
require_once('Web/Widget/SortBox.php');
|
||||
require_once('Web/Widget/FilterBox.php');
|
||||
require_once('Web/Widget/FilterBadgeRenderer.php');
|
||||
require_once('library/Monitoring/Backend.php');
|
||||
require_once('library/Monitoring/Controller.php');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Require all defined IDO queries in this module
|
||||
*
|
||||
*/
|
||||
private function requireIDOQueries()
|
||||
{
|
||||
require_once('library/Monitoring/Backend/Ido/Query/IdoQuery.php');
|
||||
$this->requireFolder('library/Monitoring/Backend/Ido/Query');
|
||||
}
|
||||
|
||||
/**
|
||||
* Require all php files in the folder $folder
|
||||
*
|
||||
* @param $folder The path to the folder containing PHP files
|
||||
*/
|
||||
private function requireFolder($folder)
|
||||
{
|
||||
$module = $this->moduleDir;
|
||||
$views = scandir($module.$folder);
|
||||
foreach ($views as $view) {
|
||||
if (!preg_match('/php$/', $view)) {
|
||||
continue;
|
||||
}
|
||||
require_once(realpath($module.$folder."/".$view));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Require all views and queries from the statusdat backen
|
||||
*
|
||||
*/
|
||||
private function requireStatusDatQueries()
|
||||
{
|
||||
require_once(realpath($this->moduleDir.'/library/Monitoring/Backend/Statusdat/Query/StatusdatQuery.php'));
|
||||
$this->requireFolder('library/Monitoring/Backend/Statusdat');
|
||||
$this->requireFolder('library/Monitoring/Backend/Statusdat/Query');
|
||||
}
|
||||
|
||||
/**
|
||||
* Require all (generic) view classes from the monitoring module
|
||||
*/
|
||||
private function requireViews()
|
||||
{
|
||||
$module = $this->moduleDir;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Require and set up a controller $controller using the backend type specified at $backend
|
||||
*
|
||||
* @param string $controller The name of the controller tu use
|
||||
* (must be under monitoring/application/controllers)
|
||||
* @param string $backend The backend to use ('mysql', 'pgsql' or 'statusdat')
|
||||
* @return ModuleActionController The newly created controller
|
||||
*/
|
||||
public function requireController($controller, $backend)
|
||||
{
|
||||
require_once($this->moduleDir . '/library/Monitoring/Controller.php');
|
||||
require_once($this->moduleDir . '/application/controllers/'.$controller.'.php');
|
||||
$controllerName = '\Monitoring_'.ucfirst($controller);
|
||||
$request = $this->getRequest();
|
||||
if ($backend == 'statusdat') {
|
||||
$this->requireStatusDatQueries();
|
||||
$request->setParam('backend', 'statusdat-unittest');
|
||||
} else {
|
||||
$this->requireStatusDatQueries();
|
||||
$request->setParam('backend', "ido-$backend-unittest");
|
||||
}
|
||||
/** @var ActionController $controller */
|
||||
$controller = new $controllerName(
|
||||
$request,
|
||||
$this->getResponse(),
|
||||
array('noInit' => true)
|
||||
);
|
||||
$controller->setBackend($this->getBackendFor($backend));
|
||||
|
||||
// Many controllers need a view to work properly
|
||||
$controller->view = new Zend_View();
|
||||
|
||||
return $controller;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new backend and insert the given fixture into it
|
||||
*
|
||||
* @param TestFixture $fixture The TestFixture to create
|
||||
* @param string $type The type of the backend ('mysql', 'pgsql' or 'statusdat')
|
||||
*/
|
||||
public function setupFixture(TestFixture $fixture, $type)
|
||||
{
|
||||
$dbInstance = new DataSourceTestSetup($type);
|
||||
$dbInstance->setup();
|
||||
$dbInstance->insert($fixture);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up and configure a new testbackend for the given type
|
||||
*
|
||||
* @param string $type The type of the backend 'mysql', 'pgsql' or 'statusdat'
|
||||
* @return Ido|Statusdat The newly created backend
|
||||
*/
|
||||
public function getBackendFor($type)
|
||||
{
|
||||
if ($type == "mysql" || $type == "pgsql") {
|
||||
$this->requireIDOQueries();
|
||||
$backendConfig = new Zend_Config(array(
|
||||
'type' => 'ido'
|
||||
));
|
||||
$resourceConfig = new Zend_Config(
|
||||
array(
|
||||
'type' => 'db',
|
||||
'db' => $type,
|
||||
'host' => "localhost",
|
||||
'username' => "icinga_unittest",
|
||||
'password' => "icinga_unittest",
|
||||
'dbname' => "icinga_unittest"
|
||||
)
|
||||
);
|
||||
return new Backend($backendConfig, $resourceConfig);
|
||||
} elseif ($type == "statusdat") {
|
||||
$this->requireStatusDatQueries();
|
||||
$backendConfig = new Zend_Config(array(
|
||||
'type' => 'statusdat'
|
||||
));
|
||||
$resourceConfig = new Zend_Config(
|
||||
array(
|
||||
'type' => 'statusdat',
|
||||
'status_file' => '/tmp/teststatus.dat',
|
||||
'object_file' => '/tmp/testobjects.cache',
|
||||
'no_cache' => true
|
||||
)
|
||||
);
|
||||
return new Backend(
|
||||
$backendConfig,
|
||||
$resourceConfig
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,155 +0,0 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - 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\Testlib\DataSource;
|
||||
|
||||
require_once(dirname(__FILE__).'/strategies/InsertionStrategy.php');
|
||||
require_once(dirname(__FILE__).'/strategies/SetupStrategy.php');
|
||||
|
||||
require_once(dirname(__FILE__).'/strategies/MySQLSetupStrategy.php');
|
||||
require_once(dirname(__FILE__).'/strategies/PgSQLSetupStrategy.php');
|
||||
require_once(dirname(__FILE__).'/strategies/PDOInsertionStrategy.php');
|
||||
|
||||
require_once(dirname(__FILE__).'/strategies/StatusdatInsertionStrategy.php');
|
||||
require_once(dirname(__FILE__).'/strategies/StatusdatSetupStrategy.php');
|
||||
|
||||
require_once(dirname(__FILE__).'/TestFixture.php');
|
||||
|
||||
use \Test\Monitoring\Testlib\Datasource\Strategies\InsertionStrategy;
|
||||
use \Test\Monitoring\Testlib\Datasource\Strategies\SetupStrategy;
|
||||
use \Test\Monitoring\Testlib\Datasource\Strategies\MySQLSetupStrategy;
|
||||
use \Test\Monitoring\Testlib\Datasource\Strategies\PgSQLSetupStrategy;
|
||||
use \Test\Monitoring\Testlib\Datasource\Strategies\PDOInsertionStrategy;
|
||||
use \Test\Monitoring\Testlib\Datasource\Strategies\StatusdatInsertionStrategy;
|
||||
use \Test\Monitoring\Testlib\Datasource\Strategies\StatusdatSetupStrategy;
|
||||
|
||||
/**
|
||||
* Fascade class that handles creation of test-fixture backends
|
||||
*
|
||||
* This class handles the creation and combination of SetupStrategies and InsertionStrategy
|
||||
* when testing controllers/queries with different backends.
|
||||
*
|
||||
* Example:
|
||||
* <code>
|
||||
* // TestFixtures contain the objects that should be written for testing
|
||||
* $fixture = new TestFixture();
|
||||
* $fixture->addHost(..)->... // setup fixture
|
||||
*
|
||||
* $ds = new DataSourceTestSetup('mysql');
|
||||
* $ds->setup(); // create a blank datasource
|
||||
* $ds->insert($fixture);
|
||||
* </code>
|
||||
*
|
||||
*
|
||||
*/
|
||||
class DataSourceTestSetup implements SetupStrategy, InsertionStrategy
|
||||
{
|
||||
/**
|
||||
* The SetupStrategy that is used on 'setup'
|
||||
* @var \Test\Monitoring\Testlib\Datasource\Strategies\StatusdatSetupStrategy
|
||||
*/
|
||||
private $setupStrategy;
|
||||
|
||||
/**
|
||||
* The InsertionStrategy that is used on 'insert'
|
||||
* @var \Test\Monitoring\Testlib\Datasource\Strategies\StatusdatInsertionStrategy
|
||||
*/
|
||||
private $insertionStrategy;
|
||||
|
||||
/**
|
||||
* Create a DataSource for the backend $type.
|
||||
*
|
||||
* On creation, a suitable setup/insert combination will be used
|
||||
* for the provided backend, so the caller needn't to care about which
|
||||
* setup or insertion strategy he wants to use.
|
||||
*
|
||||
* @param String $type The type of the backend (currently 'mysql', 'pgsql' and 'statusdat')
|
||||
*/
|
||||
public function __construct($type)
|
||||
{
|
||||
if ($type == 'mysql') {
|
||||
$this->setupStrategy = new MySQLSetupStrategy();
|
||||
$this->insertionStrategy = new PDOInsertionStrategy();
|
||||
$this->insertionStrategy->datetimeFormat = "Y-m-d H:i:s";
|
||||
|
||||
} elseif ($type == 'pgsql') {
|
||||
$this->setupStrategy = new PgSQLSetupStrategy();
|
||||
$this->insertionStrategy = new PDOInsertionStrategy();
|
||||
$this->insertionStrategy->datetimeFormat = "Y-m-d H:i:s";
|
||||
} elseif ($type == 'statusdat') {
|
||||
$this->setupStrategy = new StatusdatSetupStrategy();
|
||||
$this->insertionStrategy = new StatusdatInsertionStrategy();
|
||||
} else {
|
||||
throw new \Exception('Unsupported backend '.$type);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a testfixture into this datasource
|
||||
*
|
||||
* @param TestFixture $fixture The fixture to insert into the datasource
|
||||
*/
|
||||
public function insert(TestFixture $fixture) {
|
||||
$this->insertionStrategy->insert($fixture);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a blank datasource that can be filled with TestFixtures afterwards
|
||||
*
|
||||
* @param String $version An (optional) version to use for creation
|
||||
* @param mixed $connection An (optional) connection to use for this datasource
|
||||
*/
|
||||
public function setup($version = null, $connection = null)
|
||||
{
|
||||
$c = $this->setupStrategy->setup($version, $connection);
|
||||
|
||||
$this->insertionStrategy->setConnection($c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all testdata created in this datasource
|
||||
*
|
||||
* @param mixed $connection An optional connection to use for clean up
|
||||
*/
|
||||
public function teardown($connection = null)
|
||||
{
|
||||
$this->setupStrategy->teardown($connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the connection to use for writing to this datasource
|
||||
*
|
||||
* @param mixed $connection The connection to use. The actual type depends
|
||||
* on the used backend
|
||||
*/
|
||||
public function setConnection($connection)
|
||||
{
|
||||
$this->insertionStrategy->setConnection($connection);
|
||||
}
|
||||
}
|
|
@ -1,586 +0,0 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - 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\Testlib\DataSource;
|
||||
|
||||
/**
|
||||
* Status flags for objects
|
||||
*
|
||||
*/
|
||||
class ObjectFlags {
|
||||
/**
|
||||
* 1 if the test host is flapping, otherwise 0
|
||||
* @var int
|
||||
*/
|
||||
public $flapping = 0;
|
||||
|
||||
/**
|
||||
* 1 if the test host has notifications enabled, otherwise 0
|
||||
* @var int
|
||||
*/
|
||||
public $notifications = 1;
|
||||
|
||||
/**
|
||||
* 1 if the test host is active, otherwise 0
|
||||
* @var int
|
||||
*/
|
||||
public $active_checks = 1;
|
||||
|
||||
/**
|
||||
* 1 if the test host allows passive checks, otherwise 0
|
||||
* @var int
|
||||
*/
|
||||
public $passive_checks = 1;
|
||||
|
||||
/**
|
||||
* 1 if the test host is acknowledged, otherwise 0
|
||||
* @var int
|
||||
*/
|
||||
public $acknowledged = 0;
|
||||
|
||||
/**
|
||||
* 1 if the test host is in a downtime, otherwise 0
|
||||
* @var int
|
||||
*/
|
||||
public $in_downtime = 0;
|
||||
|
||||
/**
|
||||
* 1 if the test host is pending, otherwise 0
|
||||
* @var int
|
||||
*/
|
||||
public $is_pending = 0;
|
||||
|
||||
/**
|
||||
* The last check and state change time as a UNIX timestamp
|
||||
* @var int
|
||||
*/
|
||||
public $time = 0;
|
||||
|
||||
/**
|
||||
* Create a new ObjectFlags instance with default values
|
||||
*
|
||||
* @param int $ageInSeconds How old this check should be in seconds
|
||||
*/
|
||||
public function __construct($ageInSeconds = null)
|
||||
{
|
||||
if(!is_int($ageInSeconds))
|
||||
$ageInSeconds = 0;
|
||||
$this->time = time()-$ageInSeconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new ObjectFlags object that is in 'flapping' state
|
||||
*
|
||||
* @return ObjectFlags
|
||||
*/
|
||||
public static function FLAPPING()
|
||||
{
|
||||
$flags = new ObjectFlags();
|
||||
$flags->flapping = 0;
|
||||
return $flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new ObjectFlags object that is in 'pending' state
|
||||
*
|
||||
* @return ObjectFlags
|
||||
*/
|
||||
public static function PENDING()
|
||||
{
|
||||
$flags = new ObjectFlags();
|
||||
$flags->is_pending = 1;
|
||||
return $flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new ObjectFlags object that is in 'notifications_disabled' state
|
||||
*
|
||||
* @return ObjectFlags
|
||||
*/
|
||||
public static function DISABLE_NOTIFICATIONS()
|
||||
{
|
||||
$flags = new ObjectFlags();
|
||||
$flags->notifications = 0;
|
||||
return $flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new ObjectFlags object that has active checks disabled but passive enabled
|
||||
*
|
||||
* @return ObjectFlags
|
||||
*/
|
||||
public static function PASSIVE_ONLY()
|
||||
{
|
||||
$flags = new ObjectFlags();
|
||||
$flags->active_checks = 0;
|
||||
return $flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new ObjectFlags object that has passive checks disabled but active enabled
|
||||
*
|
||||
* @return ObjectFlags
|
||||
*/
|
||||
public static function ACTIVE_ONLY()
|
||||
{
|
||||
$flags = new ObjectFlags();
|
||||
$flags->passive_checks = 0;
|
||||
return $flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new ObjectFlags object that is neither active nor passive
|
||||
*
|
||||
* @return ObjectFlags
|
||||
*/
|
||||
public static function DISABLED() {
|
||||
$flags = new ObjectFlags();
|
||||
$flags->passive_checks = 0;
|
||||
$flags->active_checks = 0;
|
||||
return $flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new ObjectFlags object that is in 'acknowledged' state
|
||||
*
|
||||
* @return ObjectFlags
|
||||
*/
|
||||
public static function ACKNOWLEDGED()
|
||||
{
|
||||
$flags = new ObjectFlags();
|
||||
$flags->acknowledged = 1;
|
||||
return $flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new ObjectFlags object that is in a downtime
|
||||
*
|
||||
* @return ObjectFlags
|
||||
*/
|
||||
public static function IN_DOWNTIME()
|
||||
{
|
||||
$flags = new ObjectFlags();
|
||||
$flags->in_downtime = 1;
|
||||
return $flags;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal class that adds an object scope on Fixture operations
|
||||
*
|
||||
* This class allows to use $fixture->addHost('host',0)->addService() instead('svc')
|
||||
* of $fixture->addHost('host',0); $fixture->addService('host', 'svc') as it encapsulates
|
||||
* the scope of the last called object and automatically adds it as the first parameter
|
||||
* of the next call.
|
||||
*
|
||||
*/
|
||||
class TestFixtureObjectClosure
|
||||
{
|
||||
/**
|
||||
* The object (hostname or hostname/servicename pair) this scope represents
|
||||
* @var String|array
|
||||
*/
|
||||
private $scope;
|
||||
|
||||
/**
|
||||
* The Testfixture to operate on
|
||||
* @var TestFixture
|
||||
*/
|
||||
private $environment;
|
||||
|
||||
/**
|
||||
* Create a new scope using the TestFixture with the given host / service
|
||||
* as the scope
|
||||
*
|
||||
* @param TestFixture $environment The testfixture to use for subsequent calls
|
||||
* @param $scope The scope to prepend to all further calls
|
||||
*/
|
||||
public function __construct(TestFixture $environment, $scope)
|
||||
{
|
||||
$this->scope = $scope;
|
||||
$this->environment = $environment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic method that forwards all function calls to the environment
|
||||
* but prepends the scope.
|
||||
*
|
||||
* A call func($arg1) to this class would be rewritten to $environment->func($scope, $arg1)
|
||||
*
|
||||
* @param string $string The method that should be called with this scope
|
||||
* @param array $arguments The arguments the user passed to the function
|
||||
* @return mixed The result of the function call
|
||||
*/
|
||||
public function __call($string, $arguments)
|
||||
{
|
||||
$callArg = array($this->scope);
|
||||
$args = array_merge($callArg, $arguments);
|
||||
return call_user_func_array(array($this->environment, $string), $args);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create test-states that can be persisted to different backends
|
||||
* using DataSourceTestSetup.
|
||||
*
|
||||
* This class provides not all fields used in monitoring, but the most
|
||||
* important ones (and the ones that are missing should be added during
|
||||
* developmen).
|
||||
*
|
||||
* Usage:
|
||||
* <code>
|
||||
* $fixture = new TestFixture();
|
||||
* // adding a new critical, but acknowledged host
|
||||
* $fixture->addHost("hostname", 1, ObjectFlags::ACKNOWLEDGED())
|
||||
*
|
||||
* // add a comment to the host (this has to be done before adding services)
|
||||
* ->addComment("author", "comment text")
|
||||
*
|
||||
* // assign to hostgroup
|
||||
* ->addToHostgroup("myHosts")
|
||||
*
|
||||
* // and add three services to this host
|
||||
* ->addService("svc1", 0) // Service is ok
|
||||
* ->addService("svc2", 1, ObjectFlags::PASSIVE) // service is warning and passive
|
||||
* ->addService("svc3", 2, null, array("notes_url" => "test.html")) // critical with notes url
|
||||
* ->addComment("author", "what a nice service comment") // add a comment to the service
|
||||
* ->addToServicegroup("alwaysdown"); // add svc3 to servicegroup
|
||||
*
|
||||
* // Create the datasource from this fixture, here form MySQL
|
||||
* $ds = new DataSourceTestSetup("mysql");
|
||||
* $ds->setup();
|
||||
* // insert fixture
|
||||
* $ds->insert($fixture);
|
||||
* </code>
|
||||
*
|
||||
*/
|
||||
class TestFixture
|
||||
{
|
||||
/**
|
||||
* Internal dataholder for all defined hosts
|
||||
* @var array
|
||||
*/
|
||||
private $hosts = array();
|
||||
|
||||
/**
|
||||
* Internal holder for all defined services
|
||||
* @var array
|
||||
*/
|
||||
private $services = array();
|
||||
|
||||
/**
|
||||
* Internal holder for all defined contacts
|
||||
* @var array
|
||||
*/
|
||||
private $contacts = array();
|
||||
|
||||
/**
|
||||
* Internal holder for all defined comments
|
||||
* @var array
|
||||
*/
|
||||
private $comments = array();
|
||||
|
||||
/**
|
||||
* Internal holder for all defined servicegroups
|
||||
* @var array
|
||||
*/
|
||||
private $servicegroups = array();
|
||||
|
||||
/**
|
||||
* Internal holder for all defined hostgroups
|
||||
* @var array
|
||||
*/
|
||||
private $hostgroups = array();
|
||||
|
||||
/**
|
||||
* Return array with all defined hostobjects
|
||||
*
|
||||
* @return array Returns an array of host-arrays, which have the following fields
|
||||
* - 'name' : The name of the host
|
||||
* - 'state' : The state of the host (0,1,2)
|
||||
* - 'address' : The string representation of the address (127.0.0.1 as default)
|
||||
* - 'flags' : An ObjectFlags object containing additional state information
|
||||
* - 'icon_image' : The icon image of this host (default: 'icon.png')
|
||||
* - 'notes_url' : The notes url of this host (default empty string)
|
||||
* - 'action_url' : The action url of this host (default empty string)
|
||||
* - 'contacts' : An array of contact objects (having 'name' as the most important field)
|
||||
* - 'customvariables' : An associative "cv_name"=>"cv_value" array containing the customvariables
|
||||
*/
|
||||
public function getHosts()
|
||||
{
|
||||
return $this->hosts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return array with all defined service objects
|
||||
*
|
||||
* @return array Returns an array of service-arrays, which have the following fields
|
||||
* - 'name' : The name of the service
|
||||
* - 'host' : A reference to the hostobject
|
||||
* - 'state' : The state of the service (0,1,2,3)
|
||||
* - 'flags' : An ObjectFlags object containing additional state information
|
||||
* - 'icon_image' : The icon image of this service (default: 'icon.png')
|
||||
* - 'notes_url' : The notes url of this service (default empty string)
|
||||
* - 'action_url' : The action url of this service (default empty string)
|
||||
* - 'contacts' : An array of contact objects (having 'name' as the most important field)
|
||||
* - 'customvariables' : An associative "cv_name"=>"cv_value" array containing the customvariables
|
||||
*/
|
||||
public function getServices()
|
||||
{
|
||||
return $this->services;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return array with all defined contacts
|
||||
*
|
||||
* @return array Returns an array of contact-arrays, which have the following fields
|
||||
* - 'alias' : The name of the contact
|
||||
*/
|
||||
public function getContacts()
|
||||
{
|
||||
return $this->contacts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return array with all defined servicegroups
|
||||
*
|
||||
* @return array Returns an array of group-arrays in the following format:
|
||||
* - 'name' : The name of the group
|
||||
* - 'members' : An array of service objects that belong to this group
|
||||
*/
|
||||
public function getServicegroups()
|
||||
{
|
||||
return $this->servicegroups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array with all defined hostgroups
|
||||
*
|
||||
* @return array Returns an array of group-arrays in the following format:
|
||||
* - 'name' : The name of the group
|
||||
* - 'members' : An array of host objects that belong to this group
|
||||
*/
|
||||
public function getHostgroups()
|
||||
{
|
||||
return $this->hostgroups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of service and hostcomments
|
||||
*
|
||||
* @return array Returns an array of comment arrays in the following format:
|
||||
* - 'service' (if servicecomment) : A reference to the service object this comment belongs to
|
||||
* - 'host' (if hostcomment) : A reference to the host object this comment belongs to
|
||||
* - 'author' : The author of this comment
|
||||
* - 'text' : The comment text
|
||||
*/
|
||||
public function getComments()
|
||||
{
|
||||
return $this->comments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new host to this TestFixture
|
||||
*
|
||||
* @param string $name The name of the host to add
|
||||
* @param int $state The state of the host to add (0,1,2)
|
||||
* @param ObjectFlags $flags (optional) An @see ObjectFlags object defining additional state inforamtion
|
||||
* @param array $additional (optional) An array with additional object fields
|
||||
*
|
||||
* @return TestFixtureObjectClosure The TestFixture with the newly added host as the scope
|
||||
*/
|
||||
public function addHost($name, $state, ObjectFlags $flags = null, array $additional = array()) {
|
||||
if ($flags === null) {
|
||||
$flags = new ObjectFlags();
|
||||
}
|
||||
if (isset($this->hosts[$name])) {
|
||||
throw new Exception('Tried to create hosts twice');
|
||||
}
|
||||
$this->hosts[$name] = array(
|
||||
'name' => $name,
|
||||
'state' => $state,
|
||||
'address' => '127.0.0.1',
|
||||
'flags' => $flags,
|
||||
'icon_image' => 'icon.png',
|
||||
'notes_url' => '',
|
||||
'action_url' => '',
|
||||
'contacts' => array(),
|
||||
'customvariables' => array()
|
||||
|
||||
);
|
||||
$this->hosts[$name] = array_merge($this->hosts[$name], $additional);
|
||||
return new TestFixtureObjectClosure($this, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new service to this TestFixture
|
||||
*
|
||||
* @param string $host The name of the host this service belongs to (must exist prior to service creation)
|
||||
* @param string $name The name of the service to add
|
||||
* @param int $state The state of the service to add (0,1,2,3)
|
||||
* @param ObjectFlags $flags (optional) An @see ObjectFlags object defining additional state information
|
||||
* @param array $additional (optional) An array with additional object fields
|
||||
*
|
||||
* @return TestFixtureObjectClosure The TestFixture with the newly added service as the scope
|
||||
*/
|
||||
public function addService($host, $name, $state, ObjectFlags $flags = null, array $additional = array()) {
|
||||
// when called in service scope only use the host
|
||||
if (is_array($host)) {
|
||||
$host = $host[0];
|
||||
}
|
||||
if ($flags === null) {
|
||||
$flags = new ObjectFlags();
|
||||
}
|
||||
if (!isset($this->hosts[$host])) {
|
||||
throw new Exception('Tried to create service for non existing host '.$host);
|
||||
}
|
||||
if (isset($this->services[$name])) {
|
||||
throw new Exception('Tried to create service twice '.$name);
|
||||
}
|
||||
$this->services[$host.';'.$name] = array(
|
||||
'host' => &$this->hosts[$host],
|
||||
'name' => $name,
|
||||
'state' => $state,
|
||||
'contacts' => array(),
|
||||
'icon_image' => 'icon.png',
|
||||
'notes_url' => '',
|
||||
'action_url' => '',
|
||||
'customvariables' => array(),
|
||||
'flags' => $flags
|
||||
);
|
||||
$this->services[$host.';'.$name] = array_merge($this->services[$host.';'.$name], $additional);
|
||||
|
||||
return new TestFixtureObjectClosure($this, array($host, $name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new comment to the host or service provided in $hostOrServiceHostPair
|
||||
*
|
||||
* @param string|array $hostOrServiceHostPair Either a string with the hostname or an array with the hostname
|
||||
* as the first and the servicename as the second element
|
||||
* @param $author The author for the coment
|
||||
* @param $text The content of the comment
|
||||
* @return TestFixtureObjectClosure The TestFixture with the comment owner as the scope
|
||||
*/
|
||||
public function addComment($hostOrServiceHostPair, $author, $text) {
|
||||
if (is_array($hostOrServiceHostPair)) {
|
||||
if (!isset($this->services[$hostOrServiceHostPair[0].';'.$hostOrServiceHostPair[1]])) {
|
||||
throw new Exception('Tried to add a comment for a nonexisting service '.$hostOrServiceHostPair[1]);
|
||||
}
|
||||
$this->comments[] = array(
|
||||
'service' => &$this->services[$hostOrServiceHostPair[0].';'.$hostOrServiceHostPair[1]],
|
||||
'author' => $author,
|
||||
'text' => $text
|
||||
);
|
||||
} else {
|
||||
if (!isset($this->hosts[$hostOrServiceHostPair])) {
|
||||
throw new Exception('Tried to add a comment for a nonexisting host '.$hostOrServiceHostPair);
|
||||
}
|
||||
$this->comments[] = array(
|
||||
'host' => &$this->hosts[$hostOrServiceHostPair],
|
||||
'author' => $author,
|
||||
'text' => $text
|
||||
);
|
||||
}
|
||||
return new TestFixtureObjectClosure($this, $hostOrServiceHostPair);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign a new contact to a host or service
|
||||
*
|
||||
* @param $hostOrServiceHostPair Either a string with the hostname or an array with the hostname
|
||||
* as the first and the servicename as the second element
|
||||
* @param $contactname The contactname to assign (will be created)
|
||||
* @return TestFixtureObjectClosure The TestFixture with the host or service as the scope
|
||||
*/
|
||||
public function assignContact($hostOrServiceHostPair, $contactname) {
|
||||
$this->contacts[$contactname] = array('alias' => $contactname);
|
||||
if (is_array($hostOrServiceHostPair)) {
|
||||
if (!isset($this->services[$hostOrServiceHostPair[0].';'.$hostOrServiceHostPair[1]])) {
|
||||
throw new Exception('Tried to add a comment for a nonexisting service '.$hostOrServiceHostPair[1]);
|
||||
}
|
||||
$service = $this->services[$hostOrServiceHostPair[0].';'.$hostOrServiceHostPair[1]];
|
||||
$service['contacts'][] = &$this->contacts[$contactname];
|
||||
} else {
|
||||
if (!isset($this->hosts[$hostOrServiceHostPair])) {
|
||||
throw new Exception('Tried to add a comment for a nonexisting host '.$hostOrServiceHostPair);
|
||||
}
|
||||
$host = $this->hosts[$hostOrServiceHostPair];
|
||||
$host['contacts'][] = &$this->contacts[$contactname];
|
||||
}
|
||||
return new TestFixtureObjectClosure($this, $hostOrServiceHostPair);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a host to a hostgroup
|
||||
*
|
||||
* Create the new hostgroup if it not exists yet, otherwise just add the
|
||||
* host to it
|
||||
*
|
||||
* @param string $host The name of the host to add to the hostgroup
|
||||
* @param string $groupname The name of the hostgroup
|
||||
* @return TestFixtureObjectClosure The TestFixture with the host as the scope
|
||||
*/
|
||||
public function addToHostgroup($host, $groupname) {
|
||||
// check if in service scope
|
||||
if (is_array($host)) {
|
||||
$host = $host[0];
|
||||
}
|
||||
if (!isset($this->hosts[$host])) {
|
||||
throw new Exception('Tried to add non-existing host '.$host.' to hostgroup ');
|
||||
}
|
||||
if (!isset($this->hostgroups[$groupname])) {
|
||||
$this->hostgroups[$groupname] = array("name" => $groupname, "members" => array());
|
||||
}
|
||||
$this->hostgroups[$groupname]["members"][] = &$this->hosts[$host];
|
||||
return new TestFixtureObjectClosure($this, $host);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add service to a servicegroup
|
||||
*
|
||||
* Create the new service if it not exists yet, otherwise just add the service
|
||||
*
|
||||
* @param array $serviceHostPair An array containing the hostname as the first and the
|
||||
* servicename as the second element
|
||||
* @param string $groupname The name of the servicegroup
|
||||
* @return TestFixtureObjectClosure The TestFixture with the service as the scope
|
||||
*/
|
||||
public function addToServicegroup(array $serviceHostPair, $groupname) {
|
||||
if (!isset($this->services[$serviceHostPair[0].";".$serviceHostPair[1]])) {
|
||||
throw new Exception('Tried to add non-existing service '.$serviceHostPair[1].' to servicegroup ');
|
||||
}
|
||||
$service = &$this->services[$serviceHostPair[0].";".$serviceHostPair[1]];
|
||||
if (!isset($this->servicegroups[$groupname])) {
|
||||
$this->servicegroups[$groupname] = array("name" => $groupname, "members" => array());
|
||||
}
|
||||
$this->servicegroups[$groupname]["members"][] = &$service;
|
||||
return new TestFixtureObjectClosure($this, $serviceHostPair);
|
||||
}
|
||||
}
|
|
@ -1,99 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Test\Monitoring\Testlib\DataSource\schemes;
|
||||
|
||||
/**
|
||||
* Container class for Objectcache object snipptes
|
||||
*
|
||||
*/
|
||||
class ObjectsCacheTemplates {
|
||||
|
||||
public static $HOST =<<<'EOF'
|
||||
define host {
|
||||
host_name\t{{HOST_NAME}}
|
||||
alias\t{{HOST_NAME}} alias
|
||||
address\t{{HOST_ADDRESS}}
|
||||
check_period\t24x7
|
||||
check_command\ttest-check-host-alive-parent!flap!$HOSTSTATE:router_00$
|
||||
contact_groups\ttest_contact
|
||||
notification_period\t24x7
|
||||
initial_state\to
|
||||
check_interval\t10.000000
|
||||
retry_interval\t1.000000
|
||||
max_check_attempts\t5
|
||||
active_checks_enabled\t1
|
||||
passive_checks_enabled\t1
|
||||
obsess_over_host\t1
|
||||
event_handler_enabled\t1
|
||||
low_flap_threshold\t0.000000
|
||||
high_flap_threshold\t0.000000
|
||||
flap_detection_enabled\t1
|
||||
flap_detection_options\to,d,u
|
||||
freshness_threshold\t0
|
||||
check_freshness\t0
|
||||
notification_options\td,u,r
|
||||
notifications_enabled\t1
|
||||
notification_interval\t0.000000
|
||||
first_notification_delay\t0.000000
|
||||
stalking_options\tn
|
||||
process_perf_data\t1
|
||||
failure_prediction_enabled\t1
|
||||
icon_image\t{{ICON_IMAGE}}
|
||||
icon_image_alt\ticon alt string
|
||||
notes\tjust a notes string
|
||||
notes_url\t{{NOTES_URL}}
|
||||
action_url\t{{ACTION_URL}}
|
||||
retain_status_information\t1
|
||||
retain_nonstatus_information\t1
|
||||
}
|
||||
EOF;
|
||||
public static $SERVICE =<<<'EOF'
|
||||
define service {
|
||||
host_name\t{{HOST_NAME}}
|
||||
service_description\t{{SERVICE_NAME}}
|
||||
check_period\t24x7
|
||||
check_command\tcheck_service!critical
|
||||
contact_groups\ttest_contact
|
||||
notification_period\t24x7
|
||||
initial_state\to
|
||||
check_interval\t5.000000
|
||||
retry_interval\t2.000000
|
||||
max_check_attempts\t3
|
||||
is_volatile\t0
|
||||
parallelize_check\t1
|
||||
active_checks_enabled\t1
|
||||
passive_checks_enabled\t1
|
||||
obsess_over_service\t1
|
||||
event_handler_enabled\t1
|
||||
low_flap_threshold\t0.000000
|
||||
high_flap_threshold\t0.000000
|
||||
flap_detection_enabled\t1
|
||||
flap_detection_options\to,w,u,c
|
||||
freshness_threshold\t0
|
||||
check_freshness\t0
|
||||
notification_options\tu,w,c,r
|
||||
notifications_enabled\t1
|
||||
notification_interval\t0.000000
|
||||
first_notification_delay\t0.000000
|
||||
stalking_options\tn
|
||||
process_perf_data\t1
|
||||
failure_prediction_enabled\t1
|
||||
icon_image\t{{ICON_IMAGE}}
|
||||
icon_image_alt\ticon alt string
|
||||
notes\tjust a notes string
|
||||
notes_url\t{{NOTES_URL}}
|
||||
action_url\t{{ACTION_URL}}
|
||||
retain_status_information\t1
|
||||
retain_nonstatus_information\t1
|
||||
}
|
||||
EOF;
|
||||
|
||||
public static $GROUP =<<<'EOF'
|
||||
define {{TYPE}}group {
|
||||
{{TYPE}}group_name\t{{NAME}}
|
||||
alias\t{{NAME}}
|
||||
members\t{{MEMBERS}}
|
||||
}
|
||||
EOF;
|
||||
|
||||
};
|
|
@ -1,173 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* User: moja
|
||||
* Date: 7/17/13
|
||||
* Time: 10:25 AM
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
|
||||
namespace Test\Monitoring\Testlib\DataSource\schemes;
|
||||
|
||||
/**
|
||||
* Container class for Statusdat object snippets
|
||||
*
|
||||
*/
|
||||
class StatusdatTemplates {
|
||||
|
||||
public static $HOST =<<<'EOF'
|
||||
hoststatus {
|
||||
host_name={{HOST_NAME}}
|
||||
modified_attributes=0
|
||||
check_command=test-check-host-alive-parent!pending!$HOSTSTATE:router_01$
|
||||
check_period=24x7
|
||||
notification_period=24x7
|
||||
check_interval=10.000000
|
||||
retry_interval=1.000000
|
||||
event_handler=
|
||||
has_been_checked=0
|
||||
should_be_scheduled=0
|
||||
check_execution_time=0.000
|
||||
check_latency=0.000
|
||||
check_type=0
|
||||
current_state={{HOST_STATUS}}
|
||||
last_hard_state=0
|
||||
last_event_id=14750
|
||||
current_event_id=14756
|
||||
current_problem_id=6016
|
||||
last_problem_id=6010
|
||||
plugin_output=Plugin output for host {{HOST_NAME}}
|
||||
long_plugin_output=Long plugin output for host {{HOST_NAME}}
|
||||
performance_data=
|
||||
last_check={{TIME}}
|
||||
next_check=1374002661
|
||||
check_options=0
|
||||
current_attempt=2
|
||||
max_attempts=5
|
||||
state_type=0
|
||||
last_state_change={{TIME}}
|
||||
last_hard_state_change={{TIME}}
|
||||
last_time_up=1373984768
|
||||
last_time_down=1373984818
|
||||
last_time_unreachable=1373984748
|
||||
last_notification=0
|
||||
next_notification=0
|
||||
no_more_notifications=1
|
||||
current_notification_number=0
|
||||
current_down_notification_number=0
|
||||
current_unreachable_notification_number=0
|
||||
current_notification_id=0
|
||||
notifications_enabled={{NOTIFICATIONS_ENABLED}}
|
||||
problem_has_been_acknowledged={{ACKNOWLEDGED}}
|
||||
acknowledgement_type=0
|
||||
acknowledgement_end_time=0
|
||||
active_checks_enabled={{ACTIVE_ENABLED}}
|
||||
passive_checks_enabled={{PASSIVE_ENABLED}}
|
||||
event_handler_enabled=1
|
||||
flap_detection_enabled=1
|
||||
failure_prediction_enabled=1
|
||||
process_performance_data=1
|
||||
obsess_over_host=1
|
||||
last_update=1374002209
|
||||
is_flapping={{FLAPPING}}
|
||||
percent_state_change=0.00
|
||||
scheduled_downtime_depth={{IN_DOWNTIME}}
|
||||
{{CVS}}
|
||||
}
|
||||
EOF;
|
||||
|
||||
public static $SERIVCE =<<<'EOF'
|
||||
servicestatus {
|
||||
host_name={{HOST_NAME}}
|
||||
service_description={{SERVICE_NAME}}
|
||||
modified_attributes=0
|
||||
check_command=check_service!critical
|
||||
check_period=24x7
|
||||
notification_period=24x7
|
||||
check_interval=5.000000
|
||||
retry_interval=2.000000
|
||||
event_handler=
|
||||
has_been_checked=1
|
||||
should_be_scheduled=1
|
||||
check_execution_time=0.250
|
||||
check_latency=0.113
|
||||
check_type=0
|
||||
current_state={{SERVICE_STATUS}}
|
||||
last_hard_state=2
|
||||
last_event_id=0
|
||||
current_event_id=6179
|
||||
current_problem_id=2434
|
||||
last_problem_id=0
|
||||
current_attempt=3
|
||||
max_attempts=3
|
||||
state_type=1
|
||||
last_state_change={{TIME}}
|
||||
last_hard_state_change={{TIME}}
|
||||
last_time_ok=0
|
||||
last_time_warning=0
|
||||
last_time_unknown=0
|
||||
last_time_critical=1373024663
|
||||
plugin_output=Plugin output for service {{SERVICE_NAME}}
|
||||
long_plugin_output=Long plugin output for service {{SERVICE_NAME}}
|
||||
performance_data=runtime=0.012226
|
||||
last_check=1373087666
|
||||
next_check=1374002401
|
||||
check_options=0
|
||||
current_notification_number=0
|
||||
current_warning_notification_number=0
|
||||
current_critical_notification_number=0
|
||||
current_unknown_notification_number=0
|
||||
current_notification_id=0
|
||||
last_notification=0
|
||||
next_notification=0
|
||||
no_more_notifications=1
|
||||
notifications_enabled={{NOTIFICATIONS_ENABLED}}
|
||||
active_checks_enabled={{ACTIVE_ENABLED}}
|
||||
passive_checks_enabled={{PASSIVE_ENABLED}}
|
||||
event_handler_enabled=1
|
||||
problem_has_been_acknowledged={{ACKNOWLEDGED}}
|
||||
acknowledgement_type=1
|
||||
acknowledgement_end_time=0
|
||||
flap_detection_enabled=1
|
||||
failure_prediction_enabled=1
|
||||
process_performance_data=1
|
||||
obsess_over_service=1
|
||||
last_update=1374002209
|
||||
is_flapping={{FLAPPING}}
|
||||
percent_state_change=6.25
|
||||
scheduled_downtime_depth={{IN_DOWNTIME}}
|
||||
{{CVS}}
|
||||
}
|
||||
EOF;
|
||||
|
||||
public static $SERVICECOMMENT =<<<'EOF'
|
||||
servicecomment {
|
||||
host_name={{HOST_NAME}}
|
||||
service_description={{SERVICE_NAME}}
|
||||
entry_type=3
|
||||
comment_id={{ID}}
|
||||
source=0
|
||||
persistent=0
|
||||
entry_time={{TIME}}
|
||||
expires=0
|
||||
expire_time=0
|
||||
author={{AUTHOR}}
|
||||
comment_data={{TEXT}
|
||||
}
|
||||
EOF;
|
||||
|
||||
public static $HOSTCOMMENT =<<<'EOF'
|
||||
hostcomment {
|
||||
host_name={{HOST_NAME}}
|
||||
entry_type=3
|
||||
comment_id={{ID}}
|
||||
source=0
|
||||
persistent=0
|
||||
entry_time={{TIME}}
|
||||
expires=0
|
||||
expire_time=0
|
||||
author={{AUTHOR}}
|
||||
comment_data={{TEXT}}
|
||||
}
|
||||
EOF;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -1,58 +0,0 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - 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\Testlib\Datasource\Strategies;
|
||||
use \Test\Monitoring\Testlib\DataSource\TestFixture;
|
||||
|
||||
/**
|
||||
* Generic interface for Fixture insertion implementations
|
||||
*
|
||||
* These implementations can create Icinga-compatible Datatsources
|
||||
* from TestFixture classes and are therefore rather free in their
|
||||
* implementation
|
||||
*
|
||||
*/
|
||||
interface InsertionStrategy {
|
||||
/**
|
||||
* Tell the class to use the given ressource as the
|
||||
* connection identifier
|
||||
*
|
||||
* @param $connection A generic connection identifier,
|
||||
* the concrete class depends on the implementation
|
||||
*/
|
||||
public function setConnection($connection);
|
||||
|
||||
/**
|
||||
* Insert the passed fixture into the datasource and allow
|
||||
* the icinga backends to query it.
|
||||
*
|
||||
* @param TestFixture $fixture
|
||||
*/
|
||||
public function insert(TestFixture $fixture);
|
||||
}
|
|
@ -1,107 +0,0 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - 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\Testlib\Datasource\Strategies;
|
||||
|
||||
/**
|
||||
* SetupStrategy implementation for MySQL based IDO-Backends
|
||||
*
|
||||
* This strategy creates a new MySQL Database and removes old ones
|
||||
* if necessary. Per default the database user is icinga_unittest:icinga_unittest
|
||||
* and the database to be created is also icinga_unittest. The user must
|
||||
* have all Privileges on the test database, so its best to create him
|
||||
* with:
|
||||
*
|
||||
* mysql -u root
|
||||
* # CREATE USER `icinga_unittest`@`localhost` IDENTIFIED BY 'icinga_unittest';
|
||||
* # CREATE DATABASE icinga_unittest;
|
||||
* # GRANT ALL PRIVILEGES ON icinga_unittest.* TO `icinga_unittest`@`localhost`
|
||||
*
|
||||
**/
|
||||
class MySQLSetupStrategy implements SetupStrategy {
|
||||
|
||||
/**
|
||||
* Tears down any existing databases and creates a new blank IDO scheme.
|
||||
*
|
||||
* The database is created according to the passed version (or using the newest version if no version is provided),
|
||||
* using the idoMySQL-%VERSION%.sql underneath the schemes folder.
|
||||
* A \PDO Connection can be provided, if not the icinga_unittest default
|
||||
* connection will be established and used.
|
||||
*
|
||||
* @param String $version An optional version to use as the db scheme
|
||||
* @param \PDO $connection An optional connection to use instead of icinga_unittest
|
||||
* @return \PDO The connection that has been created
|
||||
*
|
||||
* @throws \PDOException In case connecting to or creating the database fails
|
||||
* @throws \Exception In case of an invalid/non-existing DB scheme
|
||||
*/
|
||||
public function setup($version = null, $connection = null)
|
||||
{
|
||||
if ($connection === null) {
|
||||
$connection = new \PDO("mysql:dbname=icinga_unittest", "icinga_unittest", "icinga_unittest");
|
||||
}
|
||||
|
||||
$connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
||||
$this->teardown($connection);
|
||||
|
||||
// the latest schema doesn't have a suffix, so if no version is given this one is used
|
||||
$sqlFileName = 'idoMySQL'.($version !== null ? '-'.$version : '' ).'.sql';
|
||||
$path = realpath(dirname(__FILE__).'/../schemes/'.$sqlFileName);
|
||||
if (!file_exists($path)) {
|
||||
throw new \Exception('File '.$path.' not found: Could not create scheme for IDO mysql backend '.($version ? '(version : '.$version.')' :''));
|
||||
}
|
||||
|
||||
$connection->setAttribute(\PDO::ATTR_EMULATE_PREPARES, true);
|
||||
|
||||
if ($connection->query(file_get_contents($path)) === false) {
|
||||
$error = $connection->errorInfo();;
|
||||
throw new \PDOException($error[0].' : '.$error[2]);
|
||||
}
|
||||
return $connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Drops all tables from the connection via DROP TABLE
|
||||
*
|
||||
* @param \PDO $connection An optional connection to use, if none is
|
||||
* given the icinga_unittest default will be used
|
||||
*
|
||||
*/
|
||||
public function teardown($connection = null)
|
||||
{
|
||||
if ($connection === null) {
|
||||
$connection = new \PDO("mysql:dbname=icinga_unittest", "icinga_unittest", "icinga_unittest");
|
||||
}
|
||||
|
||||
$tables = $connection->query("SHOW TABLES")->fetchAll();
|
||||
foreach($tables as $table) {
|
||||
$connection->query("DROP TABLE ".$table[0]);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,328 +0,0 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - 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\Testlib\Datasource\Strategies;
|
||||
use \Test\Monitoring\Testlib\DataSource\TestFixture;
|
||||
|
||||
/**
|
||||
* TestFixture insertion implementation for PDO based backends
|
||||
*
|
||||
* This class allows to create the actual IDO databases from TestFixture
|
||||
* classes using PDO.
|
||||
*
|
||||
*/
|
||||
class PDOInsertionStrategy
|
||||
{
|
||||
/**
|
||||
* Points to the (icinga) objectId of the next inserted object
|
||||
* @var int
|
||||
*/
|
||||
private $objectId = 0;
|
||||
|
||||
/**
|
||||
* The fixture that is being inserted by this object
|
||||
* @var TestFixture
|
||||
*/
|
||||
private $fixture;
|
||||
|
||||
/**
|
||||
* The database (PDO) connection to use for inserting
|
||||
* @var \PDO
|
||||
*/
|
||||
private $connection;
|
||||
|
||||
/**
|
||||
* The date format that will be used for inserting
|
||||
* date values, see @link http://php.net/manual/en/function.date.php
|
||||
* for possible values
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $datetimeFormat = "U";
|
||||
|
||||
/**
|
||||
* @see InsertionStrategy::setConnection
|
||||
*
|
||||
* @param \PDO $connection The PDO connection to use
|
||||
*/
|
||||
public function setConnection($connection) {
|
||||
$this->connection = $connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert the provided @see TestFixture into this database
|
||||
*
|
||||
* @param TestFixture $fixture The fixture to insert into the database
|
||||
*/
|
||||
public function insert(TestFixture $fixture)
|
||||
{
|
||||
$this->fixture = $fixture;
|
||||
|
||||
$this->insertContacts();
|
||||
|
||||
$this->insertHosts();
|
||||
$this->insertServices();
|
||||
$this->insertComments();
|
||||
|
||||
$this->insertHostgroups();
|
||||
$this->insertServicegroups();
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert all hosts from the current fixture into the IDO Database
|
||||
*
|
||||
* This method updates the icinga_objects, icinga_hosts, icinga_hoststatus
|
||||
* and icinga_customvariablestatus tables with the host values provided
|
||||
* by the internal fixture (@see PDOInsertStrategy::insert)
|
||||
*
|
||||
*/
|
||||
private function insertHosts()
|
||||
{
|
||||
$hosts = $this->fixture->getHosts();
|
||||
|
||||
$insertObjectQuery = $this->connection->prepare(
|
||||
'INSERT INTO icinga_objects (object_id, objecttype_id, name1, is_active) VALUES (?, 1, ?, 1);'
|
||||
);
|
||||
$insertHostQuery = $this->connection->prepare(
|
||||
'INSERT INTO icinga_hosts ('.
|
||||
'host_id, alias, display_name, address, host_object_id, '.
|
||||
'icon_image, notes_url, action_url'.
|
||||
') VALUES (?, ?, ?, ?, ?, ?, ?, ?);'
|
||||
);
|
||||
$insertContactQuery = $this->connection->prepare(
|
||||
'INSERT INTO icinga_host_contacts (host_id, contact_object_id) VALUES (?, ?);'
|
||||
);
|
||||
$insertHostStatusQuery = $this->connection->prepare(
|
||||
'INSERT INTO icinga_hoststatus'.
|
||||
'(host_object_id, current_state, last_check, last_state_change, notifications_enabled, '.
|
||||
'active_checks_enabled, passive_checks_enabled, is_flapping, scheduled_downtime_depth,'.
|
||||
'output, long_output, '.
|
||||
'problem_has_been_acknowledged, has_been_checked) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'
|
||||
);
|
||||
$insertCVQuery = $this->connection->prepare(
|
||||
'INSERT INTO icinga_customvariablestatus'.
|
||||
'(object_id, varname, varvalue) VALUES (?, ?, ?)'
|
||||
);
|
||||
foreach($hosts as &$host) {
|
||||
$flags = $host["flags"];
|
||||
|
||||
$insertObjectQuery->execute(array($this->objectId, $host["name"]));
|
||||
$insertHostQuery->execute(array(
|
||||
$this->objectId, $host["name"]." alias", $host["name"], $host["address"], $this->objectId,
|
||||
$host["icon_image"], $host["notes_url"], $host["action_url"]
|
||||
));
|
||||
$insertHostStatusQuery->execute(array(
|
||||
$this->objectId, $host["state"], date($this->datetimeFormat, $flags->time),
|
||||
date($this->datetimeFormat, $flags->time), $flags->notifications, $flags->active_checks,
|
||||
$flags->passive_checks, $flags->flapping, $flags->in_downtime, "Plugin output for host ".$host["name"],
|
||||
"Long plugin output for host ".$host["name"], $flags->acknowledged, $flags->is_pending == 0
|
||||
));
|
||||
|
||||
foreach($host["contacts"] as $contact) {
|
||||
$insertContactQuery->execute(array($this->objectId, $contact["object_id"]));
|
||||
}
|
||||
foreach($host["customvariables"] as $cvName=>$cvValue) {
|
||||
$insertCVQuery->execute(array($this->objectId, $cvName, $cvValue));
|
||||
}
|
||||
|
||||
$host["object_id"] = $this->objectId;
|
||||
$this->objectId++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert all services from the provided fixture into the IDO database
|
||||
*
|
||||
* This method updates the icinga_objects, icinga_services, icinga_servicestatus,
|
||||
* icinga_service_contacts, icinga_customvariablestatus
|
||||
*/
|
||||
private function insertServices()
|
||||
{
|
||||
$services = $this->fixture->getServices();
|
||||
$insertObjectQuery = $this->connection->prepare(
|
||||
'INSERT INTO icinga_objects (object_id, objecttype_id, name1, name2, is_active) VALUES (?, 2, ?, ?, 1);'
|
||||
);
|
||||
$insertServiceQuery = $this->connection->prepare(
|
||||
'INSERT INTO icinga_services ('.
|
||||
'service_id, host_object_id, service_object_id, display_name, '.
|
||||
'icon_image, notes_url, action_url'.
|
||||
') VALUES (?, ?, ?, ?, ?, ?, ?)'
|
||||
);
|
||||
$insertServiceStatusQuery = $this->connection->prepare(
|
||||
'INSERT INTO icinga_servicestatus'.
|
||||
'(service_object_id, current_state, last_check, last_state_change, notifications_enabled, '.
|
||||
'active_checks_enabled, passive_checks_enabled, is_flapping, scheduled_downtime_depth,'.
|
||||
'output, long_output, '.
|
||||
'problem_has_been_acknowledged, has_been_checked) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) '
|
||||
);
|
||||
$insertContactQuery = $this->connection->prepare(
|
||||
'INSERT INTO icinga_service_contacts (host_id, contact_object_id) VALUES (?, ?);'
|
||||
);
|
||||
$insertCVQuery = $this->connection->prepare(
|
||||
'INSERT INTO icinga_customvariablestatus '.
|
||||
'(object_id, varname, varvalue) VALUES (?, ?, ?)'
|
||||
);
|
||||
|
||||
foreach($services as &$service) {
|
||||
$flags = $service["flags"];
|
||||
|
||||
$insertObjectQuery->execute(array($this->objectId, $service["host"]["name"], $service["name"]));
|
||||
$insertServiceQuery->execute(array(
|
||||
$this->objectId, $service['host']['object_id'], $this->objectId, $service['name'],
|
||||
$service["icon_image"], $service["notes_url"], $service["action_url"]
|
||||
));
|
||||
$insertServiceStatusQuery->execute(array(
|
||||
$this->objectId, $service["state"], date($this->datetimeFormat, $flags->time),
|
||||
date($this->datetimeFormat, $flags->time), $flags->notifications, $flags->active_checks,
|
||||
$flags->passive_checks, $flags->flapping, $flags->in_downtime, "Plugin output for service ".$service["name"],
|
||||
"Long plugin output for service ".$service["name"], $flags->acknowledged,
|
||||
$flags->is_pending == 0 ? '1' : '0'
|
||||
));
|
||||
|
||||
foreach($service["contacts"] as $contact) {
|
||||
$insertContactQuery->execute(array($this->objectId, $contact["object_id"]));
|
||||
}
|
||||
|
||||
foreach($service["customvariables"] as $cvName=>$cvValue) {
|
||||
$insertCVQuery->execute(array($this->objectId, $cvName, $cvValue));
|
||||
}
|
||||
|
||||
$service["object_id"] = $this->objectId;
|
||||
$this->objectId++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert the contacts provided by the fixture into the database
|
||||
*
|
||||
* This method updates the icinga_objects and icinga_contacts tables
|
||||
* according to the provided fixture
|
||||
*/
|
||||
private function insertContacts()
|
||||
{
|
||||
$insertObjectQuery = $this->connection->prepare(
|
||||
'INSERT INTO icinga_objects (object_id, objecttype_id, name1) VALUES (?, 10, ?);'
|
||||
);
|
||||
$insertContactQuery = $this->connection->prepare(
|
||||
'INSERT INTO icinga_contacts (contact_object_id, alias) VALUES (?, ?);'
|
||||
);
|
||||
$contacts = $this->fixture->getContacts();
|
||||
foreach($contacts as &$contact) {
|
||||
$insertObjectQuery->execute($this->objectId, $contact["alias"]);
|
||||
$insertContactQuery->execute($this->objectId, $contact["alias"]);
|
||||
$contact["object_id"] = $this->objectId;
|
||||
$this->objectId++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert comments provided by the fixture into the IDO database
|
||||
*
|
||||
* This method updates the icinga_comments table according to the provided
|
||||
* fixture
|
||||
*/
|
||||
private function insertComments()
|
||||
{ $comment_id=0;
|
||||
$insertCommentsQuery = $this->connection->prepare(
|
||||
'INSERT INTO icinga_comments (object_id, comment_type, internal_comment_id, author_name, comment_data)'.
|
||||
' VALUES (?, ?, ?, ?, ?);'
|
||||
);
|
||||
$comments = $this->fixture->getComments();
|
||||
foreach ($comments as $comment) {
|
||||
if (isset($comment["host"])) {
|
||||
$type = 1;
|
||||
$object_id = $comment["host"]["object_id"];
|
||||
} elseif (isset($comment["service"])) {
|
||||
$type = 2;
|
||||
$object_id = $comment["service"]["object_id"];
|
||||
}
|
||||
$insertCommentsQuery->execute(array(
|
||||
$object_id, $type, $comment_id++, $comment["author"], $comment["text"]
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert hostgroups from the provided fixture into the IDO database
|
||||
*
|
||||
* This method updates the icinga_objects, icinga_hostgroups and icinga_hostgroup_members
|
||||
* table with the values provide by the fixture
|
||||
*/
|
||||
private function insertHostgroups()
|
||||
{
|
||||
$insertObjectQuery = $this->connection->prepare(
|
||||
'INSERT INTO icinga_objects (object_id, objecttype_id, name1) VALUES (?, 3, ?)'
|
||||
);
|
||||
$insertHostgroupQuery = $this->connection->prepare(
|
||||
'INSERT INTO icinga_hostgroups (hostgroup_id, hostgroup_object_id, alias) VALUES (?, ?, ?)'
|
||||
);
|
||||
$insertHostgroupMemberQuery = $this->connection->prepare(
|
||||
'INSERT INTO icinga_hostgroup_members (hostgroup_id, host_object_id) VALUES (?, ?)'
|
||||
);
|
||||
$hostgroups = $this->fixture->getHostgroups();
|
||||
|
||||
foreach ($hostgroups as &$hostgroup) {
|
||||
$insertObjectQuery->execute(array($this->objectId, $hostgroup["name"]));
|
||||
$insertHostgroupQuery->execute(array($this->objectId, $this->objectId, $hostgroup["name"]));
|
||||
foreach ($hostgroup["members"] as $member) {
|
||||
$insertHostgroupMemberQuery->execute(array($this->objectId, $member["object_id"]));
|
||||
}
|
||||
$this->objectId++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert servicegroups from the provided fixture into the IDO database
|
||||
*
|
||||
* This method updates the icinga_objects, icinga_servicegroups and icinga_servicegroup_members
|
||||
* table with the values provide by the fixture
|
||||
*/
|
||||
private function insertServicegroups()
|
||||
{
|
||||
$insertObjectQuery = $this->connection->prepare(
|
||||
'INSERT INTO icinga_objects (object_id, objecttype_id, name1) VALUES (?, 4, ?)'
|
||||
);
|
||||
$insertServicegroupQuery = $this->connection->prepare(
|
||||
'INSERT INTO icinga_servicegroups (servicegroup_id, servicegroup_object_id, alias) VALUES (?, ?, ?)'
|
||||
);
|
||||
$insertServicegroupMemberQuery = $this->connection->prepare(
|
||||
'INSERT INTO icinga_servicegroup_members (servicegroup_id, service_object_id) VALUES (?, ?)'
|
||||
);
|
||||
$servicegroups = $this->fixture->getServicegroups();
|
||||
|
||||
foreach ($servicegroups as &$servicegroup) {
|
||||
$insertObjectQuery->execute(array($this->objectId, $servicegroup["name"]));
|
||||
$insertServicegroupQuery->execute(array($this->objectId, $this->objectId, $servicegroup["name"]));
|
||||
foreach ($servicegroup["members"] as $member) {
|
||||
$insertServicegroupMemberQuery->execute(array($this->objectId, $member["object_id"]));
|
||||
}
|
||||
$this->objectId++;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,102 +0,0 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - 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\Testlib\Datasource\Strategies;
|
||||
|
||||
/***
|
||||
* SetupStrategy implementation for PostgreSQL based IDO-Backends
|
||||
*
|
||||
* This strategy creates a new PostgreSQL Database and removes old ones
|
||||
* if necessary. Per default the database user is icinga_unittest:icinga_unittest
|
||||
* and the database to be created is also icinga_unittest.
|
||||
**/
|
||||
class PgSQLSetupStrategy implements SetupStrategy {
|
||||
|
||||
/**
|
||||
* Tears down any existing databases and creates a new blank IDO scheme.
|
||||
*
|
||||
* The database is created according to the passed version (or using the
|
||||
* newest version if no version is provided), using the idoPgSQL-%VERSION%.sql
|
||||
* underneath the schemes folder.
|
||||
* A \PDO Connection can be provided, if not the icinga_unittest default
|
||||
* connection will be established and used.
|
||||
*
|
||||
* @param String $version An optional version to use as the db scheme
|
||||
* @param \PDO $connection An optional connection to use instead of icinga_unittest
|
||||
* @return \PDO The connection that has been created
|
||||
*
|
||||
* @throws \PDOException In case connecting to or creating the database fails
|
||||
* @throws \Exception In case of an invalid/non-existing DB scheme
|
||||
*/
|
||||
public function setup($version = null, $connection = null)
|
||||
{
|
||||
if ($connection === null) {
|
||||
$connection = new \PDO('pgsql:dbname=icinga_unittest', 'icinga_unittest', 'icinga_unittest');
|
||||
}
|
||||
|
||||
$connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
||||
$this->teardown($connection);
|
||||
|
||||
// the latest schema doesn't have a suffix, so if no version is given this one is used
|
||||
$sqlFileName = 'idoPgSQL'.($version !== null ? '-'.$version : '' ).'.sql';
|
||||
$path = realpath(dirname(__FILE__).'/../schemes/'.$sqlFileName);
|
||||
if (!file_exists($path)) {
|
||||
throw new \Exception('File '.$path.' not found: Could not create scheme for IDO pgsql backend '.($version ? '(version : '.$version.')' :''));
|
||||
}
|
||||
$connection->setAttribute(\PDO::ATTR_EMULATE_PREPARES, true);
|
||||
|
||||
if ($connection->query(file_get_contents($path)) === false) {
|
||||
$error = $connection->errorInfo();;
|
||||
throw new \PDOException($error[0].' : '.$error[2]);
|
||||
}
|
||||
return $connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Drops all tables from the connection via DROP TABLE
|
||||
*
|
||||
* @param \PDO $connection An optional connection to use, if none is
|
||||
* given the icinga_unittest default will be used
|
||||
*
|
||||
*/
|
||||
public function teardown($connection = null)
|
||||
{
|
||||
if ($connection === null) {
|
||||
$connection = new \PDO('pgsql:dbname=icinga_unittest', 'icinga_unittest', 'icinga_unittest');
|
||||
}
|
||||
$tables = $connection
|
||||
->query('SELECT table_schema,table_name FROM information_schema.tables WHERE table_type = \'BASE TABLE\''.
|
||||
'AND table_schema = \'public\' ORDER BY table_schema,table_name;')
|
||||
->fetchAll();
|
||||
|
||||
foreach($tables as $table) {
|
||||
$connection->query('DROP TABLE '.$table['table_name']);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Test\Monitoring\Testlib\Datasource\Strategies;
|
||||
/**
|
||||
* Interface for setup classes that provide a clean starting point
|
||||
* for @see InsertionStrategy classes to setup TestFixtures.
|
||||
*
|
||||
* As the backend for the setupstrategy can be anything from a database to
|
||||
* a file to a socket, the resource is a mixed php type and the
|
||||
* concrete requirement on the type is defined by the subclass implementing
|
||||
* this interface.
|
||||
*
|
||||
*/
|
||||
interface SetupStrategy {
|
||||
|
||||
/**
|
||||
* Set up a new clean datastore icinga backends can use for querying data
|
||||
*
|
||||
* The resource parameter should be optional, as the setup class should provide
|
||||
* a default setup method most testing setups can use
|
||||
*
|
||||
* @param String $version The optional version of the storage implementation to create
|
||||
* @param mixed $resource The optional resource to use for setting up the storage
|
||||
*
|
||||
* @return mixed The connection or resource that has been created
|
||||
*/
|
||||
public function setup($version = null, $resource = null);
|
||||
|
||||
/**
|
||||
* Remove all data from the given resource (or the default resource if none is given)
|
||||
*
|
||||
* @param mixed $resource
|
||||
*/
|
||||
public function teardown($resource = null);
|
||||
}
|
|
@ -1,320 +0,0 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - 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\Testlib\Datasource\Strategies;
|
||||
use Test\Monitoring\Testlib\DataSource\schemes\ObjectsCacheTemplates;
|
||||
use \Test\Monitoring\Testlib\DataSource\TestFixture;
|
||||
use \Test\Monitoring\Testlib\DataSource\schemes\StatusdatTemplates;
|
||||
|
||||
require_once(dirname(__FILE__).'/../schemes/ObjectsCacheTemplates.php');
|
||||
require_once(dirname(__FILE__).'/../schemes/StatusdatTemplates.php');
|
||||
|
||||
/**
|
||||
* An @see InsertionStrategy for creating status.dat and objects.cache
|
||||
* files from a TestFixture
|
||||
*
|
||||
* This class helps testing status.dat backends by writing testfixtures
|
||||
* to according objects.cache and status.dat files which then can be read
|
||||
* by the Statusdat parser and used in tests.
|
||||
*
|
||||
* The Templates for insertion can be found under schemes/objectsCacheTemplates.php
|
||||
* and schemes/StatusdatTempaltes.php
|
||||
*
|
||||
*/
|
||||
class StatusdatInsertionStrategy implements InsertionStrategy {
|
||||
|
||||
/**
|
||||
* The status.dat filename to write the object-state to
|
||||
* @var String
|
||||
*/
|
||||
private $statusDatFile;
|
||||
|
||||
/**
|
||||
* The objects.cache filename to write the object structure to
|
||||
* @var String
|
||||
*/
|
||||
private $objectsCacheFile;
|
||||
|
||||
/**
|
||||
* The TestFixture that will be written to a status.dat compatible format
|
||||
* @var TestFixture
|
||||
*/
|
||||
private $fixture;
|
||||
|
||||
/**
|
||||
* The content of the status.dat file that will be written
|
||||
* @var String
|
||||
*/
|
||||
private $statusDat;
|
||||
|
||||
/**
|
||||
* The content of the objects.cache file that will be written
|
||||
* @var String
|
||||
*/
|
||||
private $objectsCache;
|
||||
|
||||
/**
|
||||
* Tell this object to use the status.dat/objects.cache file combination
|
||||
* provided in $resource
|
||||
*
|
||||
* @param Array $ressource An associative array containing the following keys:
|
||||
* - "status_file" : The location where to write the status.dat to
|
||||
* - "objects_file" : The location to write the objects cache to
|
||||
*/
|
||||
public function setConnection($ressource)
|
||||
{
|
||||
$this->statusDatFile = $ressource['status_file'];
|
||||
$this->objectsCacheFile = $ressource['object_file'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert the provided fixture into the status.dat and objects.cache files for testing
|
||||
*
|
||||
* @param TestFixture $fixture The fixture to create status.dat and objects.cache files from
|
||||
*/
|
||||
public function insert(TestFixture $fixture)
|
||||
{
|
||||
$this->fixture = $fixture;
|
||||
$this->statusDat = '# Automatically created test statusdat from fixture\n';
|
||||
$this->objectsCache = '';
|
||||
$this->insertHoststatus();
|
||||
$this->insertHosts();
|
||||
$this->insertServicestatus();
|
||||
$this->insertServices();
|
||||
|
||||
$this->insertHostgroups();
|
||||
$this->insertServicegroups();
|
||||
$this->insertComments();
|
||||
|
||||
file_put_contents($this->statusDatFile, $this->statusDat);
|
||||
file_put_contents($this->objectsCacheFile, $this->objectsCache);
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert the host monitoring state from the provided fixture to the internal
|
||||
* statusdat string $statusDat
|
||||
*
|
||||
*/
|
||||
private function insertHoststatus()
|
||||
{
|
||||
$hosts = $this->fixture->getHosts();
|
||||
foreach ($hosts as $host) {
|
||||
$cvs = '';
|
||||
foreach ($host['customvariables'] as $name=>$var) {
|
||||
$cvs .= '_'.$name.'='.$var."\n";
|
||||
}
|
||||
$flags = $host['flags'];
|
||||
$hostStatus = str_replace(
|
||||
array(
|
||||
'{{HOST_NAME}}', '{{TIME}}', '{{NOTIFICATIONS_ENABLED}}',
|
||||
'{{ACKNOWLEDGED}}', '{{ACTIVE_ENABLED}}', '{{PASSIVE_ENABLED}}',
|
||||
'{{FLAPPING}}', '{{IN_DOWNTIME}}', '{{HOST_STATUS}}','{{CVS}}')
|
||||
, array(
|
||||
$host['name'], $flags->time, $flags->notifications, $flags->acknowledged,
|
||||
$flags->active_checks, $flags->passive_checks, $flags->flapping,
|
||||
$flags->in_downtime, $host['state'], $cvs
|
||||
), StatusdatTemplates::$HOST);
|
||||
$this->statusDat .= "\n".$hostStatus;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert the host object state into the internal objects.cache representation
|
||||
* $objectsCache
|
||||
*
|
||||
*/
|
||||
private function insertHosts()
|
||||
{
|
||||
$hosts = $this->fixture->getHosts();
|
||||
foreach ($hosts as $host) {
|
||||
if ($host['flags']->is_pending) {
|
||||
continue; // Pending states are not written to status.dat yet
|
||||
}
|
||||
$hostDefinition = str_replace(
|
||||
array('\t',
|
||||
'{{HOST_NAME}}', '{{HOST_ADDRESS}}', '{{ICON_IMAGE}}',
|
||||
'{{NOTES_URL}}', '{{ACTION_URL}}'
|
||||
),
|
||||
array("\t",
|
||||
$host['name'], $host['address'], $host['icon_image'],
|
||||
$host['notes_url'], $host['action_url']
|
||||
),
|
||||
ObjectsCacheTemplates::$HOST
|
||||
);
|
||||
$this->objectsCache .= "\n".$hostDefinition;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert the service monitoring state from the provided fixture to the internal
|
||||
* statusdat string $statusDat
|
||||
*
|
||||
*/
|
||||
private function insertServicestatus()
|
||||
{
|
||||
$services = $this->fixture->getServices();
|
||||
foreach ($services as $service) {
|
||||
if ($service['flags']->is_pending) {
|
||||
continue; // Pending states are not written to status.dat yet
|
||||
}
|
||||
$cvs = '';
|
||||
foreach ($service['customvariables'] as $name=>$var) {
|
||||
$cvs .= '_'.$name.'='.$var;
|
||||
}
|
||||
|
||||
$flags = $service['flags'];
|
||||
$serviceStatus = str_replace(
|
||||
array(
|
||||
'{{HOST_NAME}}','{{SERVICE_NAME}}', '{{TIME}}', '{{NOTIFICATIONS_ENABLED}}',
|
||||
'{{ACKNOWLEDGED}}', '{{ACTIVE_ENABLED}}', '{{PASSIVE_ENABLED}}',
|
||||
'{{FLAPPING}}', '{{IN_DOWNTIME}}', '{{SERVICE_STATUS}}','{{CVS}}')
|
||||
, array(
|
||||
$service['host']['name'], $service['name'], $flags->time, $flags->notifications,
|
||||
$flags->acknowledged, $flags->active_checks, $flags->passive_checks,
|
||||
$flags->flapping, $flags->in_downtime, $service['state'], $cvs
|
||||
), StatusdatTemplates::$SERIVCE);
|
||||
|
||||
$this->statusDat .= "\n".$serviceStatus;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert the service object state into the internal objects.cache representation
|
||||
* $objectsCache
|
||||
*
|
||||
*/
|
||||
private function insertServices()
|
||||
{
|
||||
$services = $this->fixture->getServices();
|
||||
foreach ($services as $service) {
|
||||
$serviceDefinition = str_replace(
|
||||
array('\t',
|
||||
'{{HOST_NAME}}', '{{SERVICE_NAME}}', '{{ICON_IMAGE}}',
|
||||
'{{NOTES_URL}}', '{{ACTION_URL}}'
|
||||
),
|
||||
array("\t",
|
||||
$service['host']['name'], $service['name'], $service['icon_image'],
|
||||
$service['notes_url'], $service['action_url']
|
||||
),
|
||||
ObjectsCacheTemplates::$SERVICE
|
||||
);
|
||||
$this->objectsCache .= "\n".$serviceDefinition;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts a group object into the object.cache file
|
||||
*
|
||||
* @param String $type The type of the group ('host' or 'service')
|
||||
* @param String $name The name of the group to insert
|
||||
* @param array $members A String array of the members names to use
|
||||
*/
|
||||
private function insertGroup($type, $name, array $members)
|
||||
{
|
||||
$groupDefinition = str_replace(
|
||||
array('\t',
|
||||
'{{TYPE}}', '{{NAME}}', '{{MEMBERS}}'
|
||||
),
|
||||
array("\t",
|
||||
$type, $name, implode(",", $members)
|
||||
),
|
||||
ObjectsCacheTemplates::$GROUP
|
||||
);
|
||||
$this->objectsCache .= "\n".$groupDefinition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert all hostgroups from the fixtures into the objects.cache
|
||||
*
|
||||
*/
|
||||
private function insertHostgroups()
|
||||
{
|
||||
$hostgroups = $this->fixture->getHostgroups();
|
||||
foreach ($hostgroups as $hostgroup) {
|
||||
$memberNames = array();
|
||||
foreach ($hostgroup["members"] as $member) {
|
||||
$memberNames[] = $member["name"];
|
||||
}
|
||||
$this->insertGroup("host", $hostgroup["name"], $memberNames);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts all servicegroups from the fixtures into the objects.cache
|
||||
*
|
||||
*/
|
||||
private function insertServicegroups()
|
||||
{
|
||||
$servicegroups = $this->fixture->getServicegroups();
|
||||
foreach ($servicegroups as $servicegroup) {
|
||||
$memberNames = array();
|
||||
foreach ($servicegroup["members"] as $member) {
|
||||
$memberNames[] = $member["host"]["name"];
|
||||
$memberNames[] = $member["name"];
|
||||
}
|
||||
$this->insertGroup("service", $servicegroup["name"], $memberNames);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts all comments from the fixtures into the status.dat string
|
||||
* $statusDat
|
||||
*
|
||||
*/
|
||||
private function insertComments()
|
||||
{
|
||||
$comments = $this->fixture->getComments();
|
||||
$commentId = 1;
|
||||
foreach($comments as $comment) {
|
||||
if (isset($comment["service"])) {
|
||||
$service = $comment["service"];
|
||||
$commentDefinition = str_replace(
|
||||
array('{{HOST_NAME}}', '{{SERVICE_NAME}}', '{{TIME}}', '{{AUTHOR}}', '{{TEXT}}', '{{ID}}'),
|
||||
array(
|
||||
$service["host"]["name"], $service["name"], $service["flags"]->time,
|
||||
$comment["author"], $comment["text"], $commentId++
|
||||
),
|
||||
StatusdatTemplates::$SERVICECOMMENT
|
||||
);
|
||||
} elseif (isset($comment["host"])) {
|
||||
$host = $comment["host"];
|
||||
$commentDefinition = str_replace(
|
||||
array('{{HOST_NAME}}', '{{TIME}}', '{{AUTHOR}}', '{{TEXT}}', '{{ID}}'),
|
||||
array(
|
||||
$host["name"], $host["flags"]->time,
|
||||
$comment["author"], $comment["text"], $commentId++
|
||||
),
|
||||
StatusdatTemplates::$HOSTCOMMENT
|
||||
);
|
||||
}
|
||||
$this->statusDat .= "\n".$commentDefinition;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,126 +0,0 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - 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\Testlib\Datasource\Strategies;
|
||||
|
||||
use Tests\Icinga\Protocol\Statusdat\StatusdatTestLoader;
|
||||
/**
|
||||
* SetupStrategy for status dat.
|
||||
*
|
||||
* This class is used for setting up a test enviromnent for querying
|
||||
* statusdat fixtures.
|
||||
*
|
||||
*/
|
||||
class StatusdatSetupStrategy implements SetupStrategy {
|
||||
|
||||
/**
|
||||
* Recursively require all php files underneath $folder
|
||||
*
|
||||
* @param String $folder The folder to require
|
||||
*/
|
||||
private function requireFolder($folder)
|
||||
{
|
||||
$files = scandir($folder);
|
||||
foreach($files as $file) {
|
||||
if ($file[0] == ".") {
|
||||
continue;
|
||||
}
|
||||
if (is_dir($folder."/".$file)) {
|
||||
$this->requireFolder($folder."/".$file);
|
||||
} elseif (preg_match("/\.php/", $file)) {
|
||||
require_once(realpath($folder."/".$file));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Require all classes needed to work with the status.dat Reader
|
||||
*
|
||||
* This includes the Status.dat Reader and Parser classes
|
||||
* from Icinga/PRotocol as well as a few dependencies (Logging, Zend_Cache)
|
||||
*
|
||||
*/
|
||||
private function requireStatusDat()
|
||||
{
|
||||
require_once 'library/Icinga/Protocol/Statusdat/StatusdatTestLoader.php';
|
||||
StatusdatTestLoader::requireLibrary();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the status.dat and objects.cache files for using testfixtures
|
||||
*
|
||||
* Remove existing files for status.dat testfixtures and create new
|
||||
* (empty) files at /tmp/ when no resource is given.
|
||||
*
|
||||
* @param String $version The version to use, will be ignored
|
||||
* @param array $resource An optional associative array pointing to the
|
||||
* objects_cache and status.dat files. The keys are as following:
|
||||
* - "status_file" : Path to the status.dat to remove and recreate
|
||||
* - "objects_file" : Path to the objects.cache file to remove and recreate
|
||||
* @return array An path array (see $resource) that contains the used file paths
|
||||
*/
|
||||
public function setup($version = null, $resource = null)
|
||||
{
|
||||
if ($resource == null) {
|
||||
$resource = array(
|
||||
"status_file" => "/tmp/teststatus.dat",
|
||||
"object_file" => "/tmp/testobjects.cache"
|
||||
);
|
||||
}
|
||||
$this->requireStatusDat();
|
||||
$this->teardown($resource);
|
||||
touch($resource["status_file"]);
|
||||
touch($resource["object_file"]);
|
||||
return $resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove test status.dat and objects.cache files
|
||||
*
|
||||
* @param array $resource An optional associative array pointing to the
|
||||
* objects_cache and status.dat files. The keys are as following:
|
||||
* - "status_file" : Path to the status.dat to remove
|
||||
* - "objects_file" : Path to the objects.cache file to remove
|
||||
*/
|
||||
public function teardown($resource = null)
|
||||
{
|
||||
if ($resource == null) {
|
||||
$resource = array(
|
||||
"status_file" => "/tmp/teststatus.dat",
|
||||
"object_file" => "/tmp/testobjects.cache"
|
||||
);
|
||||
}
|
||||
if (file_exists($resource["status_file"])) {
|
||||
unlink($resource["status_file"]);
|
||||
}
|
||||
if (file_exists($resource["object_file"])) {
|
||||
unlink($resource["object_file"]);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,6 +6,12 @@ class TestInit
|
|||
{
|
||||
$libaryPath = realpath(dirname(__FILE__) . '/../../library/');
|
||||
|
||||
if (!defined('ICINGA_APPDIR')) {
|
||||
define('ICINGA_APPDIR', realpath($libaryPath . '/../application'));
|
||||
}
|
||||
|
||||
$configPath = realpath($libaryPath . '/../config');
|
||||
|
||||
$modulePath = realpath(dirname(__FILE__) . '/../../modules/');
|
||||
|
||||
$applicationPath = realpath(dirname(__FILE__) . '/../../application/');
|
||||
|
@ -53,6 +59,8 @@ class TestInit
|
|||
|
||||
require_once 'Zend/Loader/Autoloader.php';
|
||||
\Zend_Loader_Autoloader::getInstance();
|
||||
|
||||
Icinga\Application\Config::$configDir = $configPath;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,39 +27,22 @@
|
|||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Tests\Icinga\Authentication;
|
||||
namespace Icinga\Tests\Authentication;
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once realpath(__DIR__ . '/../../../../../library/Icinga/Test/BaseTestCase.php');
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
use \Icinga\Test\BaseTestCase;
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once 'Zend/Log.php';
|
||||
require_once 'Zend/Config.php';
|
||||
require_once BaseTestCase::$libDir . '/Logger/Logger.php';
|
||||
require_once BaseTestCase::$libDir . '/Authentication/Manager.php';
|
||||
require_once BaseTestCase::$libDir . '/Authentication/Membership.php';
|
||||
require_once BaseTestCase::$libDir . '/Authentication/Credential.php';
|
||||
require_once BaseTestCase::$libDir . '/Authentication/Membership.php';
|
||||
require_once BaseTestCase::$libDir . '/Exception/ConfigurationError.php';
|
||||
require_once BaseTestCase::$libDir . '/Exception/ProgrammingError.php';
|
||||
require_once BaseTestCase::$libDir . '/Exception/NotReadableError.php';
|
||||
require_once BaseTestCase::$libDir . '/Web/Session.php';
|
||||
require_once 'BackendMock.php';
|
||||
require_once 'ErrorProneBackendMock.php';
|
||||
require_once 'SessionMock.php';
|
||||
// @codingStandardsIgnoreEnd
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
use \Zend_Config;
|
||||
use Icinga\Web\Session;
|
||||
use Icinga\Authentication\Manager as AuthManager;
|
||||
use Icinga\Authentication\Credential;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
use Icinga\Test\Authentication\ErrorProneBackendMock;
|
||||
use Icinga\Test\Authentication\SessionMock;
|
||||
use Icinga\Test\Authentication\BackendMock;
|
||||
|
||||
/**
|
||||
* @backupStaticAttributes enabled
|
||||
* @runTestsInSeparateProcesses
|
||||
*/
|
||||
class ManagerTest extends BaseTestCase
|
||||
{
|
||||
|
@ -76,6 +59,7 @@ class ManagerTest extends BaseTestCase
|
|||
&$session = null,
|
||||
$write = false,
|
||||
$nobackend = false,
|
||||
|
||||
Zend_Config $managerConfig = null
|
||||
) {
|
||||
if ($session == null) {
|
||||
|
@ -152,28 +136,6 @@ class ManagerTest extends BaseTestCase
|
|||
);
|
||||
}
|
||||
|
||||
public function testPersistAuthInSession()
|
||||
{
|
||||
$session = new SessionMock();
|
||||
$auth = $this->getManagerInstance($session, true);
|
||||
$this->assertFalse($auth->isAuthenticated(true));
|
||||
$auth->authenticate(new Credential("jdoe", "passjdoe"));
|
||||
$this->assertNotEquals(null, $session->get("user"));
|
||||
$user = $session->get("user");
|
||||
$this->assertEquals("Username", $user->getUsername());
|
||||
$this->assertTrue($auth->isAuthenticated(true));
|
||||
}
|
||||
|
||||
public function testAuthenticateFromSession()
|
||||
{
|
||||
$session = new SessionMock();
|
||||
$session->set("user", BackendMock::getDummyUser());
|
||||
$auth = $this->getManagerInstance($session, false);
|
||||
$this->assertFalse($auth->isAuthenticated(true));
|
||||
$this->assertTrue($auth->isAuthenticated());
|
||||
$this->assertTrue($auth->isAuthenticated());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Icinga\Exception\ConfigurationError
|
||||
* @expectedExceptionMessage No authentication backend set
|
||||
|
@ -183,7 +145,7 @@ class ManagerTest extends BaseTestCase
|
|||
$managerConfig = new Zend_Config(
|
||||
array(
|
||||
'provider1' => array(
|
||||
'class' => 'Tests\Icinga\Authentication\ErrorProneBackendMock'
|
||||
'class' => 'Icinga\Test\Authentication\ErrorProneBackendMock'
|
||||
)
|
||||
),
|
||||
true
|
||||
|
@ -211,10 +173,10 @@ class ManagerTest extends BaseTestCase
|
|||
$managerConfig = new Zend_Config(
|
||||
array(
|
||||
'provider1' => array(
|
||||
'class' => 'Tests\Icinga\Authentication\ErrorProneBackendMock'
|
||||
'class' => 'Icinga\Test\Authentication\ErrorProneBackendMock'
|
||||
),
|
||||
'provider2' => array(
|
||||
'class' => 'Tests\Icinga\Authentication\ErrorProneBackendMock'
|
||||
'class' => 'Icinga\Test\Authentication\ErrorProneBackendMock'
|
||||
)
|
||||
),
|
||||
true
|
||||
|
@ -225,12 +187,12 @@ class ManagerTest extends BaseTestCase
|
|||
$authManager = $this->getManagerInstance($session, false, true, $managerConfig);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'Tests\Icinga\Authentication\ErrorProneBackendMock',
|
||||
'Icinga\Test\Authentication\ErrorProneBackendMock',
|
||||
$authManager->getUserBackend('provider1')
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'Tests\Icinga\Authentication\ErrorProneBackendMock',
|
||||
'Icinga\Test\Authentication\ErrorProneBackendMock',
|
||||
$authManager->getUserBackend('provider2')
|
||||
);
|
||||
|
||||
|
@ -244,10 +206,12 @@ class ManagerTest extends BaseTestCase
|
|||
$managerConfig = new Zend_Config(
|
||||
array(
|
||||
'provider1' => array(
|
||||
'class' => 'Tests\Icinga\Authentication\BackendMock'
|
||||
'name' => 'provider1',
|
||||
'class' => 'Icinga\Test\Authentication\BackendMock'
|
||||
),
|
||||
'provider2' => array(
|
||||
'class' => 'Tests\Icinga\Authentication\BackendMock'
|
||||
'name' => 'provider2',
|
||||
'class' => 'Icinga\Test\Authentication\BackendMock'
|
||||
)
|
||||
),
|
||||
true
|
||||
|
@ -279,16 +243,16 @@ class ManagerTest extends BaseTestCase
|
|||
$managerConfig = new Zend_Config(
|
||||
array(
|
||||
'provider1' => array(
|
||||
'class' => 'Tests\Icinga\Authentication\ErrorProneBackendMock'
|
||||
'class' => 'Icinga\Test\Authentication\ErrorProneBackendMock'
|
||||
),
|
||||
'provider2' => array(
|
||||
'class' => 'Tests\Icinga\Authentication\ErrorProneBackendMock'
|
||||
'class' => 'Icinga\Test\Authentication\ErrorProneBackendMock'
|
||||
),
|
||||
'provider3' => array(
|
||||
'class' => 'Tests\Icinga\Authentication\ErrorProneBackendMock'
|
||||
'class' => 'Icinga\Test\Authentication\ErrorProneBackendMock'
|
||||
),
|
||||
'provider4' => array(
|
||||
'class' => 'Tests\Icinga\Authentication\BackendMock'
|
||||
'class' => 'Icinga\Test\Authentication\BackendMock'
|
||||
)
|
||||
),
|
||||
true
|
||||
|
@ -297,12 +261,12 @@ class ManagerTest extends BaseTestCase
|
|||
$authManager = $this->getManagerInstance($session, false, true, $managerConfig);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'Tests\Icinga\Authentication\ErrorProneBackendMock',
|
||||
'Icinga\Test\Authentication\ErrorProneBackendMock',
|
||||
$authManager->getUserBackend('provider1')
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'Tests\Icinga\Authentication\BackendMock',
|
||||
'Icinga\Test\Authentication\BackendMock',
|
||||
$authManager->getUserBackend('provider4')
|
||||
);
|
||||
|
||||
|
|
|
@ -1,88 +0,0 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - 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 Tests\Icinga\Web\Widget\Tabextension;
|
||||
|
||||
require_once('../../library/Icinga/Web/Widget/Widget.php');
|
||||
require_once('../../library/Icinga/Web/Widget/Tab.php');
|
||||
require_once('../../library/Icinga/Web/Widget/Tabs.php');
|
||||
require_once('../../library/Icinga/Web/Widget/Tabextension/Tabextension.php');
|
||||
require_once('../../library/Icinga/Web/Widget/Tabextension/OutputFormat.php');
|
||||
require_once('../../library/Icinga/Web/Url.php');
|
||||
|
||||
require_once('library/Icinga/Web/RequestMock.php');
|
||||
require_once('library/Icinga/Web/ViewMock.php');
|
||||
|
||||
require_once('Zend/View/Abstract.php');
|
||||
|
||||
use Icinga\Web\View;
|
||||
use Icinga\Web\Url;
|
||||
use Icinga\Web\Widget\Tabextension\OutputFormat;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use Icinga\Web\Widget\Tabs;
|
||||
use Tests\Icinga\Web\RequestMock;
|
||||
use Tests\Icinga\Web\ViewMock;
|
||||
use \Zend_View_Abstract;
|
||||
|
||||
/**
|
||||
* Test for the OutputFormat Tabextension
|
||||
*
|
||||
*/
|
||||
class OutputFormatTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Test if a simple apply adds all tabs from the extender
|
||||
*
|
||||
*/
|
||||
public function testApply()
|
||||
{
|
||||
$tabs = new Tabs();
|
||||
Url::$overwrittenRequest = new RequestMock();
|
||||
$tabs->extend(new OutputFormat());
|
||||
$this->assertEquals(3, $tabs->count(), "Asserting new tabs being available after extending the tab bar");
|
||||
Url::$overwrittenRequest = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if an apply with disabled output formats doesn't add these tabs
|
||||
*
|
||||
*/
|
||||
public function testDisableOutputFormat()
|
||||
{
|
||||
Url::$overwrittenRequest = new RequestMock();
|
||||
$tabs = new Tabs();
|
||||
$tabs->extend(new OutputFormat(array(OutputFormat::TYPE_PDF)));
|
||||
$this->assertEquals(
|
||||
2,
|
||||
$tabs->count(),
|
||||
"Asserting two tabs being available after extending the tab bar and ignoring PDF"
|
||||
);
|
||||
Url::$overwrittenRequest = null;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue