Merge branch 'master' into feature/generate-webserver-config-6120

Conflicts:
	application/clicommands/SetupCommand.php
This commit is contained in:
Eric Lippmann 2014-11-13 12:50:55 +01:00
commit 2ad2127ae3
171 changed files with 3029 additions and 1863 deletions

View File

@ -76,7 +76,7 @@ __function createService(service_type, num) {
enable_active_checks = (service_type != "pending")
vars.check_type = service_type
assign where match("*" + service_type + "*", host.vars.check_config)
assign where service_type in host.vars.check_config
}
}
@ -102,12 +102,12 @@ __function createHost(checkType, checkConfig, num, checkEnabled) {
}
__for (num in range(10)) {
createHost("ok", "ok", num, true)
createHost("random", "random,flapping", num, true)
createHost("down", "warning,critical", num, true)
createHost("unreachable", "unknown", num, true)
createHost("pending", "pending", num, false)
createHost("flap", "flapping", num, true)
createHost("ok", [ "ok" ], num, true)
createHost("random", [ "random", "flapping" ], num, true)
createHost("down", [ "warning", "critical" ], num, true)
createHost("unreachable", [ "unknown" ], num, true)
createHost("pending", [ "pending" ], num, false)
createHost("flap", [ "flapping" ], num, true)
}
// EOF

View File

@ -4,6 +4,7 @@
namespace Icinga\Clicommands;
use Icinga\Application\Icinga;
use Icinga\Cli\Command;
use Icinga\Exception\IcingaException;
@ -30,7 +31,7 @@ class WebCommand extends Command
// throw new IcingaException('Socket is required');
}
if ($basedir === null) {
$basedir = dirname(ICINGAWEB_APPDIR) . '/public';
$basedir = Icinga::app()->getBaseDir('public');
if (! file_exists($basedir) || ! is_dir($basedir)) {
throw new IcingaException('Basedir is required');
}

View File

@ -104,30 +104,30 @@ class AuthenticationController extends ActionController
}
}
if ($backendsTried === 0) {
throw new ConfigurationError(
$this->view->form->addError(
$this->translate(
'No authentication methods available. Did you create'
. ' authentication.ini when installing Icinga Web 2?'
. ' authentication.ini when setting up Icinga Web 2?'
)
);
}
if ($backendsTried === $backendsWithError) {
throw new ConfigurationError(
} else if ($backendsTried === $backendsWithError) {
$this->view->form->addError(
$this->translate(
'All configured authentication methods failed.'
. ' Please check the system log or Icinga Web 2 log for more information.'
)
);
}
if ($backendsWithError) {
$this->view->form->getElement('username')->addError(
} elseif ($backendsWithError) {
$this->view->form->addError(
$this->translate(
'Please note that not all authentication methods were available.'
. ' Check the system log or Icinga Web 2 log for more information.'
)
);
}
$this->view->form->getElement('password')->addError($this->translate('Incorrect username or password'));
if ($backendsTried > 0 && $backendsTried !== $backendsWithError) {
$this->view->form->getElement('password')->addError($this->translate('Incorrect username or password'));
}
} elseif ($request->isGet()) {
$user = new User('');
foreach ($chain as $backend) {
@ -146,7 +146,7 @@ class AuthenticationController extends ActionController
$this->view->errorInfo = $e->getMessage();
}
$this->view->configMissing = count($config->toArray()) === 0 && false === is_dir(Config::$configDir);
$this->view->configMissing = is_dir(Config::$configDir) === false;
}
/**

View File

@ -7,7 +7,7 @@ use Icinga\Web\Notification;
use Icinga\Application\Modules\Module;
use Icinga\Web\Widget;
use Icinga\Application\Icinga;
use Icinga\Application\Config as IcingaConfig;
use Icinga\Application\Config;
use Icinga\Form\Config\GeneralConfigForm;
use Icinga\Form\Config\AuthenticationBackendReorderForm;
use Icinga\Form\Config\AuthenticationBackendConfigForm;
@ -46,7 +46,7 @@ class ConfigController extends ActionController
public function indexAction()
{
$form = new GeneralConfigForm();
$form->setIniConfig(IcingaConfig::app());
$form->setIniConfig(Config::app());
$form->handleRequest();
$this->view->form = $form;
@ -131,7 +131,7 @@ class ConfigController extends ActionController
public function authenticationAction()
{
$form = new AuthenticationBackendReorderForm();
$form->setIniConfig(IcingaConfig::app('authentication'));
$form->setIniConfig(Config::app('authentication'));
$form->handleRequest();
$this->view->form = $form;
@ -145,7 +145,7 @@ class ConfigController extends ActionController
public function createauthenticationbackendAction()
{
$form = new AuthenticationBackendConfigForm();
$form->setIniConfig(IcingaConfig::app('authentication'));
$form->setIniConfig(Config::app('authentication'));
$form->setResourceConfig(ResourceFactory::getResourceConfigs());
$form->setRedirectUrl('config/authentication');
$form->handleRequest();
@ -161,7 +161,7 @@ class ConfigController extends ActionController
public function editauthenticationbackendAction()
{
$form = new AuthenticationBackendConfigForm();
$form->setIniConfig(IcingaConfig::app('authentication'));
$form->setIniConfig(Config::app('authentication'));
$form->setResourceConfig(ResourceFactory::getResourceConfigs());
$form->setRedirectUrl('config/authentication');
$form->handleRequest();
@ -179,7 +179,7 @@ class ConfigController extends ActionController
$form = new ConfirmRemovalForm(array(
'onSuccess' => function ($request) {
$configForm = new AuthenticationBackendConfigForm();
$configForm->setIniConfig(IcingaConfig::app('authentication'));
$configForm->setIniConfig(Config::app('authentication'));
$authBackend = $request->getQuery('auth_backend');
try {
@ -212,7 +212,7 @@ class ConfigController extends ActionController
*/
public function resourceAction()
{
$this->view->resources = IcingaConfig::app('resources', true)->toArray();
$this->view->resources = Config::app('resources', true)->toArray();
$this->view->tabs->activate('resources');
}
@ -222,7 +222,7 @@ class ConfigController extends ActionController
public function createresourceAction()
{
$form = new ResourceConfigForm();
$form->setIniConfig(IcingaConfig::app('resources'));
$form->setIniConfig(Config::app('resources'));
$form->setRedirectUrl('config/resource');
$form->handleRequest();
@ -236,7 +236,7 @@ class ConfigController extends ActionController
public function editresourceAction()
{
$form = new ResourceConfigForm();
$form->setIniConfig(IcingaConfig::app('resources'));
$form->setIniConfig(Config::app('resources'));
$form->setRedirectUrl('config/resource');
$form->handleRequest();
@ -252,7 +252,7 @@ class ConfigController extends ActionController
$form = new ConfirmRemovalForm(array(
'onSuccess' => function ($request) {
$configForm = new ResourceConfigForm();
$configForm->setIniConfig(IcingaConfig::app('resources'));
$configForm->setIniConfig(Config::app('resources'));
$resource = $request->getQuery('resource');
try {
@ -274,7 +274,7 @@ class ConfigController extends ActionController
// Check if selected resource is currently used for authentication
$resource = $this->getRequest()->getQuery('resource');
$authConfig = IcingaConfig::app('authentication')->toArray();
$authConfig = Config::app('authentication')->toArray();
foreach ($authConfig as $backendName => $config) {
if (array_key_exists('resource', $config) && $config['resource'] === $resource) {
$form->addError(sprintf(

View File

@ -93,7 +93,7 @@ class DashboardController extends ActionController
);
$configFile = Config::app('dashboard/dashboard')->getConfigFile();
if ($this->writeConfiguration(new Zend_Config($dashboard->toArray()), $configFile)) {
if ($this->writeConfiguration(new Config($dashboard->toArray()), $configFile)) {
$this->redirectNow(Url::fromPath('dashboard', array('pane' => $form->getValue('pane'))));
} else {
$this->render('showConfiguration');
@ -151,12 +151,12 @@ class DashboardController extends ActionController
/**
* Store the given configuration as INI file
*
* @param Zend_Config $config The configuration to store
* @param string $target The path where to store the configuration
* @param Config $config The configuration to store
* @param string $target The path where to store the configuration
*
* @return bool Whether the configuartion has been successfully stored
*/
protected function writeConfiguration(Zend_Config $config, $target)
protected function writeConfiguration(Config $config, $target)
{
$writer = new IniWriter(array('config' => $config, 'filename' => $target));

View File

@ -3,9 +3,9 @@
// {{{ICINGA_LICENSE_HEADER}}}
use Icinga\Module\Monitoring\Controller;
use Icinga\Web\Hook;
use Icinga\Web\Url;
use Icinga\Application\Logger;
use Icinga\Application\Config;
use Icinga\Protocol\File\FileReader;
use \Zend_Controller_Action_Exception as ActionError;
@ -48,7 +48,7 @@ class ListController extends Controller
. ' - (?<message>.*)$/'; // message
$loggerWriter = Logger::getInstance()->getWriter();
$resource = new FileReader(new Zend_Config(array(
$resource = new FileReader(new Config(array(
'filename' => $loggerWriter->getPath(),
'fields' => $pattern
)));

View File

@ -5,6 +5,7 @@
namespace Icinga\Form\Config\Authentication;
use Exception;
use Icinga\Application\Config;
use Icinga\Web\Form;
use Icinga\Web\Request;
use Icinga\Data\ResourceFactory;
@ -121,7 +122,7 @@ class DbBackendForm extends Form
/**
* Return the configuration for the chosen resource
*
* @return Zend_Config
* @return Config
*/
public function getResourceConfig()
{

View File

@ -5,6 +5,7 @@
namespace Icinga\Form\Config\Authentication;
use Exception;
use Icinga\Application\Config;
use Icinga\Web\Form;
use Icinga\Web\Request;
use Icinga\Data\ResourceFactory;
@ -156,7 +157,7 @@ class LdapBackendForm extends Form
/**
* Return the configuration for the chosen resource
*
* @return Zend_Config
* @return Config
*/
public function getResourceConfig()
{

View File

@ -333,7 +333,7 @@ class AuthenticationBackendConfigForm extends ConfigForm
/**
* Return the configuration for the chosen resource
*
* @return Zend_Config
* @return Config
*/
public function getResourceConfig()
{

View File

@ -5,11 +5,11 @@
namespace Icinga\Form\Config\General;
use DateTimeZone;
use Icinga\Web\Form;
use Icinga\Util\Translator;
use Icinga\Application\Icinga;
use Icinga\Data\ResourceFactory;
use Icinga\Web\Form\Element\Number;
use Icinga\File\Ini\IniWriter;
use Icinga\Util\Translator;
use Icinga\Web\Form;
/**
* Form class to modify the general application configuration
@ -67,32 +67,18 @@ class ApplicationConfigForm extends Form
)
);
$this->addElement(
new Number(
'global_filemode',
array(
'required' => true,
'label' => t('Default File Mode'),
'description' => t(
'This is the global default file mode for new configuration files created by Icinga Web 2.'
),
'value' => decoct(IniWriter::$fileMode)
)
)
);
$this->addElement(
'text',
'global_modulePath',
array(
'label' => t('Module Path'),
'required' => true,
'value' => implode(':', Icinga::app()->getModuleManager()->getModuleDirs()),
'description' => t(
'Contains the directories that will be searched for available modules, separated by '
. 'colons. Modules that don\'t exist in these directories can still be symlinked in '
. 'the module folder, but won\'t show up in the list of disabled modules.'
),
'value' => realpath(ICINGAWEB_APPDIR . '/../modules')
)
)
);

View File

@ -5,7 +5,7 @@
namespace Icinga\Form\Config\Resource;
use Exception;
use Zend_Config;
use Icinga\Application\Config;
use Icinga\Web\Form;
use Icinga\Web\Request;
use Icinga\Web\Form\Element\Number;
@ -132,7 +132,7 @@ class DbResourceForm extends Form
public static function isValidResource(Form $form)
{
try {
$resource = ResourceFactory::createResource(new Zend_Config($form->getValues()));
$resource = ResourceFactory::createResource(new Config($form->getValues()));
$resource->getConnection()->getConnection();
} catch (Exception $e) {
$form->addError(t('Connectivity validation failed, connection to the given resource not possible.'));

View File

@ -5,7 +5,7 @@
namespace Icinga\Form\Config\Resource;
use Exception;
use Zend_Config;
use Icinga\Application\Config;
use Icinga\Web\Form;
use Icinga\Web\Request;
use Icinga\Web\Form\Element\Number;
@ -113,7 +113,7 @@ class LdapResourceForm extends Form
public static function isValidResource(Form $form)
{
try {
$resource = ResourceFactory::createResource(new Zend_Config($form->getValues()));
$resource = ResourceFactory::createResource(new Config($form->getValues()));
if (false === $resource->testCredentials(
$form->getElement('bind_dn')->getValue(),
$form->getElement('bind_pw')->getValue()

View File

@ -5,7 +5,7 @@
namespace Icinga\Form\Config\Resource;
use Exception;
use Zend_Config;
use Icinga\Application\Config;
use Icinga\Web\Form;
use Icinga\Web\Request;
use Icinga\Application\Icinga;
@ -74,7 +74,7 @@ class LivestatusResourceForm extends Form
public static function isValidResource(Form $form)
{
try {
$resource = ResourceFactory::createResource(new Zend_Config($form->getValues()));
$resource = ResourceFactory::createResource(new Config($form->getValues()));
$resource->connect()->disconnect();
} catch (Exception $e) {
$form->addError(t('Connectivity validation failed, connection to the given resource not possible.'));

View File

@ -216,7 +216,7 @@ class ResourceConfigForm extends ConfigForm
if ($resourceType === 'ldap' || Platform::extensionLoaded('ldap')) {
$resourceTypes['ldap'] = 'LDAP';
}
if ($resourceType === 'db' || Platform::extensionLoaded('pdo')) {
if ($resourceType === 'db' || Platform::extensionLoaded('mysql') || Platform::extensionLoaded('pgsql')) {
$resourceTypes['db'] = t('SQL Database');
}

View File

@ -4,7 +4,7 @@
namespace Icinga\Form\Dashboard;
use Icinga\Application\Config as IcingaConfig;
use Icinga\Application\Config;
use Icinga\Web\Widget\Dashboard;
use Icinga\Web\Form;
@ -110,7 +110,7 @@ class AddUrlForm extends Form
protected function getDashboardPaneSelectionValues()
{
$dashboard = new Dashboard();
$dashboard->readConfig(IcingaConfig::app('dashboard/dashboard'));
$dashboard->readConfig(Config::app('dashboard/dashboard'));
return $dashboard->getPaneKeyTitleArray();
}
}

View File

@ -20,10 +20,10 @@
t(
'You seem not to have Icinga Web 2 configured yet so it\'s not possible to log in without any defined '
. 'authentication method. Please define a authentication method by following the instructions in the'
. ' %1$sdocumentation%3$s or by using our %2$sweb-based installer%3$s.'
. ' %1$sdocumentation%3$s or by using our %2$sweb-based setup-wizard%3$s.'
),
'<a href="' . 'documention-link-here' . '" title="Icinga Web 2 Documentation">', // TODO: Documentation link
'<a href="' . $this->href('setup') . '" title="Icinga Web 2 Installer">',
'<a href="http://docs.icinga.org/" title="Icinga Web 2 Documentation">', // TODO: Documentation link
'<a href="' . $this->href('setup') . '" title="Icinga Web 2 Setup-Wizard">',
'</a>'
); ?></div>
<?php endif ?>

View File

@ -1,83 +0,0 @@
<?php
use Icinga\Application\Icinga;
use Icinga\Application\Config;
use Icinga\Application\Platform;
use Icinga\Web\Wizard;
$setupTokenPath = rtrim(Icinga::app()->getConfigDir(), '/') . '/setup.token';
?>
<div class="welcome-page">
<h2><?= t('Welcome to the installation of Icinga Web 2!') ?></h2>
<!-- TODO: Remove this once we release the first public version -->
<div style="border:1px solid #777;border-radius:1em;background-color:beige;padding:1em;margin-bottom:1em;display:inline-block;">
Icinga Web 2 is still in development and not meant for production deployment.
Watch the <a href="https://dev.icinga.org/projects/icingaweb2/roadmap">development roadmap</a> and
<a href="https://www.icinga.org/">Icinga website</a> for release schedule updates!
</div>
<div class="info">
<p><?= sprintf(
t(
'Icinga Web 2 is the next generation monitoring web interface,'
. ' framework and CLI tool developed by the %s.'
),
'<a href="https://www.icinga.org/community/team/">' . t('Icinga Project') . '</a>'
); ?></p>
<p><?= t(
'Responsive and fast, rewritten from scratch supporting multiple backends and'
. ' providing a CLI tool. Compatible with Icinga Core 2.x and 1.x.'
); ?></p>
<p><?= sprintf(
t('Check the Icinga website for some %s.', 'setup.welcome.screenshots'),
'<a href="https://www.icinga.org/icinga/screenshots/icinga-web-2/">'
. t('insights', 'setup.welcome.screenshots.label') . '</a>'
); ?></p>
</div>
<?php if (false === file_exists($setupTokenPath) && file_exists(Config::resolvePath('config.ini'))): ?>
<p class="restart-warning"><?= t(
'You\'ve already completed the installation of Icinga Web 2. Note that most of your configuration'
. ' files will be overwritten in case you\'ll re-configure Icinga Web 2 using this wizard!'
); ?></p>
<?php else: ?>
<p><?= t(
'This wizard will guide you through the installation of Icinga Web 2. Once completed and successfully'
. ' finished you are able to log in and to explore all the new and stunning features!'
); ?></p>
<?php endif ?>
<form id="<?= $form->getName(); ?>" name="<?= $form->getName(); ?>" enctype="<?= $form->getEncType(); ?>" method="<?= $form->getMethod(); ?>" action="<?= $form->getAction(); ?>">
<?= $form->getElement('token'); ?>
<?= $form->getElement($form->getTokenElementName()); ?>
<?= $form->getElement($form->getUidElementName()); ?>
<div class="buttons">
<?= $form->getElement(Wizard::BTN_NEXT); ?>
</div>
</form>
<div class="note">
<div class="title">
<img src="<?= $this->href('img/icons/comment.png'); ?>" alt="<?= t('Note'); ?>">
<strong>Generating a New Setup Token</strong>
</div>
<div>
<p><?=
t('To run this wizard a user needs to authenticate using a token which is usually'
. ' provided to him by an administrator who\'d followed the instructions below.'
); ?></p>
<p><?= t('If you\'ve got the IcingaCLI installed you can do the following:'); ?></p>
<div class="code">
<span>sudo icingacli setup createConfigDirectory <?= Platform::getPhpUser(); ?>;</span>
<span>sudo icingacli setup generateToken;</span>
</div>
<p><?= t('In case the IcingaCLI is missing you can create the token manually:'); ?></p>
<div class="code">
<span>sudo mkdir -m 2775 <?= dirname($setupTokenPath); ?> && sudo chgrp <?= Platform::getPhpUser(); ?> <?= dirname($setupTokenPath); ?>;</span>
<span>head -c 12 /dev/urandom | base64 | sudo -u '<?= Platform::getPhpUser(); ?>' tee <?= $setupTokenPath; ?>;</span>
<span>sudo chmod 0660 <?= $setupTokenPath; ?>;</span>
</div>
<p style="font-size: 85%;"><?= sprintf(
t('Please see the %s for an extensive description on how to access and use this wizard.'),
'<a href="http://docs.icinga.org/">' . t('Icinga Web 2 documentation') . '</a>' // TODO: Add link to iw2 docs which points to the installation topic
); ?></p>
</div>
</div>
</div>

View File

@ -0,0 +1,99 @@
<?php
use Icinga\Web\Url;
if ($xAxisPaginator->count() <= 1 && $yAxisPaginator->count() <= 1) {
return; // Display this pagination only if there are multiple pages
}
$fromTo = t('%s: %d to %d of %d');
$xAxisPages = $xAxisPaginator->getPages('all');
$yAxisPages = $yAxisPaginator->getPages('all');
$totalYAxisPages = $yAxisPaginator->count();
$currentYAxisPage = $yAxisPaginator->getCurrentPageNumber();
$prevYAxisPage = $currentYAxisPage > 1 ? $currentYAxisPage - 1 : null;
$nextYAxisPage = $currentYAxisPage < $totalYAxisPages ? $currentYAxisPage + 1 : null;
$totalXAxisPages = $xAxisPaginator->count();
$currentXAxisPage = $xAxisPaginator->getCurrentPageNumber();
$prevXAxisPage = $currentXAxisPage > 1 ? $currentXAxisPage - 1 : null;
$nextXAxisPage = $currentXAxisPage < $totalXAxisPages ? $currentXAxisPage + 1 : null;
?>
<table class="joystick-pagination">
<tbody>
<tr>
<td>&nbsp;</td>
<td>
<?php if ($prevYAxisPage): ?>
<a target="_self" href="<?= Url::fromRequest()->overwriteParams(array(
'page' => $currentXAxisPage . ',' . $prevYAxisPage
))->getAbsoluteUrl(); ?>" title="<?= sprintf(
$fromTo,
t('Hosts'),
($prevYAxisPage - 1) * $yAxisPages->itemCountPerPage + 1,
$prevYAxisPage * $yAxisPages->itemCountPerPage,
$yAxisPages->totalItemCount
); ?>"><?= $this->icon('up_petrol.png'); ?></a>
<?php else: ?>
<?= $this->icon('up.png'); ?>
<?php endif ?>
</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>
<?php if ($prevXAxisPage): ?>
<a target="_self" href="<?= Url::fromRequest()->overwriteParams(array(
'page' => $prevXAxisPage . ',' . $currentYAxisPage
))->getAbsoluteUrl(); ?>" title="<?= sprintf(
$fromTo,
t('Services'),
($prevXAxisPage - 1) * $xAxisPages->itemCountPerPage + 1,
$prevXAxisPage * $xAxisPages->itemCountPerPage,
$xAxisPages->totalItemCount
); ?>"><?= $this->icon('prev_petrol.png'); ?></a>
<?php else: ?>
<?= $this->icon('prev.png'); ?>
<?php endif ?>
</td>
<td>&nbsp;</td>
<td>
<?php if ($nextXAxisPage): ?>
<a target="_self" href="<?= Url::fromRequest()->overwriteParams(array(
'page' => $nextXAxisPage . ',' . $currentYAxisPage
))->getAbsoluteUrl(); ?>" title="<?= sprintf(
$fromTo,
t('Services'),
$currentXAxisPage * $xAxisPages->itemCountPerPage + 1,
$nextXAxisPage * $xAxisPages->itemCountPerPage,
$xAxisPages->totalItemCount
); ?>"><?= $this->icon('next_petrol.png'); ?></a>
<?php else: ?>
<?= $this->icon('next.png'); ?>
<?php endif ?>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<?php if ($nextYAxisPage): ?>
<a target="_self" href="<?= Url::fromRequest()->overwriteParams(array(
'page' => $currentXAxisPage . ',' . $nextYAxisPage
))->getAbsoluteUrl(); ?>" title="<?= sprintf(
$fromTo,
t('Hosts'),
$currentYAxisPage * $yAxisPages->itemCountPerPage + 1,
$nextYAxisPage * $yAxisPages->itemCountPerPage,
$yAxisPages->totalItemCount
); ?>"><?= $this->icon('down_petrol.png'); ?></a>
<?php else: ?>
<?= $this->icon('down.png'); ?>
<?php endif ?>
</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>

View File

@ -1,6 +1,9 @@
#!/usr/bin/php
<?php
use Icinga\Application\Cli;
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
require_once dirname(__DIR__) . '/library/Icinga/Application/Cli.php';
Cli::start()->dispatch();
Icinga\Application\Cli::start()->dispatch();

View File

@ -6,7 +6,6 @@ namespace Icinga\Application;
use ErrorException;
use Exception;
use Zend_Config;
use Icinga\Application\Modules\Manager as ModuleManager;
use Icinga\Data\ResourceFactory;
use Icinga\Exception\ConfigurationError;
@ -41,6 +40,43 @@ use Icinga\Exception\IcingaException;
*/
abstract class ApplicationBootstrap
{
/**
* Base directory
*
* Parent folder for at least application, bin, modules, library/vendor and public
*
* @var string
*/
protected $baseDir;
/**
* Application directory
*
* @var string
*/
protected $appDir;
/**
* Vendor library directory
*
* @var string
*/
protected $vendorDir;
/**
* Library directory
*
* @var string
*/
protected $libDir;
/**
* Configuration directory
*
* @var string
*/
protected $configDir;
/**
* Icinga auto loader
*
@ -48,34 +84,13 @@ abstract class ApplicationBootstrap
*/
private $loader;
/**
* Library directory
*
* @var string
*/
private $libDir;
/**
* Config object
*
* @var Zend_Config
* @var Config
*/
protected $config;
/**
* Configuration directory
*
* @var string
*/
private $configDir;
/**
* Application directory
*
* @var string
*/
private $appDir;
/**
* Module manager
*
@ -99,27 +114,20 @@ abstract class ApplicationBootstrap
/**
* Constructor
*
* @param string $baseDir Icinga Web 2 base directory
* @param string $configDir Path to Icinga Web 2's configuration files
*/
protected function __construct($configDir = null)
protected function __construct($baseDir = null, $configDir = null)
{
if ($baseDir === null) {
$baseDir = dirname($this->getBootstrapDirectory());
}
$this->baseDir = $baseDir;
$this->appDir = $baseDir . '/application';
$this->vendorDir = $baseDir . '/library/vendor';
$this->libDir = realpath(__DIR__ . '/../..');
if (!defined('ICINGA_LIBDIR')) {
define('ICINGA_LIBDIR', $this->libDir);
}
if (defined('ICINGAWEB_APPDIR')) {
$this->appDir = ICINGAWEB_APPDIR;
} elseif (array_key_exists('ICINGAWEB_APPDIR', $_SERVER)) {
$this->appDir = $_SERVER['ICINGAWEB_APPDIR'];
} else {
$this->appDir = realpath($this->libDir. '/../application');
}
if (!defined('ICINGAWEB_APPDIR')) {
define('ICINGAWEB_APPDIR', $this->appDir);
}
if ($configDir === null) {
if (array_key_exists('ICINGAWEB_CONFIGDIR', $_SERVER)) {
$configDir = $_SERVER['ICINGAWEB_CONFIGDIR'];
@ -197,44 +205,6 @@ abstract class ApplicationBootstrap
return $this->isWeb;
}
/**
* Getter for application dir
*
* Optional append sub directory
*
* @param string $subdir optional subdir
*
* @return string
*/
public function getApplicationDir($subdir = null)
{
return $this->getDirWithSubDir($this->appDir, $subdir);
}
/**
* Getter for config dir
*
* @param string $subdir
*
* @return string
*/
public function getConfigDir($subdir = null)
{
return $this->getDirWithSubDir($this->configDir, $subdir);
}
/**
* Get the path to the bootstrapping directory.
*
* This is usually /public for Web and EmbeddedWeb
*
* @return string
*/
public function getBootstrapDirecory()
{
return dirname($_SERVER['SCRIPT_FILENAME']);
}
/**
* Helper to glue directories together
*
@ -253,15 +223,76 @@ abstract class ApplicationBootstrap
}
/**
* Starting concrete bootstrap classes
* Get the base directory
*
* @param string $configDir
* @param string $subDir Optional sub directory to get
*
* @return ApplicationBootstrap
* @return string
*/
public static function start($configDir = null)
public function getBaseDir($subDir = null)
{
$application = new static($configDir);
return $this->getDirWithSubDir($this->baseDir, $subDir);
}
/**
* Get the application directory
*
* @param string $subDir Optional sub directory to get
*
* @return string
*/
public function getApplicationDir($subDir = null)
{
return $this->getDirWithSubDir($this->appDir, $subDir);
}
/**
* Get the vendor library directory
*
* @param string $subDir Optional sub directory to get
*
* @return string
*/
public function getVendorDir($subDir = null)
{
return $this->getDirWithSubDir($this->vendorDir, $subDir);
}
/**
* Get the configuration directory
*
* @param string $subDir Optional sub directory to get
*
* @return string
*/
public function getConfigDir($subDir = null)
{
return $this->getDirWithSubDir($this->configDir, $subDir);
}
/**
* Get the path to the bootstrapping directory
*
* This is usually /public for Web and EmbeddedWeb and /bin for the CLI
*
* @return string
*/
public function getBootstrapDirectory()
{
return dirname(realpath($_SERVER['SCRIPT_FILENAME']));
}
/**
* Start the bootstrap
*
* @param string $baseDir Icinga Web 2 base directory
* @param string $configDir Path to Icinga Web 2's configuration files
*
* @return static
*/
public static function start($baseDir = null, $configDir = null)
{
$application = new static($baseDir, $configDir);
$application->bootstrap();
return $application;
}
@ -314,16 +345,26 @@ abstract class ApplicationBootstrap
$this->moduleManager = new ModuleManager(
$this,
$this->configDir . '/enabledModules',
explode(
':',
$this->config->global !== null
? $this->config->global->get('modulePath', ICINGAWEB_APPDIR . '/../modules')
: ICINGAWEB_APPDIR . '/../modules'
)
explode(':', $this->config->fromSection('global', 'modulePath', $this->baseDir . '/modules'))
);
return $this;
}
/**
* Load all core modules
*
* @return self
*/
protected function loadCoreModules()
{
try {
$this->moduleManager->loadCoreModules();
} catch (NotReadableError $e) {
Logger::error(new IcingaException('Cannot load core modules. An exception was thrown:', $e));
}
return $this;
}
/**
* Load all enabled modules
*
@ -347,7 +388,7 @@ abstract class ApplicationBootstrap
protected function setupLogging()
{
Logger::create(
new Zend_Config(
new Config(
array(
'log' => 'syslog'
)
@ -369,13 +410,7 @@ abstract class ApplicationBootstrap
$this->config = Config::app();
} catch (NotReadableError $e) {
Logger::error(new IcingaException('Cannot load application configuration. An exception was thrown:', $e));
$this->config = new Zend_Config(array());
}
if ($this->config->global !== null) {
IniWriter::$fileMode = octdec($this->config->global->get('filemode', '0664'));
} else {
IniWriter::$fileMode = 0664;
$this->config = new Config();
}
return $this;
@ -413,9 +448,9 @@ abstract class ApplicationBootstrap
*/
protected function setupLogger()
{
if ($this->config->logging !== null) {
if (($loggingConfig = $this->config->logging) !== null) {
try {
Logger::create($this->config->logging);
Logger::create($loggingConfig);
} catch (ConfigurationError $e) {
Logger::error($e);
}
@ -454,7 +489,7 @@ abstract class ApplicationBootstrap
if (! $default) {
$default = 'UTC';
}
$timeZoneString = $this->config->global !== null ? $this->config->global->get('timezone', $default) : $default;
$timeZoneString = $this->config->fromSection('global', 'timezone', $default);
date_default_timezone_set($timeZoneString);
DateTimeFactory::setConfig(array('timezone' => $timeZoneString));
return $this;

View File

@ -4,6 +4,7 @@
namespace Icinga\Application;
use Icinga\Application\Config;
use Icinga\Application\Platform;
use Icinga\Application\ApplicationBootstrap;
use Icinga\Cli\Params;
@ -12,7 +13,6 @@ use Icinga\Cli\Screen;
use Icinga\Application\Logger;
use Icinga\Application\Benchmark;
use Icinga\Exception\ProgrammingError;
use Zend_Config;
require_once __DIR__ . '/ApplicationBootstrap.php';
@ -43,17 +43,17 @@ class Cli extends ApplicationBootstrap
->parseBasicParams()
->setupLogger()
->setupResourceFactory()
->setupModuleManager();
->setupModuleManager()
->loadCoreModules();
}
protected function setupLogging()
{
Logger::create(
new Zend_Config(
new Config(
array(
'level' => Logger::INFO,
'log' => 'file',
'file' => 'php://stderr'
'log' => 'stdout',
)
)
);

View File

@ -4,14 +4,17 @@
namespace Icinga\Application;
use Zend_Config;
use Zend_Config_Ini;
use Iterator;
use Countable;
use ArrayAccess;
use LogicException;
use UnexpectedValueException;
use Icinga\Exception\NotReadableError;
/**
* Global registry of application and module configuration.
* Container for configuration values and global registry of application and module related configuration.
*/
class Config extends Zend_Config
class Config implements Countable, Iterator, ArrayAccess
{
/**
* Configuration directory where ALL (application and module) configuration is located
@ -20,13 +23,6 @@ class Config extends Zend_Config
*/
public static $configDir;
/**
* The INI file this configuration has been loaded from or should be written to
*
* @var string
*/
protected $configFile;
/**
* Application config instances per file
*
@ -42,95 +38,34 @@ class Config extends Zend_Config
protected static $modules = array();
/**
* Load configuration from the given INI file
* This config's data
*
* @param string $file The file to parse
*
* @throws NotReadableError When the file does not exist or cannot be read
* @var array
*/
public static function fromIni($file)
{
$config = new static(array(), true);
$filepath = realpath($file);
if ($filepath === false) {
$config->setConfigFile($file);
} elseif (is_readable($filepath)) {
$config->setConfigFile($filepath);
$config->merge(new Zend_Config_Ini($filepath));
} else {
throw new NotReadableError('Cannot read config file "%s". Permission denied', $filepath);
}
return $config;
}
protected $data;
/**
* Retrieve a application config instance
* The INI file this configuration has been loaded from or should be written to
*
* @param string $configname The configuration name (without ini suffix) to read and return
* @param bool $fromDisk When set true, the configuration will be read from the disk, even
* if it already has been read
*
* @return Config The configuration object that has been requested
* @var string
*/
public static function app($configname = 'config', $fromDisk = false)
{
if (!isset(self::$app[$configname]) || $fromDisk) {
self::$app[$configname] = Config::fromIni(self::resolvePath($configname . '.ini'));
}
return self::$app[$configname];
}
protected $configFile;
/**
* Set module config
* Create a new config
*
* @param string $moduleName
* @param string $configName
* @param Zend_Config $config
* @param array $data The data to initialize the new config with
*/
public static function setModuleConfig($moduleName, $configName, Zend_Config $config)
public function __construct(array $data = array())
{
self::$modules[$moduleName][$configName] = $config;
}
$this->data = array();
/**
* Retrieve a module config instance
*
* @param string $modulename The name of the module to look for configurations
* @param string $configname The configuration name (without ini suffix) to read and return
* @param string $fromDisk Whether to read the configuration from disk
*
* @return Config The configuration object that has been requested
*/
public static function module($modulename, $configname = 'config', $fromDisk = false)
{
if (!isset(self::$modules[$modulename])) {
self::$modules[$modulename] = array();
}
$moduleConfigs = self::$modules[$modulename];
if (!isset($moduleConfigs[$configname]) || $fromDisk) {
$moduleConfigs[$configname] = Config::fromIni(
self::resolvePath('modules/' . $modulename . '/' . $configname . '.ini')
);
}
return $moduleConfigs[$configname];
}
/**
* Retrieve names of accessible sections or properties
*
* @param $name
* @return array
*/
public function keys($name = null)
{
if ($name === null) {
return array_keys($this->toArray());
} elseif ($this->$name === null) {
return array();
} else {
return array_keys($this->$name->toArray());
foreach ($data as $key => $value) {
if (is_array($value)) {
$this->data[$key] = new static($value);
} else {
$this->data[$key] = $value;
}
}
}
@ -158,13 +93,375 @@ class Config extends Zend_Config
}
/**
* Prepend configuration base dir if input is relative
* Deep clone this config
*/
public function __clone()
{
$array = array();
foreach ($this->data as $key => $value) {
if ($value instanceof self) {
$array[$key] = clone $value;
} else {
$array[$key] = $value;
}
}
$this->data = $array;
}
/**
* Return the count of available sections and properties
*
* @param string $path Input path
* @return string Absolute path
* @return int
*/
public function count()
{
return count($this->data);
}
/**
* Reset the current position of $this->data
*
* @return mixed
*/
public function rewind()
{
return reset($this->data);
}
/**
* Return the section's or property's value of the current iteration
*
* @return mixed
*/
public function current()
{
return current($this->data);
}
/**
* Return whether the position of the current iteration is valid
*
* @return bool
*/
public function valid()
{
return key($this->data) !== null;
}
/**
* Return the section's or property's name of the current iteration
*
* @return mixed
*/
public function key()
{
return key($this->data);
}
/**
* Advance the position of the current iteration and return the new section's or property's value
*
* @return mixed
*/
public function next()
{
return next($this->data);
}
/**
* Return whether the given section or property is set
*
* @param string $key The name of the section or property
*
* @return bool
*/
public function __isset($key)
{
return isset($this->data[$key]);
}
/**
* Return the value for the given property or the config for the given section
*
* @param string $key The name of the property or section
*
* @return mixed|NULL The value or NULL in case $key does not exist
*/
public function __get($key)
{
if (array_key_exists($key, $this->data)) {
return $this->data[$key];
}
}
/**
* Add a new property or section
*
* @param string $key The name of the new property or section
* @param mixed $value The value to set for the new property or section
*/
public function __set($key, $value)
{
if (is_array($value)) {
$this->data[$key] = new static($value);
} else {
$this->data[$key] = $value;
}
}
/**
* Remove the given property or section
*
* @param string $key The property or section to remove
*/
public function __unset($key)
{
unset($this->data[$key]);
}
/**
* Return whether the given section or property is set
*
* @param string $key The name of the section or property
*
* @return bool
*/
public function offsetExists($key)
{
return isset($this->$key);
}
/**
* Return the value for the given property or the config for the given section
*
* @param string $key The name of the property or section
*
* @return mixed|NULL The value or NULL in case $key does not exist
*/
public function offsetGet($key)
{
return $this->$key;
}
/**
* Add a new property or section
*
* @param string $key The name of the new property or section
* @param mixed $value The value to set for the new property or section
*/
public function offsetSet($key, $value)
{
if ($key === null) {
throw new LogicException('Appending values without an explicit key is not supported');
}
$this->$key = $value;
}
/**
* Remove the given property or section
*
* @param string $key The property or section to remove
*/
public function offsetUnset($key)
{
unset($this->$key);
}
/**
* Return whether this config has any data
*
* @return bool
*/
public function isEmpty()
{
return $this->count() === 0;
}
/**
* Return the value for the given property or the config for the given section
*
* @param string $key The name of the property or section
* @param mixed $default The value to return in case the property or section is missing
*
* @return mixed
*/
public function get($key, $default = null)
{
$value = $this->$key;
if ($default !== null && $value === null) {
$value = $default;
}
return $value;
}
/**
* Return all section and property names
*
* @return array
*/
public function keys()
{
return array_keys($this->data);
}
/**
* Return this config's data as associative array
*
* @return array
*/
public function toArray()
{
$array = array();
foreach ($this->data as $key => $value) {
if ($value instanceof self) {
$array[$key] = $value->toArray();
} else {
$array[$key] = $value;
}
}
return $array;
}
/**
* Merge the given data with this config
*
* @param array|Config $data An array or a config
*
* @return self
*/
public function merge($data)
{
if ($data instanceof self) {
$data = $data->toArray();
}
foreach ($data as $key => $value) {
if (array_key_exists($key, $this->data)) {
if (is_array($value)) {
if ($this->data[$key] instanceof self) {
$this->data[$key]->merge($value);
} else {
$this->data[$key] = new static($value);
}
} else {
$this->data[$key] = $value;
}
} else {
$this->data[$key] = is_array($value) ? new static($value) : $value;
}
}
}
/**
* Return the value from a section's property
*
* @param string $section The section where the given property can be found
* @param string $key The section's property to fetch the value from
* @param mixed $default The value to return in case the section or the property is missing
*
* @return mixed
*
* @throws UnexpectedValueException In case the given section does not hold any configuration
*/
public function fromSection($section, $key, $default = null)
{
$value = $this->$section;
if ($value instanceof self) {
$value = $value->$key;
} elseif ($value !== null) {
throw new UnexpectedValueException(
sprintf('Value "%s" is not of type "Config" or a sub-type of it', $value)
);
}
if ($value === null && $default !== null) {
$value = $default;
}
return $value;
}
/**
* Load configuration from the given INI file
*
* @param string $file The file to parse
*
* @throws NotReadableError When the file does not exist or cannot be read
*/
public static function fromIni($file)
{
$config = new static();
$filepath = realpath($file);
if ($filepath === false) {
$config->setConfigFile($file);
} elseif (is_readable($filepath)) {
$config->setConfigFile($filepath);
$config->merge(parse_ini_file($filepath, true));
} else {
throw new NotReadableError(t('Cannot read config file "%s". Permission denied'), $filepath);
}
return $config;
}
/**
* Prepend configuration base dir to the given relative path
*
* @param string $path A relative path
*
* @return string
*/
public static function resolvePath($path)
{
return self::$configDir . DIRECTORY_SEPARATOR . ltrim($path, DIRECTORY_SEPARATOR);
}
/**
* Retrieve a application config
*
* @param string $configname The configuration name (without ini suffix) to read and return
* @param bool $fromDisk When set true, the configuration will be read from disk, even
* if it already has been read
*
* @return Config The requested configuration
*/
public static function app($configname = 'config', $fromDisk = false)
{
if (!isset(self::$app[$configname]) || $fromDisk) {
self::$app[$configname] = static::fromIni(static::resolvePath($configname . '.ini'));
}
return self::$app[$configname];
}
/**
* Retrieve a module config
*
* @param string $modulename The name of the module where to look for the requested configuration
* @param string $configname The configuration name (without ini suffix) to read and return
* @param string $fromDisk When set true, the configuration will be read from disk, even
* if it already has been read
*
* @return Config The requested configuration
*/
public static function module($modulename, $configname = 'config', $fromDisk = false)
{
if (!isset(self::$modules[$modulename])) {
self::$modules[$modulename] = array();
}
$moduleConfigs = self::$modules[$modulename];
if (!isset($moduleConfigs[$configname]) || $fromDisk) {
$moduleConfigs[$configname] = static::fromIni(
static::resolvePath('modules/' . $modulename . '/' . $configname . '.ini')
);
}
return $moduleConfigs[$configname];
}
}

View File

@ -31,6 +31,7 @@ class EmbeddedWeb extends ApplicationBootstrap
->setupErrorHandling()
->setupTimezone()
->setupModuleManager()
->loadCoreModules()
->loadEnabledModules();
}
}

View File

@ -5,7 +5,7 @@
namespace Icinga\Application;
use Exception;
use Zend_Config;
use Icinga\Application\Config;
use Icinga\Application\Logger\Writer\FileWriter;
use Icinga\Application\Logger\Writer\SyslogWriter;
use Icinga\Exception\ConfigurationError;
@ -71,12 +71,12 @@ class Logger
/**
* Create a new logger object
*
* @param Zend_Config $config
* @param Config $config
*
* @throws ConfigurationError If the logging configuration directive 'log' is missing or if the logging level is
* not defined
*/
public function __construct(Zend_Config $config)
public function __construct(Config $config)
{
if ($config->log === null) {
throw new ConfigurationError('Required logging configuration directive \'log\' missing');
@ -118,11 +118,11 @@ class Logger
/**
* Create a new logger object
*
* @param Zend_Config $config
* @param Config $config
*
* @return static
*/
public static function create(Zend_Config $config)
public static function create(Config $config)
{
static::$instance = new static($config);
return static::$instance;
@ -131,12 +131,12 @@ class Logger
/**
* Create a log writer
*
* @param Zend_Config $config The configuration to initialize the writer with
* @param Config $config The configuration to initialize the writer with
*
* @return \Icinga\Application\Logger\LogWriter The requested log writer
* @throws ConfigurationError If the requested writer cannot be found
*/
protected function createWriter(Zend_Config $config)
protected function createWriter(Config $config)
{
$class = 'Icinga\\Application\\Logger\\Writer\\' . ucfirst(strtolower($config->log)) . 'Writer';
if (! class_exists($class)) {

View File

@ -4,17 +4,25 @@
namespace Icinga\Application\Logger;
use Zend_Config;
use Icinga\Application\Config;
/**
* Abstract class for writers that write messages to a log
*/
abstract class LogWriter
{
/**
* @var Zend_Config
*/
protected $config;
/**
* Create a new log writer initialized with the given configuration
*/
abstract public function __construct(Zend_Config $config);
public function __construct(Config $config)
{
$this->config = $config;
}
/**
* Log a message with the given severity

View File

@ -5,7 +5,7 @@
namespace Icinga\Application\Logger\Writer;
use Exception;
use Zend_Config;
use Icinga\Application\Config;
use Icinga\Application\Logger;
use Icinga\Application\Logger\LogWriter;
use Icinga\Exception\ConfigurationError;
@ -26,12 +26,12 @@ class FileWriter extends LogWriter
/**
* Create a new file log writer
*
* @param Zend_Config $config
* @param Config $config
*
* @throws ConfigurationError If the configuration directive 'file' is missing or if the path to 'file' does
* not exist or if writing to 'file' is not possible
*/
public function __construct(Zend_Config $config)
public function __construct(Config $config)
{
if ($config->file === null) {
throw new ConfigurationError('Required logging configuration directive \'file\' missing');

View File

@ -0,0 +1,50 @@
<?php
namespace Icinga\Application\Logger\Writer;
use Icinga\Cli\Screen;
use Icinga\Application\Logger\Logger;
use Icinga\Application\Logger\LogWriter;
use Zend_Config;
/**
* Class to write log messages to STDOUT
*/
class StdoutWriter extends LogWriter
{
protected $screen;
protected function screen()
{
if ($this->screen === null) {
$this->screen = Screen::instance();
}
return $this->screen;
}
/**
* Log a message with the given severity
*
* @param int $severity The severity to use
* @param string $message The message to log
*/
public function log($severity, $message)
{
$color = 'black';
switch ($severity) {
case Logger::$ERROR:
$color = 'red';
break;
case Logger::$WARNING:
$color = 'orange';
break;
case Logger::$INFO:
$color = 'green';
break;
case Logger::$DEBUG:
$color = 'blue';
break;
}
file_put_contents('php://stderr', $this->screen()->colorize($message, $color) . "\n");
}
}

View File

@ -4,7 +4,7 @@
namespace Icinga\Application\Logger\Writer;
use Zend_Config;
use Icinga\Application\Config;
use Icinga\Application\Logger;
use Icinga\Application\Logger\LogWriter;
@ -51,9 +51,9 @@ class SyslogWriter extends LogWriter
/**
* Create a new syslog log writer
*
* @param Zend_Config $config
* @param Config $config
*/
public function __construct(Zend_Config $config)
public function __construct(Config $config)
{
$this->ident = $config->get('application', 'icingaweb');
$this->facility = static::$facilities['user'];

View File

@ -67,6 +67,18 @@ class Manager
*/
private $modulePaths = array();
/**
* The core modules
*
* Core modules do not need to be enabled to load and cannot be disabled
* by the user. This must not be writable programmatically!
*
* @var array
*/
private $coreModules = array(
'setup'
);
/**
* Create a new instance of the module manager
*
@ -157,7 +169,21 @@ class Manager
}
/**
* Try to set all enabled modules in loaded sate
* Try to set all core modules in loaded state
*
* @return self
* @see Manager::loadModule()
*/
public function loadCoreModules()
{
foreach ($this->coreModules as $name) {
$this->loadModule($name);
}
return $this;
}
/**
* Try to set all enabled modules in loaded state
*
* @return self
* @see Manager::loadModule()
@ -211,6 +237,8 @@ class Manager
'Cannot enable module "%s". Module is not installed.',
$name
);
} elseif (in_array($name, $this->coreModules)) {
return $this;
}
clearstatcache(true);
@ -427,7 +455,7 @@ class Manager
}
$installed = $this->listInstalledModules();
foreach ($installed as $name) {
foreach (array_diff($installed, $this->coreModules) as $name) {
$info[$name] = (object) array(
'name' => $name,
'path' => $this->installedBaseDirs[$name],
@ -531,4 +559,14 @@ class Manager
ksort($this->installedBaseDirs);
return $this;
}
/**
* Get the directories where to look for installed modules
*
* @return array
*/
public function getModuleDirs()
{
return $this->modulePaths;
}
}

View File

@ -5,7 +5,6 @@
namespace Icinga\Application\Modules;
use Exception;
use Zend_Config;
use Zend_Controller_Router_Route_Abstract;
use Zend_Controller_Router_Route as Route;
use Zend_Controller_Router_Route_Regex as RegexRoute;
@ -18,7 +17,7 @@ use Icinga\Web\Hook;
use Icinga\Web\Menu;
use Icinga\Web\Widget;
use Icinga\Web\Widget\Dashboard\Pane;
use Icinga\Web\Setup\SetupWizard;
use Icinga\Module\Setup\SetupWizard;
use Icinga\Util\File;
use Icinga\Exception\ProgrammingError;
use Icinga\Exception\IcingaException;
@ -243,7 +242,7 @@ class Module
if (array_key_exists($name, $this->menuItems)) {
$this->menuItems[$name]->setProperties($properties);
} else {
$this->menuItems[$name] = new Menu($name, new Zend_Config($properties));
$this->menuItems[$name] = new Menu($name, new Config($properties));
}
return $this->menuItems[$name];

View File

@ -156,8 +156,6 @@ class Platform
$userInfo = posix_getpwuid(posix_geteuid());
return $userInfo['name'];
}
return 'php_username';
}
/**

View File

@ -92,6 +92,7 @@ class Web extends ApplicationBootstrap
->setupZendMvc()
->setupFormNamespace()
->setupModuleManager()
->loadCoreModules()
->loadEnabledModules()
->setupRoute()
->setupPagination();

View File

@ -5,7 +5,7 @@
namespace Icinga\Authentication;
use Iterator;
use Zend_Config;
use Icinga\Application\Config;
use Icinga\Application\Logger;
use Icinga\Exception\ConfigurationError;
@ -17,7 +17,7 @@ class AuthChain implements Iterator
/**
* User backends configuration
*
* @var Zend_Config
* @var Config
*/
private $config;
@ -31,9 +31,9 @@ class AuthChain implements Iterator
/**
* Create a new authentication chain from config
*
* @param Zend_Config $config User backends configuration
* @param Config $config User backends configuration
*/
public function __construct(Zend_Config $config)
public function __construct(Config $config)
{
$this->config = $config;
}

View File

@ -4,7 +4,7 @@
namespace Icinga\Authentication\Backend;
use Zend_Config;
use Icinga\Application\Config;
use Icinga\Authentication\UserBackend;
use Icinga\User;
@ -23,9 +23,9 @@ class AutoLoginBackend extends UserBackend
/**
* Create new autologin backend
*
* @param Zend_Config $config
* @param Config $config
*/
public function __construct(Zend_Config $config)
public function __construct(Config $config)
{
$this->stripUsernameRegexp = $config->get('strip_username_regexp');
}

View File

@ -82,10 +82,7 @@ class LdapUserBackend extends UserBackend
$q = $this->conn->select()->setBase($this->baseDn)->from($this->userClass);
$result = $q->fetchRow();
} catch (LdapException $e) {
throw new AuthenticationException(
'Connection not possible: %s',
$e->getMessage()
);
throw new AuthenticationException('Connection not possible.', $e);
}
if (! isset($result)) {
@ -176,7 +173,7 @@ class LdapUserBackend extends UserBackend
} catch (AuthenticationException $e) {
// Authentication not possible
throw new AuthenticationException(
'Authentication against backend "%s" not possible: %s',
'Authentication against backend "%s" not possible.',
$this->getName(),
$e
);

View File

@ -5,7 +5,6 @@
namespace Icinga\Authentication;
use Exception;
use Zend_Config;
use Icinga\Application\Config;
use Icinga\Exception\IcingaException;
use Icinga\Exception\NotReadableError;
@ -62,7 +61,7 @@ class Manager
$e
)
);
$config = new Zend_Config(array());
$config = new Config();
}
if (($preferencesConfig = $config->preferences) !== null) {
try {

View File

@ -6,7 +6,7 @@ namespace Icinga\Authentication;
use Countable;
use Icinga\Authentication\Backend\AutoLoginBackend;
use Zend_Config;
use Icinga\Application\Config;
use Icinga\Authentication\Backend\DbUserBackend;
use Icinga\Authentication\Backend\LdapUserBackend;
use Icinga\Data\ResourceFactory;
@ -45,7 +45,7 @@ abstract class UserBackend implements Countable
return $this->name;
}
public static function create($name, Zend_Config $backendConfig)
public static function create($name, Config $backendConfig)
{
if ($backendConfig->name !== null) {
$name = $backendConfig->name;

View File

@ -4,7 +4,7 @@
namespace Icinga\Authentication;
use Zend_Config;
use Icinga\Application\Config;
use Icinga\Authentication\Backend\DbUserGroupBackend;
use Icinga\Authentication\Backend\IniUserGroupBackend;
use Icinga\Data\ResourceFactory;
@ -50,13 +50,13 @@ abstract class UserGroupBackend
/**
* Create a user group backend
*
* @param string $name
* @param Zend_Config $backendConfig
* @param string $name
* @param Config $backendConfig
*
* @return DbUserGroupBackend|IniUserGroupBackend
* @throws ConfigurationError If the backend configuration is invalid
*/
public static function create($name, Zend_Config $backendConfig)
public static function create($name, Config $backendConfig)
{
if ($backendConfig->name !== null) {
$name = $backendConfig->name;

View File

@ -66,7 +66,7 @@ class Loader
public function __construct(App $app)
{
$this->app = $app;
$this->coreAppDir = ICINGAWEB_APPDIR . '/clicommands';
$this->coreAppDir = $app->getBaseDir('clicommands');
}
/**

View File

@ -4,14 +4,14 @@
namespace Icinga\Data\Db;
use PDO;
use Zend_Db;
use Icinga\Application\Config;
use Icinga\Application\Benchmark;
use Icinga\Data\Db\DbQuery;
use Icinga\Data\ResourceFactory;
use Icinga\Data\Selectable;
use Icinga\Exception\ConfigurationError;
use PDO;
use Zend_Config;
use Zend_Db;
/**
* Encapsulate database connections and query creation
@ -21,7 +21,7 @@ class DbConnection implements Selectable
/**
* Connection config
*
* @var Zend_Config
* @var Config
*/
private $config;
@ -59,9 +59,9 @@ class DbConnection implements Selectable
/**
* Create a new connection object
*
* @param Zend_Config $config
* @param Config $config
*/
public function __construct(Zend_Config $config = null)
public function __construct(Config $config = null)
{
$this->config = $config;
if (isset($config->prefix)) {
@ -216,7 +216,10 @@ class DbConnection implements Selectable
*/
public function fetchRow(DbQuery $query)
{
return $this->dbAdapter->fetchRow($query->getSelectQuery());
Benchmark::measure('DB is fetching row');
$result = $this->dbAdapter->fetchRow($query->getSelectQuery());
Benchmark::measure('DB row done');
return $result;
}
/**

View File

@ -79,7 +79,7 @@ abstract class Filter
}
}
krsort($operators, SORT_NATURAL);
krsort($operators, version_compare(PHP_VERSION, '5.4.0') >= 0 ? SORT_NATURAL : SORT_REGULAR);
foreach ($operators as $id => $operator) {
$f = $filter->getById($id);
if ($f->getOperatorName() !== $operator) {

View File

@ -4,7 +4,6 @@
namespace Icinga\Data;
use Zend_Config;
use Icinga\Application\Config;
use Icinga\Exception\ProgrammingError;
use Icinga\Util\ConfigAwareFactory;
@ -22,14 +21,14 @@ class ResourceFactory implements ConfigAwareFactory
/**
* Resource configuration
*
* @var Zend_Config
* @var Config
*/
private static $resources;
/**
* Set resource configurations
*
* @param Zend_Config $config
* @param Config $config
*/
public static function setConfig($config)
{
@ -41,7 +40,7 @@ class ResourceFactory implements ConfigAwareFactory
*
* @param $resourceName String The resource's name
*
* @return Zend_Config The configuration of the resource
* @return Config The configuration of the resource
*
* @throws ConfigurationError
*/
@ -62,7 +61,7 @@ class ResourceFactory implements ConfigAwareFactory
*
* @param String|null $type Fetch only resources that have the given type.
*
* @return Zend_Config The configuration containing all resources
* @return Config The configuration containing all resources
*/
public static function getResourceConfigs($type = null)
{
@ -76,7 +75,7 @@ class ResourceFactory implements ConfigAwareFactory
$resources[$name] = $resource;
}
}
return new Zend_Config($resources);
return new Config($resources);
}
}
@ -100,13 +99,13 @@ class ResourceFactory implements ConfigAwareFactory
* NOTE: The factory does not test if the given configuration is valid and the resource is accessible, this
* depends entirely on the implementation of the returned resource.
*
* @param Zend_Config $config The configuration for the created resource.
* @param Config $config The configuration for the created resource.
*
* @return DbConnection|LdapConnection|LivestatusConnection An object that can be used to access
* the given resource. The returned class depends on the configuration property 'type'.
* @throws ConfigurationError When an unsupported type is given
*/
public static function createResource(Zend_Config $config)
public static function createResource(Config $config)
{
switch (strtolower($config->type)) {
case 'db':

View File

@ -1,14 +0,0 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Exception;
/**
* Class InstallException
*
* Used to indicate that a installation should be aborted.
*/
class InstallException extends IcingaException
{
}

View File

@ -433,6 +433,9 @@ class IniEditor
*/
private function formatKey(array $key)
{
foreach ($key as $i => $separator) {
$key[$i] = $this->sanitize($separator);
}
return implode($this->nestSeparator, $key);
}
@ -599,7 +602,7 @@ class IniEditor
}
/**
* Prepare a value for INe
* Prepare a value for INI
*
* @param $value The value of the string
*
@ -613,10 +616,12 @@ class IniEditor
return $value;
} elseif (is_bool($value)) {
return ($value ? 'true' : 'false');
} elseif (strpos($value, '"') === false) {
return '"' . $value . '"';
} else {
return '"' . str_replace('"', '\"', $value) . '"';
}
return '"' . str_replace('"', '\"', $this->sanitize($value)) . '"';
}
private function sanitize($value)
{
return str_replace('\n', '', $value);
}
}

View File

@ -8,6 +8,7 @@ use Zend_Config;
use Zend_Config_Ini;
use Zend_Config_Exception;
use Zend_Config_Writer_FileAbstract;
use Icinga\Application\Config;
/**
* A INI file adapter that respects the file structure and the comments of already existing ini files
@ -26,7 +27,7 @@ class IniWriter extends Zend_Config_Writer_FileAbstract
*
* @var int
*/
public static $fileMode;
public static $fileMode = 0664;
/**
* Create a new INI writer
@ -41,49 +42,16 @@ class IniWriter extends Zend_Config_Writer_FileAbstract
*/
public function __construct(array $options = null)
{
if (isset($options['config']) && $options['config'] instanceof Config) {
// As this class inherits from Zend_Config_Writer_FileAbstract we must
// not pass the config directly as it needs to be of type Zend_Config
$options['config'] = new Zend_Config($options['config']->toArray(), true);
}
$this->options = $options;
parent::__construct($options);
}
/**
* Find all keys containing dots and convert it to a nested configuration
*
* Ensure that configurations with the same ini representation the have
* similarly nested Zend_Config objects. The configuration may be altered
* during that process.
*
* @param Zend_Config $config The configuration to normalize
* @return Zend_Config The normalized config
*/
private function normalizeKeys(Zend_Config $config)
{
foreach ($config as $key => $value) {
if (preg_match('/\./', $key) > 0) {
// remove old key
unset ($config->$key);
// insert new key
$nests = explode('.', $key);
$current = $config;
$i = 0;
for (; $i < count($nests) - 1; $i++) {
if (! isset($current->{$nests[$i]})) {
// configuration key doesn't exist, create a new nesting level
$current->{$nests[$i]} = new Zend_Config (array(), true);
}
// move to next nesting level
$current = $current->{$nests[$i]};
}
// reached last nesting level, insert value
$current->{$nests[$i]} = $value;
}
if ($value instanceof Zend_Config) {
$config->$key = $this->normalizeKeys ($value);
}
}
return $config;
}
/**
* Render the Zend_Config into a config file string
*
@ -97,16 +65,6 @@ class IniWriter extends Zend_Config_Writer_FileAbstract
$oldconfig = new Zend_Config(array());
}
// create an internal copy of the given configuration, since the user of this class
// won't expect that a configuration will ever be altered during
// the rendering process.
$extends = $this->_config->getExtends();
$this->_config = new Zend_Config ($this->_config->toArray(), true);
foreach ($extends as $extending => $extended) {
$this->_config->setExtend($extending, $extended);
}
$this->_config = $this->normalizeKeys($this->_config);
$newconfig = $this->_config;
$editor = new IniEditor(@file_get_contents($this->_filename), $this->options);
$this->diffConfigs($oldconfig, $newconfig, $editor);

View File

@ -49,7 +49,7 @@ class Pdf extends DOMPDF
$layout->content = $controller->getResponse();
$html = $layout->render();
$imgDir = Url::fromPath('img');
$html = preg_replace('~src="' . $imgDir . '/~', 'src="' . Icinga::app()->getBootstrapDirecory() . '/img/', $html);
$html = preg_replace('~src="' . $imgDir . '/~', 'src="' . Icinga::app()->getBootstrapDirectory() . '/img/', $html);
$html = preg_replace('~src="/svg/chart.php(.*)"~', 'class="icon" src="http://master1.com/png/chart.php$1"', $html);
$this->load_html($html);
$this->render();

View File

@ -4,9 +4,9 @@
namespace Icinga\Protocol\File;
use Icinga\Data\Selectable;
use Countable;
use Zend_Config;
use Icinga\Application\Config;
use Icinga\Data\Selectable;
/**
* Read file line by line
@ -30,11 +30,11 @@ class FileReader implements Selectable, Countable
/**
* Create a new reader
*
* @param Zend_Config $config
* @param Config $config
*
* @throws FileReaderException If a required $config directive (filename or fields) is missing
*/
public function __construct(Zend_Config $config)
public function __construct(Config $config)
{
foreach (array('filename', 'fields') as $key) {
if (isset($config->{$key})) {

View File

@ -8,7 +8,6 @@ use Icinga\Protocol\Ldap\Exception as LdapException;
use Icinga\Application\Platform;
use Icinga\Application\Config;
use Icinga\Application\Logger;
use Zend_Config;
/**
* Backend class managing all the LDAP stuff for you.
@ -101,9 +100,9 @@ class Connection
*
* TODO: Allow to pass port and SSL options
*
* @param Zend_Config $config
* @param Config $config
*/
public function __construct(Zend_Config $config)
public function __construct(Config $config)
{
$this->hostname = $config->hostname;
$this->bind_dn = $config->bind_dn;
@ -336,9 +335,9 @@ class Connection
public function testCredentials($username, $password)
{
$ds = $this->prepareNewConnection();
$this->connect();
$r = @ldap_bind($ds, $username, $password);
$r = @ldap_bind($this->ds, $username, $password);
if ($r) {
Logger::debug(
'Successfully tested LDAP credentials (%s / %s)',
@ -351,7 +350,7 @@ class Connection
'Testing LDAP credentials (%s / %s) failed: %s',
$username,
'***',
ldap_error($ds)
ldap_error($this->ds)
);
return false;
}
@ -364,7 +363,7 @@ class Connection
*/
protected function getConfigDir($sub = null)
{
$dir = Config::getInstance()->getConfigDir() . '/ldap';
$dir = Config::$configDir . '/ldap';
if ($sub !== null) {
$dir .= '/' . $sub;
}
@ -388,7 +387,19 @@ class Connection
}
$ds = ldap_connect($this->hostname, $this->port);
list($cap, $namingContexts) = $this->discoverCapabilities($ds);
try {
$capabilities = $this->discoverCapabilities($ds);
list($cap, $namingContexts) = $capabilities;
} catch (LdapException $e) {
// discovery failed, guess defaults
$cap = (object) array(
'supports_ldapv3' => true,
'supports_starttls' => false,
'msCapabilities' => array()
);
$namingContexts = null;
}
$this->capabilities = $cap;
$this->namingContexts = $namingContexts;
@ -626,7 +637,8 @@ class Connection
if (! $result) {
throw new LdapException(
sprintf(
'Capability query failed (%s:%d): %s',
'Capability query failed (%s:%d): %s. Check if hostname and port of the ldap resource are correct '
. ' and if anonymous access is permitted.',
$this->hostname,
$this->port,
ldap_error($ds)
@ -634,6 +646,16 @@ class Connection
);
}
$entry = ldap_first_entry($ds, $result);
if ($entry === false) {
throw new LdapException(
sprintf(
'Capabilities not available (%s:%d): %s. Discovery of root DSE probably not permitted.',
$this->hostname,
$this->port,
ldap_error($ds)
)
);
}
$cap = (object) array(
'supports_ldapv3' => false,
@ -641,10 +663,6 @@ class Connection
'msCapabilities' => array()
);
if ($entry === false) {
// TODO: Is it OK to have no capabilities?
return false;
}
$ldapAttributes = ldap_get_attributes($ds, $entry);
$result = $this->cleanupAttributes($ldapAttributes);
$cap->supports_ldapv3 = $this->hasCapabilityLdapV3($result);

View File

@ -24,9 +24,9 @@ namespace Icinga\Test {
use Exception;
use RuntimeException;
use Mockery;
use Zend_Config;
use PHPUnit_Framework_TestCase;
use Icinga\Application\Icinga;
use Icinga\Application\Config;
use Icinga\Util\DateTimeFactory;
use Icinga\Data\ResourceFactory;
use Icinga\Data\Db\DbConnection;
@ -191,17 +191,17 @@ namespace Icinga\Test {
}
/**
* Create Zend_Config for database configuration
* Create Config for database configuration
*
* @param string $name
*
* @return Zend_Config
* @return Config
* @throws RuntimeException
*/
protected function createDbConfigFor($name)
{
if (array_key_exists($name, self::$dbConfiguration)) {
return new Zend_Config(self::$dbConfiguration[$name]);
return new Config(self::$dbConfiguration[$name]);
}
throw new RuntimeException('Configuration for database type not available: ' . $name);

View File

@ -4,13 +4,12 @@
namespace Icinga\User\Preferences;
use Zend_Config;
use Icinga\Application\Config;
use Icinga\User;
use Icinga\User\Preferences;
use Icinga\Data\ResourceFactory;
use Icinga\Exception\ConfigurationError;
use Icinga\Data\Db\DbConnection;
use Icinga\Application\Config as IcingaConfig;
/**
* Preferences store factory
@ -19,13 +18,13 @@ use Icinga\Application\Config as IcingaConfig;
* <code>
* <?php
*
* use Zend_Config;
* use Icinga\Application\Config;
* use Icinga\User\Preferences;
* use Icinga\User\Preferences\PreferencesStore;
*
* // Create a INI store
* $store = PreferencesStore::create(
* new Zend_Config(
* new Config(
* 'type' => 'ini',
* 'config_path' => '/path/to/preferences'
* ),
@ -42,7 +41,7 @@ abstract class PreferencesStore
/**
* Store config
*
* @var Zend_Config
* @var Config
*/
protected $config;
@ -56,10 +55,10 @@ abstract class PreferencesStore
/**
* Create a new store
*
* @param Zend_Config $config The config for this adapter
* @param User $user The user to which these preferences belong
* @param Config $config The config for this adapter
* @param User $user The user to which these preferences belong
*/
public function __construct(Zend_Config $config, User $user)
public function __construct(Config $config, User $user)
{
$this->config = $config;
$this->user = $user;
@ -69,7 +68,7 @@ abstract class PreferencesStore
/**
* Getter for the store config
*
* @return Zend_Config
* @return Config
*/
public function getStoreConfig()
{
@ -108,14 +107,14 @@ abstract class PreferencesStore
/**
* Create preferences storage adapter from config
*
* @param Zend_Config $config The config for the adapter
* @param User $user The user to which these preferences belong
* @param Config $config The config for the adapter
* @param User $user The user to which these preferences belong
*
* @return self
*
* @throws ConfigurationError When the configuration defines an invalid storage type
*/
public static function create(Zend_Config $config, User $user)
public static function create(Config $config, User $user)
{
if (($type = $config->type) === null) {
throw new ConfigurationError(
@ -133,7 +132,7 @@ abstract class PreferencesStore
}
if ($type === 'Ini') {
$config->location = IcingaConfig::resolvePath('preferences');
$config->location = Config::resolvePath('preferences');
} elseif ($type === 'Db') {
$config->connection = new DbConnection(ResourceFactory::getResourceConfig($config->resource));
}

View File

@ -4,7 +4,7 @@
namespace Icinga\User\Preferences\Store;
use Zend_Config;
use Icinga\Application\Config;
use Icinga\Exception\NotReadableError;
use Icinga\Exception\NotWritableError;
use Icinga\File\Ini\IniWriter;
@ -116,7 +116,7 @@ class IniStore extends PreferencesStore
$this->writer = new IniWriter(
array(
'config' => new Zend_Config($this->preferences),
'config' => new Config($this->preferences),
'filename' => $this->preferencesFile
)
);

View File

@ -224,6 +224,7 @@ class Translator
}
}
}
sort($codes);
return $codes;
}

View File

@ -463,7 +463,15 @@ class Form extends Zend_Form
$el = parent::createElement($type, $name, $options);
if ($el && $el->getAttrib('autosubmit')) {
$el->addDecorator(new NoScriptApply()); // Non-JS environments
$noScript = new NoScriptApply(); // Non-JS environments
$decorators = $el->getDecorators();
$pos = array_search('Zend_Form_Decorator_ViewHelper', array_keys($decorators)) + 1;
$el->setDecorators(
array_slice($decorators, 0, $pos, true)
+ array(get_class($noScript) => $noScript)
+ array_slice($decorators, $pos, count($decorators) - $pos, true)
);
$class = $el->getAttrib('class');
if (is_array($class)) {
$class[] = 'autosubmit';
@ -473,6 +481,7 @@ class Form extends Zend_Form
$class .= ' autosubmit';
}
$el->setAttrib('class', $class); // JS environments
unset($el->autosubmit);
}

View File

@ -5,7 +5,6 @@
namespace Icinga\Web\Form\Validator;
use Zend_Validate_Abstract;
use Icinga\Application\Config as IcingaConfig;
/**
* Validator that interprets the value as a path and checks if it's writable

View File

@ -67,7 +67,7 @@ class JavaScript
public static function send($minified = false)
{
header('Content-Type: application/javascript');
$basedir = Icinga::app()->getBootstrapDirecory();
$basedir = Icinga::app()->getBootstrapDirectory();
$js = $out = '';
$min = $minified ? '.min' : '';

View File

@ -6,7 +6,6 @@ namespace Icinga\Web;
use Icinga\Web\Menu\MenuItemRenderer;
use RecursiveIterator;
use Zend_Config;
use Icinga\Application\Config;
use Icinga\Application\Icinga;
use Icinga\Application\Logger;
@ -79,10 +78,10 @@ class Menu implements RecursiveIterator
/**
* Create a new menu
*
* @param int $id The id of this menu
* @param Zend_Config $config The configuration for this menu
* @param int $id The id of this menu
* @param Config $config The configuration for this menu
*/
public function __construct($id, Zend_Config $config = null, Menu $parent = null)
public function __construct($id, Config $config = null, Menu $parent = null)
{
$this->id = $id;
if ($parent !== null) {
@ -94,7 +93,7 @@ class Menu implements RecursiveIterator
/**
* Set all given properties
*
* @param array|Zend_Config $props Property list
* @param array|Config $props Property list
*/
public function setProperties($props = null)
{
@ -415,11 +414,11 @@ class Menu implements RecursiveIterator
* Add a sub menu to this menu
*
* @param string $id The id of the menu to add
* @param Zend_Config $itemConfig The config with which to initialize the menu
* @param Config $itemConfig The config with which to initialize the menu
*
* @return self
*/
public function addSubMenu($id, Zend_Config $menuConfig = null)
public function addSubMenu($id, Config $menuConfig = null)
{
if (false === ($pos = strpos($id, '.'))) {
$subMenu = new self($id, $menuConfig, $this);
@ -509,7 +508,7 @@ class Menu implements RecursiveIterator
*/
public function add($name, $config = array())
{
return $this->addSubMenu($name, new Zend_Config($config));
return $this->addSubMenu($name, new Config($config));
}
/**

View File

@ -0,0 +1,90 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Web\Menu;
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
use Icinga\Web\Menu;
use Icinga\Web\Url;
class MonitoringMenuItemRenderer implements MenuItemRenderer {
protected static $summary;
protected $columns = array();
protected static function summary($column = null)
{
if (self::$summary === null) {
self::$summary = MonitoringBackend::instance()->select()->from(
'statusSummary',
array(
'hosts_down_unhandled',
'services_critical_unhandled'
)
)->getQuery()->fetchRow();
}
if ($column === null) {
return self::$summary;
} elseif (isset(self::$summary->$column)) {
return self::$summary->$column;
} else {
return null;
}
}
protected function getBadgeTitle()
{
$translations = array(
'hosts_down_unhandled' => mt('monitoring', '%d unhandled hosts down'),
'services_critical_unhandled' => mt('monitoring', '%d unhandled services critical')
);
$titles = array();
$sum = $this->summary();
foreach ($this->columns as $col) {
if (isset($sum->$col) && $sum->$col > 0) {
$titles[] = sprintf($translations[$col], $sum->$col);
}
}
return implode(', ', $titles);
}
protected function countItems()
{
$sum = self::summary();
$count = 0;
foreach ($this->columns as $col) {
if (isset($sum->$col)) {
$count += $sum->$col;
}
}
return $count;
}
public function render(Menu $menu)
{
$count = $this->countItems();
$badge = '';
if ($count) {
$badge = sprintf(
'<div title="%s" class="badge-container"><span class="badge badge-critical">%s</span></div>',
$this->getBadgeTitle(),
$count
);
}
return sprintf(
'<a href="%s">%s%s%s</a>',
$menu->getUrl() ?: '#',
$menu->getIcon() ? '<img src="' . Url::fromPath($menu->getIcon()) . '" class="icon" /> ' : '',
htmlspecialchars($menu->getTitle()),
$badge
);
}
}

View File

@ -1,39 +1,11 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Web\Menu;
use Icinga\Module\Monitoring\Backend;
use Icinga\Web\Menu;
use Icinga\Web\Url;
class ProblemMenuItemRenderer implements MenuItemRenderer {
public function render(Menu $menu)
{
$statusSummary = Backend::createBackend()
->select()->from(
'statusSummary',
array(
'hosts_down_unhandled',
'services_critical_unhandled'
)
)->getQuery()->fetchRow();
$unhandled = $statusSummary->hosts_down_unhandled + $statusSummary->services_critical_unhandled;
$badge = '';
if ($unhandled) {
$badge = sprintf(
'<div class="badge-container"><span class="badge badge-critical">%s</span></div>',
$unhandled
);
}
return sprintf(
'<a href="%s">%s%s %s</a>',
$menu->getUrl() ?: '#',
$menu->getIcon() ? '<img src="' . Url::fromPath($menu->getIcon()) . '" class="icon" /> ' : '',
htmlspecialchars($menu->getTitle()),
$badge
);
}
class ProblemMenuItemRenderer extends MonitoringMenuItemRenderer
{
protected $columns = array(
'hosts_down_unhandled',
'services_critical_unhandled'
);
}

View File

@ -1,38 +1,12 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Web\Menu;
use Icinga\Module\Monitoring\Backend;
use Icinga\Web\Menu;
use Icinga\Web\Url;
class UnhandledHostMenuItemRenderer implements MenuItemRenderer {
public function render(Menu $menu)
{
$statusSummary = Backend::createBackend()
->select()->from(
'statusSummary',
array(
'hosts_down_unhandled'
)
)->getQuery()->fetchRow();
$badge = '';
if ($statusSummary->hosts_down_unhandled) {
$badge = sprintf(
'<div title="%s" class="badge-container"><span class="badge badge-critical">%s</span></div>',
t(sprintf('%d unhandled host problems', $statusSummary->hosts_down_unhandled)),
$statusSummary->hosts_down_unhandled
);
}
return sprintf(
'<a href="%s">%s%s %s</a>',
$menu->getUrl() ?: '#',
$menu->getIcon() ? '<img src="' . Url::fromPath($menu->getIcon()) . '" class="icon" /> ' : '',
htmlspecialchars($menu->getTitle()),
$badge
);
}
class UnhandledHostMenuItemRenderer extends MonitoringMenuItemRenderer
{
protected $columns = array(
'hosts_down_unhandled',
);
}

View File

@ -1,38 +1,12 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Web\Menu;
use Icinga\Module\Monitoring\Backend;
use Icinga\Web\Menu;
use Icinga\Web\Url;
class UnhandledServiceMenuItemRenderer implements MenuItemRenderer {
public function render(Menu $menu)
{
$statusSummary = Backend::createBackend()
->select()->from(
'statusSummary',
array(
'services_critical_unhandled'
)
)->getQuery()->fetchRow();
$badge = '';
if ($statusSummary->services_critical_unhandled) {
$badge = sprintf(
'<div title="%s" class="badge-container"><span class="badge badge-critical">%s</span></div>',
t(sprintf('%d unhandled service problems', $statusSummary->services_critical_unhandled)),
$statusSummary->services_critical_unhandled
);
}
return sprintf(
'<a href="%s">%s%s %s</a>',
$menu->getUrl() ?: '#',
$menu->getIcon() ? '<img src="' . Url::fromPath($menu->getIcon()) . '" class="icon" /> ' : '',
htmlspecialchars($menu->getTitle()),
$badge
);
}
class UnhandledServiceMenuItemRenderer extends MonitoringMenuItemRenderer
{
protected $columns = array(
'services_critical_unhandled'
);
}

View File

@ -31,7 +31,7 @@ class StyleSheet
public static function compileForPdf()
{
$less = new LessCompiler();
$basedir = Icinga::app()->getBootstrapDirecory();
$basedir = Icinga::app()->getBootstrapDirectory();
foreach (self::$lessFiles as $file) {
$less->addFile($basedir . '/' . $file);
}
@ -57,7 +57,7 @@ class StyleSheet
public static function send($minified = false)
{
$app = Icinga::app();
$basedir = $app->getBootstrapDirecory();
$basedir = $app->getBootstrapDirectory();
foreach (self::$lessFiles as $file) {
$lessFiles[] = $basedir . '/' . $file;
}

View File

@ -5,7 +5,7 @@
namespace Icinga\Web\Widget;
use Icinga\Application\Icinga;
use Icinga\Application\Config as IcingaConfig;
use Icinga\Application\Config;
use Icinga\Exception\ConfigurationError;
use Icinga\Exception\ProgrammingError;
use Icinga\Web\Widget\Dashboard\Pane;
@ -26,7 +26,7 @@ class Dashboard extends AbstractWidget
/**
* The configuration containing information about this dashboard
*
* @var IcingaConfig;
* @var Config;
*/
private $config;
@ -140,11 +140,11 @@ class Dashboard extends AbstractWidget
/**
* Populate this dashboard via the given configuration file
*
* @param IcingaConfig $config The configuration file to populate this dashboard with
* @param Config $config The configuration file to populate this dashboard with
*
* @return self
*/
public function readConfig(IcingaConfig $config)
public function readConfig(Config $config)
{
$this->config = $config;
$this->panes = array();

View File

@ -4,16 +4,12 @@
namespace Icinga\Web\Widget\Dashboard;
use Icinga\Exception\IcingaException;
use Icinga\Util\Dimension;
use Zend_Form_Element_Button;
use Icinga\Application\Config;
use Icinga\Web\Form;
use Icinga\Web\Url;
use Icinga\Web\Widget\AbstractWidget;
use Icinga\Web\View;
use Zend_Config;
use Zend_Form_Element_Submit;
use Zend_Form_Element_Button;
use Exception;
use Icinga\Exception\IcingaException;
/**
* A dashboard pane component
@ -218,13 +214,13 @@ EOD;
/**
* Create a @see Component instance from the given Zend config, using the provided title
*
* @param $title The title for this component
* @param Zend_Config $config The configuration defining url, parameters, height, width, etc.
* @param Pane $pane The pane this component belongs to
* @param $title The title for this component
* @param Config $config The configuration defining url, parameters, height, width, etc.
* @param Pane $pane The pane this component belongs to
*
* @return Component A newly created Component for use in the Dashboard
* @return Component A newly created Component for use in the Dashboard
*/
public static function fromIni($title, Zend_Config $config, Pane $pane)
public static function fromIni($title, Config $config, Pane $pane)
{
$height = null;
$width = null;

View File

@ -4,7 +4,7 @@
namespace Icinga\Web\Widget\Dashboard;
use Zend_Config;
use Icinga\Application\Config;
use Icinga\Web\Widget\AbstractWidget;
use Icinga\Exception\ProgrammingError;
use Icinga\Exception\ConfigurationError;
@ -253,11 +253,11 @@ class Pane extends AbstractWidget
* Create a new pane with the title $title from the given configuration
*
* @param $title The title for this pane
* @param Zend_Config $config The configuration to use for setup
* @param Config $config The configuration to use for setup
*
* @return Pane
*/
public static function fromIni($title, Zend_Config $config)
public static function fromIni($title, Config $config)
{
$pane = new Pane($title);
if ($config->get('title', false)) {

View File

@ -201,7 +201,7 @@ class Tab extends AbstractWidget
$caption = $view->escape($this->title);
if ($this->icon !== null) {
$caption = $view->img($this->icon, array('class' => 'icon')) . ' ' . $caption;
$caption = $view->img($this->icon, array('class' => 'icon')) . $caption;
}
if ($this->url !== null) {
$this->url->overwriteParams($this->urlParams);

View File

@ -9,17 +9,14 @@ use Icinga\Module\Monitoring\Form\Command\DisableNotificationWithExpireForm;
use Icinga\Module\Monitoring\Form\Command\SingleArgumentCommandForm;
use Icinga\Web\Form;
use Icinga\Web\Url;
use Icinga\Data\Filter\Filter;
use Icinga\Web\Notification;
use Icinga\Module\Monitoring\Controller;
use Icinga\Protocol\Commandpipe\CommandPipe;
use Icinga\Exception\ConfigurationError;
use Icinga\Exception\MissingParameterException;
use Icinga\Module\Monitoring\Backend;
use Icinga\Module\Monitoring\Form\Command\AcknowledgeForm;
use Icinga\Module\Monitoring\Form\Command\CommentForm;
use Icinga\Module\Monitoring\Form\Command\CommandForm;
use Icinga\Module\Monitoring\Form\Command\CommandWithIdentifierForm;
use Icinga\Module\Monitoring\Form\Command\CustomNotificationForm;
use Icinga\Module\Monitoring\Form\Command\DelayNotificationForm;
use Icinga\Module\Monitoring\Form\Command\RescheduleNextCheckForm;

View File

@ -296,7 +296,7 @@ class Monitoring_ListController extends Controller
->order('downtime_scheduled_start', 'DESC');
$this->applyFilters($query);
$this->view->downtimes = $query->paginate();
$this->setupSortControl(array(
'downtime_is_in_effect' => $this->translate('Is In Effect'),
'downtime_host' => $this->translate('Host / Service'),
@ -308,6 +308,8 @@ class Monitoring_ListController extends Controller
'downtime_scheduled_end' => $this->translate('Scheduled End'),
'downtime_duration' => $this->translate('Duration'),
));
$this->view->downtimes = $query->paginate();
$this->view->delDowntimeForm = new DeleteDowntimeCommandForm();
}
@ -570,12 +572,12 @@ class Monitoring_ListController extends Controller
$this->view->history = $query->paginate();
}
public function servicematrixAction()
public function servicegridAction()
{
if ($url = $this->hasBetterUrl()) {
return $this->redirectNow($url);
}
$this->addTitleTab('servicematrix');
$this->addTitleTab('servicegrid', $this->translate('Service Grid'));
$this->setAutorefreshInterval(15);
$query = $this->backend->select()->from('serviceStatus', array(
'host_name',

View File

@ -4,16 +4,13 @@
use \DateTime;
use \DateInterval;
use \Zend_Config;
use Icinga\Web\Url;
use Icinga\Util\Format;
use Icinga\Application\Config;
use Icinga\Util\DateTimeFactory;
use Icinga\Module\Monitoring\Controller;
use Icinga\Module\Monitoring\Timeline\TimeLine;
use Icinga\Module\Monitoring\Timeline\TimeRange;
use Icinga\Module\Monitoring\Web\Widget\SelectBox;
use Icinga\Module\Monitoring\DataView\EventHistory as EventHistoryView;
class Monitoring_TimelineController extends Controller
{
@ -257,22 +254,6 @@ class Monitoring_TimelineController extends Controller
);
}
/**
* Get the application's global configuration or an empty one
*
* @return Zend_Config
*/
private function getGlobalConfiguration()
{
$globalConfig = Config::app()->global;
if ($globalConfig === null) {
$globalConfig = new Zend_Config(array());
}
return $globalConfig;
}
/**
* Get the user's preferred time format or the application's default
*

View File

@ -4,7 +4,7 @@
namespace Icinga\Module\Monitoring\Form\Command;
use Icinga\Module\Monitoring\Backend;
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
use Icinga\Module\Monitoring\Command\Transport\CommandTransport;
use Icinga\Web\Form;
use Icinga\Web\Request;
@ -24,11 +24,11 @@ abstract class CommandForm extends Form
/**
* Set the monitoring backend
*
* @param Backend $backend
* @param MonitoringBackend $backend
*
* @return $this
*/
public function setBackend(Backend $backend)
public function setBackend(MonitoringBackend $backend)
{
$this->backend = $backend;
return $this;

View File

@ -225,15 +225,31 @@ class BackendConfigForm extends ConfigForm
'value' => $resourceType
)
);
$this->addElement(
$resourceElement = $this->createElement(
'select',
'resource',
array(
'required' => true,
'label' => mt('monitoring', 'Resource'),
'description' => mt('monitoring', 'The resource to use'),
'multiOptions' => $this->resources[$resourceType]
'multiOptions' => $this->resources[$resourceType],
'autosubmit' => true
)
);
$resourceName = (isset($formData['resource'])) ? $formData['resource'] : $this->getValue('resource');
if ($resourceElement) {
$resourceElement->getDecorator('Description')->setEscape(false);
$link = sprintf(
'<a href="%s" data-base-target="_main">%s</a>',
$this->getView()->href('/icingaweb/config/editresource', array('resource' => $resourceName)),
mt('monitoring', 'Show resource configuration')
);
$resourceElement->setDescription($resourceElement->getDescription() . ' (' . $link . ')');
}
$this->addElement($resourceElement);
}
}

View File

@ -55,7 +55,8 @@ class SecurityConfigForm extends ConfigForm
'text',
'protected_customvars',
array(
'required' => true,
'allowEmpty' => true,
'value' => '*pw*,*pass*,community',
'label' => mt('monitoring', 'Protected Custom Variables'),
'description' => mt('monitoring',
'Comma separated case insensitive list of protected custom variables.'

View File

@ -17,6 +17,18 @@ class BackendPage extends Form
public function createElements(array $formData)
{
$this->addElement(
new Note(
'title',
array(
'value' => mt('monitoring', 'Monitoring Backend', 'setup.page.title'),
'decorators' => array(
'ViewHelper',
array('HtmlTag', array('tag' => 'h2'))
)
)
)
);
$this->addElement(
new Note(
'description',
@ -34,20 +46,17 @@ class BackendPage extends Form
'name',
array(
'required' => true,
'value' => 'icinga',
'label' => mt('monitoring', 'Backend Name'),
'description' => mt('monitoring', 'The identifier of this backend')
)
);
$resourceTypes = array('livestatus' => 'Livestatus');
if (
Platform::extensionLoaded('pdo') && (
Platform::zendClassExists('Zend_Db_Adapter_Pdo_Mysql')
|| Platform::zendClassExists('Zend_Db_Adapter_Pdo_Pgsql')
)
) {
$resourceTypes = array();
if (Platform::extensionLoaded('mysql') || Platform::extensionLoaded('pgsql')) {
$resourceTypes['ido'] = 'IDO';
}
$resourceTypes['livestatus'] = 'Livestatus';
$this->addElement(
'select',

View File

@ -25,6 +25,18 @@ class IdoResourcePage extends Form
'value' => 'db'
)
);
$this->addElement(
new Note(
'title',
array(
'value' => mt('monitoring', 'Monitoring IDO Resource', 'setup.page.title'),
'decorators' => array(
'ViewHelper',
array('HtmlTag', array('tag' => 'h2'))
)
)
)
);
$this->addElement(
new Note(
'description',
@ -53,6 +65,7 @@ class IdoResourcePage extends Form
$livestatusResourceForm = new DbResourceForm();
$this->addElements($livestatusResourceForm->createElements($formData)->getElements());
$this->getElement('name')->setValue('icinga_ido');
}
public function isValid($data)

View File

@ -17,6 +17,18 @@ class InstancePage extends Form
public function createElements(array $formData)
{
$this->addElement(
new Note(
'title',
array(
'value' => mt('monitoring', 'Monitoring Instance', 'setup.page.title'),
'decorators' => array(
'ViewHelper',
array('HtmlTag', array('tag' => 'h2'))
)
)
)
);
$this->addElement(
new Note(
'description',
@ -36,5 +48,6 @@ class InstancePage extends Form
$instanceConfigForm = new InstanceConfigForm();
$instanceConfigForm->createElements($formData);
$this->addElements($instanceConfigForm->getElements());
$this->getElement('name')->setValue('icinga');
}
}

View File

@ -25,6 +25,18 @@ class LivestatusResourcePage extends Form
'value' => 'livestatus'
)
);
$this->addElement(
new Note(
'title',
array(
'value' => mt('monitoring', 'Monitoring Livestatus Resource', 'setup.page.title'),
'decorators' => array(
'ViewHelper',
array('HtmlTag', array('tag' => 'h2'))
)
)
)
);
$this->addElement(
new Note(
'description',
@ -53,6 +65,7 @@ class LivestatusResourcePage extends Form
$livestatusResourceForm = new LivestatusResourceForm();
$this->addElements($livestatusResourceForm->createElements($formData)->getElements());
$this->getElement('name')->setValue('icinga_livestatus');
}
public function isValid($data)

View File

@ -17,6 +17,18 @@ class SecurityPage extends Form
public function createElements(array $formData)
{
$this->addElement(
new Note(
'title',
array(
'value' => mt('monitoring', 'Monitoring Security', 'setup.page.title'),
'decorators' => array(
'ViewHelper',
array('HtmlTag', array('tag' => 'h2'))
)
)
)
);
$this->addElement(
new Note(
'description',

View File

@ -20,7 +20,10 @@ class WelcomePage extends Form
new Note(
'welcome',
array(
'value' => mt('monitoring', 'Welcome to the installation of the monitoring module for Icinga Web 2!'),
'value' => mt(
'monitoring',
'Welcome to the configuration of the monitoring module for Icinga Web 2!'
),
'decorators' => array(
'ViewHelper',
array('HtmlTag', array('tag' => 'h2'))

View File

@ -0,0 +1,55 @@
<?php
class Zend_View_Helper_Customvar extends Zend_View_Helper_Abstract
{
/**
* Create dispatch instance
*
* @return self
*/
public function checkPerformance()
{
return $this;
}
public function customvar($struct)
{
if (is_string($struct) || is_int($struct) || is_float($struct)) {
return $this->view->escape((string) $struct);
} elseif (is_array($struct)) {
return $this->renderArray($struct);
} elseif (is_object($struct)) {
return $this->renderObject($struct);
}
}
protected function renderArray($array)
{
if (empty($array)) {
return '[]';
}
$out = "<ul>\n";
foreach ($array as $val) {
$out .= '<li>' . $this->customvar($val) . "</li>\n";
}
return $out . "</ul>\n";
}
protected function renderObject($object)
{
if (empty($object)) {
return '{}';
}
$out = "{<ul>\n";
foreach ($object as $key => $val) {
$out .= '<li>'
. $this->view->escape($key)
. ' => '
. $this->customvar($val)
. "</li>\n";
}
return $out . "</ul>}";
}
}

View File

@ -95,8 +95,11 @@ class Zend_View_Helper_MonitoringState extends Zend_View_Helper_Abstract
*/
public function getStateTitle($object, $type)
{
return strtoupper($this->monitoringState($object, $type))
. ' since '
. date('Y-m-d H:i:s', $object->{$type.'_last_state_change'});
return sprintf(
'%s %s %s',
$this->view->translate(strtoupper($this->monitoringState($object, $type))),
$this->view->translate('since'),
date('Y-m-d H:i:s', $object->{$type.'_last_state_change'})
);
}
}

View File

@ -3,6 +3,9 @@
<?= $this->tabs->render($this); ?>
<div style="margin: 1em" class="dontprint">
<?= $this->translate('Sort by'); ?> <?= $this->sortControl->render($this); ?>
<?php if (! $this->filterEditor): ?>
<?= $this->filterPreview ?>
<?php endif; ?>
</div>
<?= $this->widget('limiter', array('url' => $this->url, 'max' => $downtimes->count())); ?>
<?= $this->paginationControl($downtimes, null, null, array('preserve' => $this->preserve)); ?>
@ -10,6 +13,7 @@
<?php endif ?>
<div class="content">
<?= $this->filterEditor ?>
<?php if (empty($downtimes)): ?>
<?= $this->translate('No downtimes matching the filter'); ?>
</div>

View File

@ -0,0 +1,77 @@
<?php if (!$this->compact): ?>
<div class="controls">
<?= $this->tabs; ?>
<div style="margin: 1em;" class="dontprint">
<?= $this->translate('Sort by'); ?> <?= $this->sortControl; ?>
</div>
</div>
<?php endif ?>
<div class="content" data-base-target="_next">
<table class="pivot servicestates">
<?php
$hasHeader = false;
$pivotData = $this->pivot->toArray();
$hostFilter = '(' . implode('|', array_keys($pivotData)) . ')';
?>
<?php if (count($pivotData) === 0): ?>
<?= $this->translate('No Services matching the filter'); ?>
<?php endif ?>
<?php foreach ($pivotData as $host_name => $serviceStates): ?>
<?php if (!$hasHeader): ?>
<thead>
<tr>
<th><?= $this->partial(
'joystickPagination.phtml',
'default',
array(
'xAxisPaginator' => $horizontalPaginator,
'yAxisPaginator' => $verticalPaginator
)
); ?></th>
<th colspan="<?= count($serviceStates); ?>">
<div>
<?php foreach (array_keys($serviceStates) as $service_description): ?>
<span>
<a href="<?= $this->href(
'monitoring/list/services',
array(
'service_description' => $service_description,
'host_name' => $hostFilter
)
); ?>">
<abbr title="<?= $service_description; ?>">
<?= strlen($service_description) > 18 ? substr($service_description, 0, 18) . '...' : $service_description; ?>
</abbr>
</a>
</span>
<?php endforeach ?>
</div>
</th>
</tr>
</thead>
<tbody>
<?php $hasHeader = true; ?>
<?php endif ?>
<tr>
<th>
<a href="<?= $this->href('monitoring/show/services', array('host' => $host_name)); ?>"><?= $host_name; ?></a>
</th>
<?php foreach (array_values($serviceStates) as $service): ?>
<?php if ($service !== null): ?>
<td>
<a href="<?= $this->href('monitoring/show/service', array(
'host' => $service->host_name,
'service' => $service->service_description
)); ?>" title="<?= $this->escape($service->service_output); ?>" class="state_<?= $this->monitoringState($service, 'service'); ?> <?= $service->service_handled ? 'handled' : ''; ?>"></a>
</td>
<?php else: ?>
<td>&middot;</td>
<?php endif ?>
<?php endforeach ?>
</tr>
<?php endforeach ?>
</tbody>
</table>
</div>

View File

@ -1,84 +0,0 @@
<?php if (!$this->compact): ?>
<div class="controls">
<?= $this->tabs; ?>
<div style="margin: 1em;" class="dontprint">
<?= $this->translate('Sort by') ?> <?= $this->sortControl ?>
</div>
<?= $this->partial(
'pivottablePagination.phtml',
'default',
array(
'xAxisPaginator' => $this->horizontalPaginator,
'yAxisPaginator' => $this->verticalPaginator
)
); ?>
</div>
<?php endif ?>
<div class="content" data-base-target="_next">
<table class="pivot servicestates">
<?php
$hasHeader = false;
$pivotData = $this->pivot->toArray();
$hostFilter = '(' . implode('|', array_keys($pivotData)) . ')';
?>
<?php if (count($pivotData) === 0): ?>
<?= $this->translate('No Services matching the filter'); ?>
<?php endif ?>
<?php foreach ($pivotData as $host_name => $serviceStates): ?>
<?php if (!$hasHeader): ?>
<thead>
<tr>
<th>&nbsp;</th>
<th colspan="<?= count($serviceStates); ?>">
<div>
<?php foreach (array_keys($serviceStates) as $service_description): ?>
<span>
<a href="<?= $this->href(
'monitoring/list/services',
array(
'service_description' => $service_description,
'host_name' => $hostFilter
)
); ?>">
<abbr title="<?= $service_description; ?>"><?=
strlen($service_description) > 18 ?
substr($service_description, 0, 18) . '...' :
$service_description
?></abbr>
</a>
</span>
<?php endforeach ?>
</div>
</th>
</tr>
</thead>
<tbody>
<?php $hasHeader = true; ?>
<?php endif ?>
<tr>
<th>
<a href="<?=
$this->href('monitoring/show/services', array('host' => $host_name))
?>"><?= $host_name ?></a>
</th>
<?php foreach (array_values($serviceStates) as $service): ?>
<?php if ($service !== null): ?>
<td>
<a href="<?= $this->href('monitoring/show/service', array(
'host' => $service->host_name,
'service' => $service->service_description
)) ?>" title="<?= $this->escape($service->service_output)
?>" class="state_<?= $this->monitoringState($service, 'service') ?> <?= $service->service_handled ? 'handled' : '' ?>"></a>
</td>
<?php else: ?>
<td>&middot;</td>
<?php endif ?>
<?php endforeach ?>
</tr>
<?php endforeach ?>
</tbody>
</table>
</div>

View File

@ -1,8 +1,11 @@
<?php
foreach ($object->customvars as $name => $value) {
printf(
"<tr><th>%s</th><td>%s</td></tr>\n",
'<tr><th>%s</th><td class="customvar">%s</td></tr>' . "\n",
$this->escape($name),
$this->escape($value)
$this->customvar($value)
);
}

View File

@ -1,123 +0,0 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
use Icinga\Module\Monitoring\Backend;
use Icinga\Util\Format;
$backend = Backend::getInstance($params->shift('backend'));
$query = $backend->select()->from('status', array(
'host_name',
'host_state',
'host_output',
'host_acknowledged',
'host_in_downtime',
'service_description',
'service_state',
'service_acknowledged',
'service_in_downtime',
'service_handled',
'service_output',
'service_last_state_change'
))->order('service_last_state_change ASC');
$endless = $params->shift('endless');
$query->applyFilters($params->getParams());
$host_colors = array(
0 => '2', // UP
1 => '1', // DOWN
2 => '3', // UNREACH (brown)
99 => '0', // PEND
);
$host_states = array(
0 => 'UP', // UP
1 => 'DOWN', // DOWN
2 => 'UNREACHABLE', // UNREACH (brown)
99 => 'PENDING', // PEND
);
$service_colors = array(
0 => '2', // OK
1 => '3', // WARN
2 => '1', // CRIT
3 => '5', // UNKN
99 => '0', // PEND
);
$service_states = array(
0 => 'OK', // OK
1 => 'WARNING', // WARN
2 => 'CRITICAL', // CRIT
3 => 'UNKNOWN', // UNKN
99 => 'PENDING', // PEND
);
$finished = false;
while (! $finished) {
$out = '';
$last_host = null;
foreach ($query->fetchAll() as $key => $row) {
$host_extra = array();
if ($row->host_in_downtime) {
$host_extra[] = 'DOWNTIME';
}
if ($row->host_acknowledged) {
$host_extra[] = 'ACK';
}
if (empty($host_extra)) {
$host_extra = '';
} else {
$host_extra = " \033[34;1m[" . implode(',', $host_extra) . "]\033[0m";
}
$service_extra = array();
if ($row->service_in_downtime) {
$service_extra[] = 'DOWNTIME';
}
if ($row->service_acknowledged) {
$service_extra[] = 'ACK';
}
if (empty($service_extra)) {
$service_extra = '';
} else {
$service_extra = " \033[34;52;1m[" . implode(',', $service_extra) . "]\033[0m";
}
if ($row->host_name !== $last_host) {
$out .= sprintf(
"\n\033[01;37;4%dm %-5s \033[0m \033[30;1m%s\033[0m%s: %s\n",
$host_colors[$row->host_state],
substr($host_states[$row->host_state], 0, 5),
$row->host_name,
$host_extra,
$row->host_output
);
}
$last_host = $row->host_name;
$out .= sprintf(
"\033[01;37;4%dm \033[01;37;4%dm %4s \033[0m %s%s since %s: %s\n",
$host_colors[$row->host_state],
$service_colors[$row->service_state],
substr($service_states[$row->service_state] . ' ', 0, 4),
$row->service_description,
$service_extra,
Format::timeSince($row->service_last_state_change),
preg_replace('/\n/', sprintf(
"\n\033[01;37;4%dm \033[01;37;4%dm \033[0m ",
$host_colors[$row->host_state],
$service_colors[$row->service_state]
), substr(wordwrap(str_repeat(' ', 30) . preg_replace('~\@{3,}~', '@@@', $row->service_output), 72), 30))
);
}
$out .= "\n";
if ($endless) {
echo "\033[2J\033[1;1H\033[1S" . $out;
sleep(3);
} else {
echo $out;
$finished = true;
}
}

View File

@ -18,7 +18,7 @@ $this->provideConfigTab('security', array(
'title' => 'Security',
'url' => 'config/security'
));
$this->provideSetupWizard('Icinga\Module\Monitoring\Setup');
$this->provideSetupWizard('Icinga\Module\Monitoring\MonitoringWizard');
/*
* Available Search Urls
@ -75,8 +75,8 @@ $section->add($this->translate('Services'), array(
'url' => 'monitoring/list/services',
'priority' => 50
));
$section->add($this->translate('Servicematrix'), array(
'url' => 'monitoring/list/servicematrix?service_problem=1',
$section->add($this->translate('Service Grid'), array(
'url' => 'monitoring/list/servicegrid?service_problem=1',
'priority' => 51
));
$section->add($this->translate('Servicegroups'), array(

View File

@ -1,186 +1,11 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
// TODO: obsolete, remove once MonitoringBackend is in use everywhere
namespace Icinga\Module\Monitoring;
use Icinga\Exception\ProgrammingError;
use Icinga\Data\Selectable;
use Icinga\Data\Queryable;
use Icinga\Data\ConnectionInterface;
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
use Icinga\Application\Config as IcingaConfig;
use Icinga\Data\ResourceFactory;
use Icinga\Exception\ConfigurationError;
/**
* Data view and query loader tied to a backend type
*/
class Backend implements Selectable, Queryable, ConnectionInterface
class Backend extends MonitoringBackend
{
/**
* Resource
*
* @var mixed
*/
protected $resource;
/**
* Type
*
* @var string
*/
protected $type;
protected $name;
/**
* Create a new backend
*
* @param mixed $resource
* @param string $type
*/
public function __construct($resource, $type)
{
$this->resource = $resource;
$this->type = $type;
}
// Temporary workaround, we have no way to know our name
protected function setName($name)
{
$this->name = $name;
}
public function getName()
{
return $this->name;
}
/**
* Create a backend
*
* @param string $backendName Name of the backend or null for creating the default backend which is the first INI
* configuration entry not being disabled
*
* @return Backend
* @throws ConfigurationError When no backend has been configured or all backends are disabled or the
* configuration for the requested backend does either not exist or it's disabled
*/
public static function createBackend($backendName = null)
{
$config = IcingaConfig::module('monitoring', 'backends');
if ($config->count() === 0) {
throw new ConfigurationError(mt('monitoring', 'No backend has been configured'));
}
if ($backendName !== null) {
$backendConfig = $config->get($backendName);
if ($backendConfig === null) {
throw new ConfigurationError('No configuration for backend %s', $backendName);
}
if ((bool) $backendConfig->get('disabled', false) === true) {
throw new ConfigurationError(
mt('monitoring', 'Configuration for backend %s available but backend is disabled'),
$backendName
);
}
} else {
foreach ($config as $name => $backendConfig) {
if ((bool) $backendConfig->get('disabled', false) === false) {
$backendName = $name;
break;
}
}
if ($backendName === null) {
throw new ConfigurationError(mt('monitoring', 'All backends are disabled'));
}
}
$resource = ResourceFactory::create($backendConfig->resource);
if ($backendConfig->type === 'ido' && $resource->getDbType() !== 'oracle') {
// TODO(el): The resource should set the table prefix
$resource->setTablePrefix('icinga_');
}
$backend = new Backend($resource, $backendConfig->type);
$backend->setName($backendName);
return $backend;
}
public function getResource()
{
return $this->resource;
}
/**
* Backend entry point
*
* @return self
*/
public function select()
{
return $this;
}
/**
* Create a data view to fetch data from
*
* @param string $viewName
* @param array $columns
*
* @return DataView
*/
public function from($viewName, array $columns = null)
{
$viewClass = $this->resolveDataViewName($viewName);
return new $viewClass($this, $columns);
}
/**
* View name to class name resolution
*
* @param string $viewName
*
* @return string
* @throws ProgrammingError When the view does not exist
*/
protected function resolveDataViewName($viewName)
{
$viewClass = '\\Icinga\\Module\\Monitoring\\DataView\\' . ucfirst($viewName);
if (!class_exists($viewClass)) {
throw new ProgrammingError(
'DataView %s does not exist',
ucfirst($viewName)
);
}
return $viewClass;
}
public function getQueryClass($name)
{
return $this->resolveQueryName($name);
}
/**
* Query name to class name resolution
*
* @param string $queryName
*
* @return string
* @throws ProgrammingError When the query does not exist for this backend
*/
protected function resolveQueryName($queryName)
{
$queryClass = '\\Icinga\\Module\\Monitoring\\Backend\\'
. ucfirst($this->type)
. '\\Query\\'
. ucfirst($queryName)
. 'Query';
if (!class_exists($queryClass)) {
throw new ProgrammingError(
'Query "%s" does not exist for backend %s',
ucfirst($queryName),
ucfirst($this->type)
);
}
return $queryClass;
}
}

View File

@ -0,0 +1,9 @@
<?php
namespace Icinga\Module\Monitoring\Backend\Ido;
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
class IdoBackend extends MonitoringBackend
{
}

View File

@ -10,6 +10,7 @@ class CustomvarQuery extends IdoQuery
'customvars' => array(
'varname' => 'cvs.varname',
'varvalue' => 'cvs.varvalue',
'is_json' => 'cvs.is_json',
),
'objects' => array(
'host' => 'cvo.name1 COLLATE latin1_general_ci',
@ -37,6 +38,10 @@ class CustomvarQuery extends IdoQuery
protected function joinBaseTables()
{
if (version_compare($this->getIdoVersion(), '1.12.0', '<')) {
$this->columnMap['customvars']['is_json'] = '(0)';
}
$this->select->from(
array('cvs' => $this->prefix . 'customvariablestatus'),
array()

View File

@ -16,6 +16,7 @@ class DowntimeQuery extends IdoQuery
protected $columnMap = array(
'downtime' => array(
'downtime_author' => 'sd.author_name',
'author' => 'sd.author_name',
'downtime_comment' => 'sd.comment_data',
'downtime_entry_time' => 'UNIX_TIMESTAMP(sd.entry_time)',
'downtime_is_fixed' => 'sd.is_fixed',

View File

@ -0,0 +1,331 @@
<?php
namespace Icinga\Module\Monitoring\Backend;
use Icinga\Application\Config;
use Icinga\Data\ResourceFactory;
use Icinga\Data\ConnectionInterface;
use Icinga\Data\Queryable;
use Icinga\Data\Selectable;
use Icinga\Exception\ConfigurationError;
use Icinga\Exception\ProgrammingError;
class MonitoringBackend implements Selectable, Queryable, ConnectionInterface
{
/**
* Backend configuration
*
* @var Config
*/
protected $config;
/**
* Resource
*
* @var mixed
*/
protected $resource;
/**
* Type
*
* @var string
*/
protected $type;
/**
* The configured name of this backend
*
* @var string
*/
protected $name;
/**
* Already created instances
*
* @var array
*/
protected static $instances = array();
/**
* Create a new backend
*
* @param string $name
* @param mixed $config
*/
protected function __construct($name, $config)
{
$this->name = $name;
$this->config = $config;
}
/**
* Get a backend instance
*
* You may ask for a specific backend name or get the default one otherwise
*
* @param string $name Backend name
*
* @return MonitoringBackend
*/
public static function instance($name = null)
{
if (! array_key_exists($name, self::$instances)) {
list($foundName, $config) = static::loadConfig($name);
$type = $config->get('type');
$class = implode(
'\\',
array(
__NAMESPACE__,
ucfirst($type),
ucfirst($type) . 'Backend'
)
);
if (!class_exists($class)) {
throw new ConfigurationError(
mt('monitoring', 'There is no "%s" monitoring backend'),
$class
);
}
self::$instances[$name] = new $class($foundName, $config);
if ($name === null) {
self::$instances[$foundName] = self::$instances[$name];
}
}
return self::$instances[$name];
}
/**
* Clear all cached instances. Mostly for testing purposes.
*/
public static function clearInstances()
{
self::$instances = array();
}
/**
* Whether this backend is of a specific type
*
* @param string $type Backend type
*
* @return boolean
*/
public function is($type)
{
return $this->getType() === $type;
}
/**
* Get the configured name of this backend
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Get the backend type name
*
* @return string
*/
public function getType()
{
if ($this->type === null) {
$parts = preg_split('~\\\~', get_class($this));
$class = array_pop($parts);
if (substr($class, -7) === 'Backend') {
$this->type = lcfirst(substr($class, 0, -7));
} else {
throw new ProgrammingError(
'%s is not a valid monitoring backend class name',
$class
);
}
}
return $this->type;
}
/**
* Return the configuration for the first enabled or the given backend
*/
protected static function loadConfig($name = null)
{
$backends = Config::module('monitoring', 'backends');
if ($name === null) {
$count = 0;
foreach ($backends as $name => $config) {
$count++;
if ((bool) $config->get('disabled', false) === false) {
return array($name, $config);
}
}
if ($count === 0) {
$message = mt('monitoring', 'No backend has been configured');
} else {
$message = mt('monitoring', 'All backends are disabled');
}
throw new ConfigurationError($message);
} else {
$config = $backends->get($name);
if ($config === null) {
throw new ConfigurationError(
mt('monitoring', 'No configuration for backend %s'),
$name
);
}
if ((bool) $config->get('disabled', false) === true) {
throw new ConfigurationError(
mt('monitoring', 'Configuration for backend %s is disabled'),
$name
);
}
return array($name, $config);
}
}
/**
* Create a backend
*
* @deprecated
*
* @param string $backendName Name of the backend or null for creating the default backend which is the first INI
* configuration entry not being disabled
*
* @return Backend
* @throws ConfigurationError When no backend has been configured or all backends are disabled or the
* configuration for the requested backend does either not exist or it's disabled
*/
public static function createBackend($name = null)
{
return self::instance($name);
}
/**
* Get this backend's internal resource
*
* @return mixed
*/
public function getResource()
{
if ($this->resource === null) {
$this->resource = ResourceFactory::create($this->config->get('resource'));
if ($this->is('ido') && $this->resource->getDbType() !== 'oracle') {
// TODO(el): The resource should set the table prefix
$this->resource->setTablePrefix('icinga_');
}
}
return $this->resource;
}
/**
* Backend entry point
*
* @return self
*/
public function select()
{
return $this;
}
/**
* Create a data view to fetch data from
*
* @param string $name
* @param array $columns
*
* @return DataView
*/
public function from($name, array $columns = null)
{
$class = $this->buildViewClassName($name);
return new $class($this, $columns);
}
/**
* View name to class name resolution
*
* @param string $viewName
*
* @return string
* @throws ProgrammingError When the view does not exist
*/
protected function buildViewClassName($view)
{
$class = '\\Icinga\\Module\\Monitoring\\DataView\\' . ucfirst($view);
if (!class_exists($class)) {
throw new ProgrammingError(
'DataView %s does not exist',
ucfirst($view)
);
}
return $class;
}
/**
* Get a specific query class instance
*
* @param string $name Query name
* @param array $columns Optional column list
*
* @return Icinga\Data\QueryInterface
*/
public function query($name, $columns = null)
{
$class = $this->buildQueryClassName($name);
if (!class_exists($class)) {
throw new ProgrammingError(
'Query "%s" does not exist for backend %s',
$name,
$this->getType()
);
}
return new $class($this->getResource(), $columns);
}
/**
* Whether this backend supports the given query
*
* @param string $name Query name to check for
*
* @return bool
*/
public function hasQuery($name)
{
return class_exists($this->buildQueryClassName($name));
}
/**
* Query name to class name resolution
*
* @param string $query
*
* @return string
* @throws ProgrammingError When the query does not exist for this backend
*/
protected function buildQueryClassName($query)
{
$parts = preg_split('~\\\~', get_class($this));
array_pop($parts);
array_push($parts, 'Query', ucfirst($query) . 'Query');
return implode('\\', $parts);
}
}

View File

@ -2,11 +2,10 @@
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\Installation;
namespace Icinga\Module\Monitoring;
use Exception;
use Zend_Config;
use Icinga\Web\Setup\Step;
use Icinga\Module\Setup\Step;
use Icinga\Application\Config;
use Icinga\File\Ini\IniWriter;
@ -40,9 +39,8 @@ class BackendStep extends Step
try {
$writer = new IniWriter(array(
'config' => new Zend_Config($config),
'filename' => Config::resolvePath('modules/monitoring/backends.ini'),
'filemode' => octdec($this->data['fileMode'])
'config' => new Config($config),
'filename' => Config::resolvePath('modules/monitoring/backends.ini')
));
$writer->write();
} catch (Exception $e) {
@ -62,12 +60,12 @@ class BackendStep extends Step
try {
$config = Config::app('resources', true);
$config->merge(new Zend_Config(array($resourceName => $resourceConfig)));
$config->merge(new Config(array($resourceName => $resourceConfig)));
$writer = new IniWriter(array(
'config' => $config,
'filename' => Config::resolvePath('resources.ini'),
'filemode' => octdec($this->data['fileMode'])
'filemode' => 0660
));
$writer->write();
} catch (Exception $e) {
@ -81,7 +79,7 @@ class BackendStep extends Step
public function getSummary()
{
$pageTitle = '<h2>' . mt('monitoring', 'Monitoring Backend') . '</h2>';
$pageTitle = '<h2>' . mt('monitoring', 'Monitoring Backend', 'setup.page.title') . '</h2>';
$backendDescription = '<p>' . sprintf(
mt(
'monitoring',

View File

@ -4,7 +4,6 @@
namespace Icinga\Module\Monitoring\Command\Transport;
use Zend_Config;
use Icinga\Application\Config;
use Icinga\Exception\ConfigurationError;
@ -45,12 +44,12 @@ abstract class CommandTransport
/**
* Create a transport from config
*
* @param Zend_Config $config
* @param Config $config
*
* @return LocalCommandFile|RemoteCommandFile
* @throws ConfigurationError
*/
public static function fromConfig(Zend_Config $config)
public static function fromConfig(Config $config)
{
switch (strtolower($config->transport)) {
case RemoteCommandFile::TRANSPORT:

View File

@ -19,6 +19,7 @@ class Customvar extends DataView
return array(
'varname',
'varvalue',
'is_json',
'object_type'
);
}

View File

@ -15,7 +15,7 @@ use Icinga\Data\Filterable;
use Icinga\Exception\QueryException;
use Icinga\Web\Request;
use Icinga\Web\Url;
use Icinga\Module\Monitoring\Backend;
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
/**
* A read-only view of an underlying query
@ -44,8 +44,7 @@ abstract class DataView implements Browsable, Countable, Filterable, Sortable
public function __construct(ConnectionInterface $connection, array $columns = null)
{
$this->connection = $connection;
$queryClass = $connection->getQueryClass($this->getQueryName());
$this->query = new $queryClass($this->connection->getResource(), $columns);
$this->query = $connection->query($this->getQueryName(), $columns);
$this->filter = Filter::matchAll();
$this->init();
}
@ -105,7 +104,7 @@ abstract class DataView implements Browsable, Countable, Filterable, Sortable
*/
public static function fromRequest($request, array $columns = null)
{
$view = new static(Backend::createBackend($request->getParam('backend')), $columns);
$view = new static(MonitoringBackend::instance($request->getParam('backend')), $columns);
$view->applyUrlFilter($request);
return $view;
@ -141,7 +140,7 @@ abstract class DataView implements Browsable, Countable, Filterable, Sortable
*/
public static function fromParams(array $params, array $columns = null)
{
$view = new static(Backend::createBackend($params['backend']), $columns);
$view = new static(MonitoringBackend::instance($params['backend']), $columns);
foreach ($params as $key => $value) {
if ($view->isValidFilterTarget($key)) {

View File

@ -16,6 +16,7 @@ class Downtime extends DataView
return array(
'downtime_objecttype',
'downtime_author',
'author',
'downtime_comment',
'downtime_entry_time',
'downtime_is_fixed',

View File

@ -2,11 +2,10 @@
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\Installation;
namespace Icinga\Module\Monitoring;
use Exception;
use Zend_Config;
use Icinga\Web\Setup\Step;
use Icinga\Module\Setup\Step;
use Icinga\Application\Config;
use Icinga\File\Ini\IniWriter;
@ -29,9 +28,8 @@ class InstanceStep extends Step
try {
$writer = new IniWriter(array(
'config' => new Zend_Config(array($instanceName => $instanceConfig)),
'filename' => Config::resolvePath('modules/monitoring/instances.ini'),
'filemode' => octdec($this->data['fileMode'])
'config' => new Config(array($instanceName => $instanceConfig)),
'filename' => Config::resolvePath('modules/monitoring/instances.ini')
));
$writer->write();
} catch (Exception $e) {
@ -45,7 +43,7 @@ class InstanceStep extends Step
public function getSummary()
{
$pageTitle = '<h2>' . mt('monitoring', 'Monitoring Instance') . '</h2>';
$pageTitle = '<h2>' . mt('monitoring', 'Monitoring Instance', 'setup.page.title') . '</h2>';
if (isset($this->data['instanceConfig']['host'])) {
$pipeHtml = '<p>' . sprintf(

View File

@ -7,15 +7,12 @@ namespace Icinga\Module\Monitoring;
use Icinga\Web\Form;
use Icinga\Web\Wizard;
use Icinga\Web\Request;
use Icinga\Web\Setup\Installer;
use Icinga\Web\Setup\MakeDirStep;
use Icinga\Web\Setup\EnableModuleStep;
use Icinga\Web\Setup\SetupWizard;
use Icinga\Web\Setup\Requirements;
use Icinga\Module\Monitoring\Installation\BackendStep;
use Icinga\Module\Monitoring\Installation\InstanceStep;
use Icinga\Module\Monitoring\Installation\SecurityStep;
use Icinga\Form\Setup\SummaryPage;
use Icinga\Module\Setup\Setup;
use Icinga\Module\Setup\SetupWizard;
use Icinga\Module\Setup\Requirements;
use Icinga\Module\Setup\Utils\MakeDirStep;
use Icinga\Module\Setup\Utils\EnableModuleStep;
use Icinga\Module\Setup\Form\SummaryPage;
use Icinga\Module\Monitoring\Form\Setup\WelcomePage;
use Icinga\Module\Monitoring\Form\Setup\BackendPage;
use Icinga\Module\Monitoring\Form\Setup\InstancePage;
@ -26,7 +23,7 @@ use Icinga\Module\Monitoring\Form\Setup\LivestatusResourcePage;
/**
* Monitoring Module Setup Wizard
*/
class Setup extends Wizard implements SetupWizard
class MonitoringWizard extends Wizard implements SetupWizard
{
/**
* @see Wizard::init()
@ -50,7 +47,7 @@ class Setup extends Wizard implements SetupWizard
if ($page->getName() === 'setup_requirements') {
$page->setRequirements($this->getRequirements());
} elseif ($page->getName() === 'setup_summary') {
$page->setSummary($this->getInstaller()->getSummary());
$page->setSummary($this->getSetup()->getSummary());
$page->setSubjectTitle(mt('monitoring', 'the monitoring module', 'setup.summary.subject'));
} elseif (
$this->getDirection() === static::FORWARD
@ -114,53 +111,45 @@ class Setup extends Wizard implements SetupWizard
$page->getElement(static::BTN_NEXT)->setLabel(t('Start', 'setup.welcome.btn.next'));
} elseif ($index === count($pages) - 1) {
$page->getElement(static::BTN_NEXT)->setLabel(
mt('monitoring', 'Install the monitoring module for Icinga Web 2', 'setup.summary.btn.finish')
mt('monitoring', 'Setup the monitoring module for Icinga Web 2', 'setup.summary.btn.finish')
);
}
}
/**
* @see SetupWizard::getInstaller()
* @see SetupWizard::getSetup()
*/
public function getInstaller()
public function getSetup()
{
$pageData = $this->getPageData();
$installer = new Installer();
$setup = new Setup();
$installer->addStep(
new MakeDirStep(
array($this->getConfigDir() . '/modules/monitoring'),
$pageData['setup_general_config']['global_filemode']
)
);
$setup->addStep(new MakeDirStep(array($this->getConfigDir() . '/modules/monitoring'), 0775));
$installer->addStep(
$setup->addStep(
new BackendStep(array(
'backendConfig' => $pageData['setup_monitoring_backend'],
'resourceConfig' => isset($pageData['setup_monitoring_ido'])
? array_diff_key($pageData['setup_monitoring_ido'], array('skip_validation' => null))
: array_diff_key($pageData['setup_monitoring_livestatus'], array('skip_validation' => null)),
'fileMode' => $pageData['setup_general_config']['global_filemode']
: array_diff_key($pageData['setup_monitoring_livestatus'], array('skip_validation' => null))
))
);
$installer->addStep(
$setup->addStep(
new InstanceStep(array(
'instanceConfig' => $pageData['setup_monitoring_instance'],
'fileMode' => $pageData['setup_general_config']['global_filemode']
'instanceConfig' => $pageData['setup_monitoring_instance']
))
);
$installer->addStep(
$setup->addStep(
new SecurityStep(array(
'securityConfig' => $pageData['setup_monitoring_security'],
'fileMode' => $pageData['setup_general_config']['global_filemode']
'securityConfig' => $pageData['setup_monitoring_security']
))
);
$installer->addStep(new EnableModuleStep('monitoring'));
$setup->addStep(new EnableModuleStep('monitoring'));
return $installer;
return $setup;
}
/**

View File

@ -5,7 +5,7 @@
namespace Icinga\Module\Monitoring\Object;
use InvalidArgumentException;
use Icinga\Module\Monitoring\Backend;
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
/**
* A Icinga host
@ -63,10 +63,10 @@ class Host extends MonitoredObject
/**
* Create a new host
*
* @param Backend $backend Backend to fetch host information from
* @param MonitoringBackend $backend Backend to fetch host information from
* @param string $host Host name
*/
public function __construct(Backend $backend, $host)
public function __construct(MonitoringBackend $backend, $host)
{
parent::__construct($backend);
$this->host = $host;

View File

@ -7,7 +7,7 @@ namespace Icinga\Module\Monitoring\Object;
use InvalidArgumentException;
use Icinga\Application\Config;
use Icinga\Exception\InvalidPropertyException;
use Icinga\Module\Monitoring\Backend;
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
use Icinga\Web\UrlParams;
/**
@ -28,7 +28,7 @@ abstract class MonitoredObject
/**
* Backend to fetch object information from
*
* @var Backend
* @var MonitoringBackend
*/
protected $backend;
@ -119,9 +119,9 @@ abstract class MonitoredObject
/**
* Create a monitored object, i.e. host or service
*
* @param Backend $backend Backend to fetch object information from
* @param MonitoringBackend $backend Backend to fetch object information from
*/
public function __construct(Backend $backend)
public function __construct(MonitoringBackend $backend)
{
$this->backend = $backend;
}
@ -283,7 +283,8 @@ abstract class MonitoredObject
$query = $this->backend->select()->from('customvar', array(
'varname',
'varvalue'
'varvalue',
'is_json'
))
->where('object_type', $this->type)
->where('host_name', $this->host_name);
@ -293,13 +294,16 @@ abstract class MonitoredObject
$this->customvars = array();
$customvars = $query->getQuery()->fetchPairs();
foreach ($customvars as $name => $value) {
$name = ucwords(str_replace('_', ' ', strtolower($name)));
if ($blacklistPattern && preg_match($blacklistPattern, $name)) {
$value = '***';
$customvars = $query->getQuery()->fetchAll();
foreach ($customvars as $name => $cv) {
$name = ucwords(str_replace('_', ' ', strtolower($cv->varname)));
if ($blacklistPattern && preg_match($blacklistPattern, $cv->varname)) {
$this->customvars[$name] = '***';
} elseif ($cv->is_json) {
$this->customvars[$name] = json_decode($cv->varvalue);
} else {
$this->customvars[$name] = $cv->varvalue;
}
$this->customvars[$name] = $value;
}
return $this;
@ -476,9 +480,9 @@ abstract class MonitoredObject
public static function fromParams(UrlParams $params)
{
if ($params->has('service') && $params->has('host')) {
return new Service(Backend::createBackend(), $params->get('host'), $params->get('service'));
return new Service(MonitoringBackend::instance(), $params->get('host'), $params->get('service'));
} elseif ($params->has('host')) {
return new Host(Backend::createBackend(), $params->get('host'));
return new Host(MonitoringBackend::instance(), $params->get('host'));
}
return null;
}

View File

@ -5,7 +5,7 @@ namespace Icinga\Module\Monitoring\Object;
use ArrayIterator;
use Countable;
use IteratorAggregate;
use Icinga\Module\Monitoring\Backend;
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
abstract class ObjectList implements Countable, IteratorAggregate
{
@ -21,7 +21,7 @@ abstract class ObjectList implements Countable, IteratorAggregate
protected $count;
public function __construct(Backend $backend)
public function __construct(MonitoringBackend $backend)
{
$this->backend = $backend;
}

Some files were not shown because too many files have changed in this diff Show More