/**
  * Initialize this AgaviLoggingManager.
  *
  * @param      AgaviContext An AgaviContext instance.
  * @param      array        An array of initialization parameters.
  *
  * @throws     <b>AgaviInitializationException</b> If an error occurs while
  *                                                 initializing this instance.
  *
  * @author     David Zülke <*****@*****.**>
  * @author     Sean Kerr <*****@*****.**>
  * @since      0.9.0
  */
 public function initialize(AgaviContext $context, array $parameters = array())
 {
     $this->context = $context;
     if (isset($parameters['default_message_class'])) {
         $this->defaultMessageClass = $parameters['default_message_class'];
     }
     // load logging configuration
     require AgaviConfigCache::checkConfig(AgaviConfig::get('core.config_dir') . '/logging.xml', $context->getName());
 }
 public function initialize(AgaviContext $ctx, AgaviParameterHolder $p)
 {
     parent::initialize($context, $p);
     $time = $p->getParameter("default_timespan", AgaviConfig::get("modukle.api.sla_settings,default_timespan"));
     $this->defaultStartDate = @strtotime($time);
     if ($this->defaultStartDate === false) {
         $ctx->getLoggerManager()->log("Warning: Invalid SLA default timespan " + $time + " provided, using -90 days");
         $this->defaultStartDate = @strtotime("-90 days");
     }
     if ($this->defaultStartDate === false) {
         throw new AppKitException("Couldn't set sla default_timespan");
     }
 }
Пример #3
0
 /**
  * @group Interface
  */
 public function testIcingaStatus()
 {
     $context = AgaviContext::getInstance();
     $icingaCmd = $context->getModel("IcingaControlTask", "Api", array("host" => "vm_host1"));
     $code = $icingaCmd->getIcingaStatus();
     $this->assertTrue($code < 2, "Icinga status returned code " . $code);
 }
 /**
  * Returns the SLA Summary (@see IcingaSLASummary) for this filter
  *
  * @param Doctrine_Connection $dbConnection
  * @param type $filter
  * @return Doctrine_Collection
  */
 public static function getSummary(Doctrine_Connection $dbConnection = null, $filter = null)
 {
     if ($dbConnection == null) {
         $dbConnection = AgaviContext::getInstance()->getDatabaseConnection("icinga");
     }
     $driver = $dbConnection->getDriverName();
     $stmt = null;
     switch (strtolower($driver)) {
         case 'pgsql':
             $stmt = self::getPgsqlSummaryQuery($dbConnection, $filter);
             break;
         case 'oracle':
         case 'icingaoracle':
             $stmt = self::getOracleSummaryQuery($dbConnection, $filter);
             break;
         case 'mysql':
             $stmt = self::getMySQLSummaryQuery($dbConnection, $filter);
             break;
         default:
             throw new AppKitDoctrineException("Invalid driver " . $driver);
     }
     $stmt->execute();
     $result = new Doctrine_Collection("IcingaSLASummary");
     while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
         $record = new IcingaSLASummary();
         foreach ($row as $key => $value) {
             $record->{strtolower($key)} = $value;
         }
         $result->add($record);
     }
     return $result;
 }
 public function __construct($table = null, $isNewEntry = false)
 {
     $dbalmm = AgaviContext::getInstance()->getModel("Api_DBALMetaManagerModel", "Api");
     $db = $dbalmm->getCurrentDB();
     Doctrine_Manager::getInstance()->bindComponent($this->get, $db);
     parent::__construct($table, $isNewEntry);
 }
Пример #6
0
 public function __construct()
 {
     if (file_exists($this->icingaWebDir . '/app/config.php')) {
         require $this->icingaWebDir . '/lib/agavi/src/agavi.php';
         require $this->icingaWebDir . '/app/config.php';
         require_once $this->icingaWebDir . '/lib/doctrine/lib/Doctrine/Exception.php';
         require_once $this->icingaWebDir . '/lib/doctrine/lib/Doctrine/Locator/Injectable.php';
         require_once $this->icingaWebDir . '/lib/doctrine/lib/Doctrine/Access.php';
         require_once $this->icingaWebDir . '/lib/doctrine/lib/Doctrine/Record/Abstract.php';
         require_once $this->icingaWebDir . '/lib/doctrine/lib/Doctrine/Record.php';
         require_once $this->icingaWebDir . '/lib/doctrine/lib/Doctrine/Record/Iterator.php';
         require_once $this->icingaWebDir . '/lib/doctrine/lib/Doctrine/Null.php';
         require_once $this->icingaWebDir . '/lib/doctrine/lib/Doctrine/Core.php';
         require_once $this->icingaWebDir . '/lib/doctrine/lib/Doctrine/Configurable.php';
         require_once $this->icingaWebDir . '/lib/doctrine/lib/Doctrine/Manager/Exception.php';
         require_once $this->icingaWebDir . '/lib/doctrine/lib/Doctrine/Manager.php';
         require_once $this->icingaWebDir . '/app/modules/AppKit/lib/database/models/generated/BaseNsmUser.php';
         require_once $this->icingaWebDir . '/app/modules/AppKit/lib/database/models/NsmUser.php';
         Agavi::bootstrap('production');
         AgaviConfig::set('core.default_context', 'web');
         AgaviConfig::set('core.context_implementation', 'AppKitAgaviContext');
         AgaviContext::getInstance('web')->getController()->dispatch();
         $icingWebUser = new NsmUser('nsm_user');
         //                $icingWebUser->
         $icingWebUser->updatePassword($newPassword);
     }
 }
 private function addPrincipalsToFilter(&$filter)
 {
     $user = AgaviContext::getInstance()->getUser()->getNsmUser();
     $sarr = $user->getTargetValuesArray();
     foreach ($sarr as $principal => $values) {
         switch ($principal) {
             case 'IcingaHostgroup':
                 $filter->setHostgroupNames($values[0]);
                 break;
             case 'IcingaServicegroup':
                 $filter->setServicegroupNames($values[0]);
                 break;
             case 'IcingaHostCustomVariablePair':
                 foreach ($values as $cv) {
                     $filter->addHostCV($cv["cv_name"], $cv["cv_value"]);
                 }
                 break;
             case 'IcingaServiceCustomVariablePair':
                 foreach ($values as $cv) {
                     $filter->addServiceCV($cv["cv_name"], $cv["cv_value"]);
                 }
                 break;
         }
     }
 }
Пример #8
0
 /**
  * @depends testReadState
  * @group Database
  */
 public function testSaveState()
 {
     info("\tTesting state-save\n");
     $token = str_shuffle("ABCDEF123456789");
     $params = array("cmd" => "write", "data" => '[{"name":"test-case-setting","value":"TEST_CASE_' . $token . '"}]', "id" => 1, "session" => "session", "user" => "user");
     $paramHolder = new AgaviRequestDataHolder();
     $paramHolder->setParameters($params);
     $controller = AgaviContext::getInstance()->getController();
     $container = $controller->createExecutionContainer("AppKit", "Ext.ApplicationState", $paramHolder, "javascript", "write");
     try {
         $result = $container->execute();
         $data = json_decode($result->getContent(), true);
     } catch (Exception $e) {
         $this->fail("An exception was thrown during state write: " . $e->getMessage());
     }
     // Check for success state
     if (@(!$data["success"])) {
         $this->fail("Could not write view state! Your cronk settings may not be saved in icinga-web.");
     }
     // Finally get sure the enry is really set
     $entryFound = false;
     foreach ($data["data"] as $entry) {
         if ($entry["name"] == 'test-case-setting' && $entry["value"] == 'TEST_CASE_' . $token) {
             $entryFound = true;
         }
     }
     if (!$entryFound) {
         $this->fail("Write returned success, but preference could not be found in DB!\n");
     }
     success("\tWriting state succeeded!\n");
 }
Пример #9
0
 public function getContext()
 {
     if (!$this->context) {
         $this->context = AgaviContext::getInstance();
     }
     return $this->context;
 }
Пример #10
0
 public function testGetServices()
 {
     info("Testing service retrieval\n");
     $model = AgaviContext::getInstance()->getModel("ApiServiceRequest", "Api");
     $this->assertFalse(is_null($model->getServices()));
     $this->assertEquals($model->getServices(array(200))->count(), 1);
 }
Пример #11
0
 /**
  * @runInSeparateProcess
  */
 public function testStaticSessionId()
 {
     $context = AgaviContext::getInstance('agavi-session-storage-test::tests-static-session-id');
     $storage = new AgaviSessionStorage();
     $storage->initialize($context);
     $storage->startup();
     $this->assertEquals(session_id(), 'foobar');
 }
Пример #12
0
 public function setUp()
 {
     $_SERVER['SCRIPT_NAME'] = '';
     // takes care of php setting the commandline scriptname in $_SERVER, throwing the routing off guard
     $this->routing = new AgaviTestingWebRouting();
     $this->routing->initialize(AgaviContext::getInstance(null), $this->parameters);
     $this->routing->startup();
 }
Пример #13
0
 public function testGetHost()
 {
     $model = AgaviContext::getInstance()->getModel("ApiHostRequest", "Api");
     $host = $model->getHostsByName(array("c1-db1", "test"));
     $this->assertFalse(is_null($host), "Host request returned null");
     $this->assertEquals($host->count(), 1, "Number of hosts is wrong, should be 1, is " . $host->count());
     success("Getting host succeeded \n");
 }
Пример #14
0
 private static function getLogger()
 {
     if (self::$logger == null) {
         $ctx = AgaviContext::getInstance();
         self::$logger = $ctx->getLoggerManager();
     }
     return self::$logger;
 }
 /**
  * @group Validators
  */
 public function runValidator($f, $in)
 {
     $req = new AgaviRequestDataHolder();
     $req->setParameter("input", $in);
     $exec = AgaviContext::getInstance()->getController()->createExecutionContainer();
     $val = $exec->getValidationManager()->createValidator('TestValidator', array("input"), array("invalid_json" => "Invalid json provided", "invalid_format" => "Invalid format"), array("format" => $f, "name" => "test_filter", "base" => NULL, "export" => "test", "source" => "parameters"));
     $val->setValidationParameters($req);
     return $val->validate();
 }
 public function tearDown()
 {
     $_SERVER = $this->_SERVER;
     $_ENV = $this->_ENV;
     $_GET = $this->_GET;
     $ctx = AgaviContext::getInstance('routing-server-cases');
     $ctx->getRequest()->initialize($ctx);
     AgaviConfig::set('core.use_routing', false);
 }
Пример #17
0
 public function setUp()
 {
     // otherwise, the full URI wouldn't work
     $_SERVER['REQUEST_URI'] = '/index.php';
     $_SERVER['SCRIPT_NAME'] = '/index.php';
     $this->routing = new AgaviTestingWebRouting();
     $this->routing->initialize(AgaviContext::getInstance(null), $this->parameters);
     $this->routing->startup();
 }
Пример #18
0
 public function testDeleteCredentialPermission()
 {
     $model = new TestDataStoreModel();
     $e = null;
     $context = AgaviContext::getInstance();
     $context->getUser()->addCredential("testCredential");
     $model->doDelete("no data");
     $this->checkCalls($model, array(false, false, false, true), "delete");
 }
Пример #19
0
 public function main()
 {
     require_once dirname(__FILE__) . '/../../app/config.php';
     Agavi::bootstrap('development');
     AgaviController::initializeModule('AppKit');
     AgaviConfig::set('core.default_context', 'console');
     AgaviConfig::set('core.context_implementation', 'AppKitAgaviContext');
     AgaviContext::getInstance('console')->getController()->dispatch();
 }
Пример #20
0
 /**
  * dispatch the request
  *
  * @author     Felix Gilcher <*****@*****.**>
  * @since      1.0.0 
  */
 public function execute($arguments = null, $outputType = null, $requestMethod = null)
 {
     $context = AgaviContext::getInstance();
     $controller = $context->getController();
     $controller->setParameter('send_response', false);
     if (!$arguments instanceof AgaviRequestDataHolder) {
         $arguments = $this->createRequestDataHolder(array(AgaviRequestDataHolder::SOURCE_PARAMETERS => $arguments));
     }
     $this->response = $controller->dispatch(null, $controller->createExecutionContainer($this->moduleName, $this->actionName, $arguments, $outputType, $requestMethod));
 }
 public function execute(AgaviXmlConfigDomDocument $document)
 {
     $this->document = $document;
     $this->menuDefinition = new AppKitLinkedList();
     $this->context = AgaviContext::getInstance();
     $document->setDefaultNamespace(self::XML_NAMESPACE, 'm');
     $this->setupXPath();
     $this->fetchMenudefinition();
     return $this->generate('return ' . var_export($this->menuDefinition->toArray(), true));
 }
 public function icingaConstants($val, AgaviParameterHolder $method_params, AgaviParameterHolder $row)
 {
     $type = $method_params->getParameter('type');
     $ref = new ReflectionClass('IcingaConstantResolver');
     if ($m = $ref->getMethod($type)) {
         if ($m->isPublic() && $m->isStatic()) {
             return AgaviContext::getInstance()->getTranslationManager()->_($m->invoke(null, $val));
         }
     }
     return $val;
 }
Пример #23
0
 /**
  * @depends testLibs
  * @group Bootstrap
  **/
 public function testBootstrap()
 {
     $ctx = AgaviContext::getInstance('testing');
     IcingaWebTestTool::assertInstanceOf('AppKitAgaviContext', $ctx, "AgaviContext has wrong instance");
     IcingaWebTestTool::assertInstanceOf('AgaviDoctrineDatabase', $ctx->getDatabaseManager()->getDatabase());
     IcingaWebTestTool::assertInstanceOf('Doctrine_Manager', $ctx->getDatabaseManager()->getDatabase()->getDoctrineManager());
     try {
         $ctx->getDatabaseManager()->getDatabase()->connect();
     } catch (Doctrine_Connection_Exception $e) {
         $this->fail('No database connection');
     }
 }
Пример #24
0
 public function testTicket962()
 {
     $ctx = AgaviContext::getInstance();
     $tm = $ctx->getTranslationManager();
     $locale = $tm->getLocale('de@timezone=America/Los_Angeles');
     $inputFormat = new AgaviDateFormat('yyyy-MM-dd HH:mm:ssZZZ');
     $cal = $inputFormat->parse('2008-11-19 23:00:00America/Los_Angeles', $locale, false);
     $originalTimeZoneId = $cal->getTimeZone()->getId();
     $this->assertEquals('America/Los_Angeles', $cal->getTimeZone()->getId());
     $this->assertEquals('Donnerstag, 20. November 2008 2:00 Uhr GMT-05:00', $tm->_d($cal, null, 'de@timezone=America/New_York'));
     $this->assertEquals($originalTimeZoneId, $cal->getTimeZone()->getId());
 }
 public function __construct()
 {
     $this->context = AgaviContext::getInstance();
     $this->parser = new AppKitFormatParserUtil();
     $p =& $this->parser;
     $p->registerNamespace('xmlfn', AppKitFormatParserUtil::TYPE_METHOD);
     $ref = new ReflectionObject($this);
     // Register some methods
     $p->registerMethod('xmlfn', 'author', array(&$this, $ref->getMethod('valueAuthor')));
     $p->registerMethod('xmlfn', 'instance', array(&$this, $ref->getMethod('valueDefaultInstance')));
     $p->registerMethod('xmlfn', 'pagerMaxItems', array(&$this, $ref->getMethod('pagerMaxItems')));
     $p->registerMethod('xmlfn', 'autoRefreshTime', array(&$this, $ref->getMethod('autoRefreshTime')));
 }
Пример #26
0
 /**
  * @group Installation 
  */
 public function testAPIConnection()
 {
     $root = AgaviConfig::get("core.root_dir");
     info("\tTesting if API Connection is available\n");
     $ctx = AgaviContext::getInstance();
     try {
         $API = $ctx->getModel("Icinga.ApiContainer", "Web");
     } catch (IcingaApiException $e) {
         error("Could not connect to API. The API Connector returned the following message:\n" . $e->getMessage() . ")\n" . "Without the icinga-API you will not be able to request any information from icinga!\n");
         $this->fail("Icinga-API connection test failed. Please correct the api settings in " . $root . "/app/modules/AppKit/config/module.xml and retry");
     }
     success("\tAPI Connection available\n");
 }
 /**
  * Post-unserialization callback.
  *
  * Will restore the context based on the names set by __sleep.
  *
  * @author     David Zülke <*****@*****.**>
  * @since      0.11.0
  */
 public function __wakeup()
 {
     $this->context = AgaviContext::getInstance($this->contextName);
     unset($this->contextName);
     if (isset($this->outputTypeName)) {
         $this->outputType = $this->context->getController()->getOutputType($this->outputTypeName);
         unset($this->outputTypeName);
     }
     if (isset($this->contentStreamMeta)) {
         // contrary to what the documentation says, stream_get_meta_data() will not return a list of filters attached to the stream, so we cannot restore these, unfortunately.
         $this->content = fopen($this->contentStreamMeta['uri'], $this->contentStreamMeta['mode']);
         unset($this->contentStreamMeta);
     }
 }
 /**
  * Creates an instance
  * @param mixed $conn
  * @param mixed $class
  * @return IcingaDoctrine_Query
  */
 public static function create($conn = NULL, $class = NULL)
 {
     $manager = Doctrine_Manager::getInstance();
     if (!$conn instanceof Doctrine_Connection && $conn) {
         $conn = $manager->getConnection($conn);
     } else {
         $conn = $manager->getConnection(IcingaDoctrineDatabase::CONNECTION_ICINGA);
     }
     $conn_name = $manager->getConnectionName($conn);
     if ($conn_name !== IcingaDoctrineDatabase::CONNECTION_ICINGA) {
         AgaviContext::getInstance()->getLoggerManager()->log('QUERY::CREATE Obtain doctrine connection: ' . $conn_name, AgaviLogger::DEBUG);
     }
     return parent::create($conn, 'IcingaDoctrine_Query');
 }
 /**
  * parent::execute would overwrite the routing default namespace with the one agavi uses, so we
  * cannot simply call the parent one (self::XML_NAMESPACE wouldn't refer to http://icinga.org/...)
  * This is just a copy of @See AgaviRoutingConfigHandler::execute and additionally calls the Ext.direct
  * Provider
  *
  * @param    AgaviXmlConfigDomDocument   The DOMDocument to parse
  *
  * @author   Jannis Moßhammer   <*****@*****.**>
  *
  **/
 private function parent_execute(AgaviXmlConfigDomDocument $document)
 {
     $routing = AgaviContext::getInstance($this->context)->getRouting();
     $this->unnamedRoutes = array();
     $routing->importRoutes(array());
     $data = array();
     foreach ($document->getConfigurationElements() as $cfg) {
         if ($cfg->has('routes')) {
             $this->parseRoutesExtended($routing, $cfg->get('routes'));
             $this->parseApiProviders();
             $this->parseRoutes($routing, $cfg->get('routes'), $parent = null);
         }
     }
     return serialize($routing->exportRoutes());
 }
 /**
  * (non-PHPdoc)
  * @see lib/agavi/src/core/AgaviContext#initialize()
  */
 public function initialize()
 {
     // Fill in the context
     AppKitAgaviUtil::initContext($this);
     /*
      * Make our settings ready
      * before run agavi
      */
     self::buildVersionString();
     $this->initializePhpSettings();
     $this->initializeModules();
     parent::initialize();
     $this->initializeAutosettings();
     $this->initializeExceptionHandling();
 }