Merge branch 'master' into feature/setup-wizard-7163
Conflicts: application/forms/Config/General/LoggingConfigForm.php
This commit is contained in:
commit
9f127be1dc
|
@ -5,6 +5,7 @@
|
||||||
namespace Icinga\Form\Config\General;
|
namespace Icinga\Form\Config\General;
|
||||||
|
|
||||||
use Icinga\Application\Icinga;
|
use Icinga\Application\Icinga;
|
||||||
|
use Icinga\Logger\Logger;
|
||||||
use Icinga\Web\Form;
|
use Icinga\Web\Form;
|
||||||
use Icinga\Web\Form\Validator\WritablePathValidator;
|
use Icinga\Web\Form\Validator\WritablePathValidator;
|
||||||
|
|
||||||
|
@ -19,30 +20,14 @@ class LoggingConfigForm extends Form
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see Form::createElements()
|
* (non-PHPDoc)
|
||||||
|
* @see Form::createElements() For the method documentation.
|
||||||
*/
|
*/
|
||||||
public function createElements(array $formData)
|
public function createElements(array $formData)
|
||||||
{
|
{
|
||||||
$this->addElement(
|
$this->addElement(
|
||||||
'select',
|
'select',
|
||||||
'logging_level',
|
'logging_log',
|
||||||
array(
|
|
||||||
'value' => 1,
|
|
||||||
'required' => true,
|
|
||||||
'label' => t('Logging Level'),
|
|
||||||
'description' => t('The maximum loglevel to emit.'),
|
|
||||||
'multiOptions' => array(
|
|
||||||
0 => t('None', 'app.config.logging.level'),
|
|
||||||
1 => t('Error', 'app.config.logging.level'),
|
|
||||||
2 => t('Warning', 'app.config.logging.level'),
|
|
||||||
3 => t('Information', 'app.config.logging.level'),
|
|
||||||
4 => t('Debug', 'app.config.logging.level')
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
$this->addElement(
|
|
||||||
'select',
|
|
||||||
'logging_type',
|
|
||||||
array(
|
array(
|
||||||
'required' => true,
|
'required' => true,
|
||||||
'autosubmit' => true,
|
'autosubmit' => true,
|
||||||
|
@ -50,13 +35,32 @@ class LoggingConfigForm extends Form
|
||||||
'description' => t('The type of logging to utilize.'),
|
'description' => t('The type of logging to utilize.'),
|
||||||
'multiOptions' => array(
|
'multiOptions' => array(
|
||||||
'syslog' => 'Syslog',
|
'syslog' => 'Syslog',
|
||||||
'file' => t('File', 'app.config.logging.type')
|
'file' => t('File', 'app.config.logging.type'),
|
||||||
|
'none' => t('None', 'app.config.logging.type')
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (false === isset($formData['logging_type']) || $formData['logging_type'] === 'syslog') {
|
if (! isset($formData['logging_log']) || $formData['logging_log'] !== 'none') {
|
||||||
$this->addElement(
|
$this->addElement(
|
||||||
|
'select',
|
||||||
|
'logging_level',
|
||||||
|
array(
|
||||||
|
'required' => true,
|
||||||
|
'label' => t('Logging Level'),
|
||||||
|
'description' => t('The maximum logging level to emit.'),
|
||||||
|
'multiOptions' => array(
|
||||||
|
Logger::$levels[Logger::ERROR] => t('Error', 'app.config.logging.level'),
|
||||||
|
Logger::$levels[Logger::WARNING] => t('Warning', 'app.config.logging.level'),
|
||||||
|
Logger::$levels[Logger::INFO] => t('Information', 'app.config.logging.level'),
|
||||||
|
Logger::$levels[Logger::DEBUG] => t('Debug', 'app.config.logging.level')
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($formData['logging_log']) && $formData['logging_log'] === 'syslog') {
|
||||||
|
$this->addElement(
|
||||||
'text',
|
'text',
|
||||||
'logging_application',
|
'logging_application',
|
||||||
array(
|
array(
|
||||||
|
@ -78,26 +82,30 @@ class LoggingConfigForm extends Form
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$this->addElement(
|
/*
|
||||||
'select',
|
* Note(el): Since we provide only one possible value for the syslog facility, I opt against exposing
|
||||||
'logging_facility',
|
* this configuration.
|
||||||
array(
|
*/
|
||||||
'required' => true,
|
// $this->addElement(
|
||||||
'label' => t('Facility'),
|
// 'select',
|
||||||
'description' => t('The Syslog facility to utilize.'),
|
// 'logging_facility',
|
||||||
'multiOptions' => array(
|
// array(
|
||||||
'LOG_USER' => 'LOG_USER'
|
// 'required' => true,
|
||||||
)
|
// 'label' => t('Facility'),
|
||||||
)
|
// 'description' => t('The syslog facility to utilize.'),
|
||||||
);
|
// 'multiOptions' => array(
|
||||||
} elseif ($formData['logging_type'] === 'file') {
|
// 'user' => 'LOG_USER'
|
||||||
|
// )
|
||||||
|
// )
|
||||||
|
// );
|
||||||
|
} elseif (isset($formData['logging_log']) && $formData['logging_log'] === 'file') {
|
||||||
$this->addElement(
|
$this->addElement(
|
||||||
'text',
|
'text',
|
||||||
'logging_target',
|
'logging_file',
|
||||||
array(
|
array(
|
||||||
'required' => true,
|
'required' => true,
|
||||||
'label' => t('Filepath'),
|
'label' => t('File path'),
|
||||||
'description' => t('The logfile to write messages to.'),
|
'description' => t('The full path to the log file to write messages to.'),
|
||||||
'value' => $this->getDefaultLogDir(),
|
'value' => $this->getDefaultLogDir(),
|
||||||
'validators' => array(new WritablePathValidator())
|
'validators' => array(new WritablePathValidator())
|
||||||
)
|
)
|
||||||
|
@ -108,9 +116,9 @@ class LoggingConfigForm extends Form
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the default logging directory for type "file"
|
* Return the default logging directory for type 'file'
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function getDefaultLogDir()
|
protected function getDefaultLogDir()
|
||||||
{
|
{
|
||||||
|
|
|
@ -40,13 +40,16 @@ class GeneralConfigForm extends ConfigForm
|
||||||
*/
|
*/
|
||||||
public function onSuccess(Request $request)
|
public function onSuccess(Request $request)
|
||||||
{
|
{
|
||||||
|
$sections = array();
|
||||||
foreach ($this->getValues() as $sectionAndPropertyName => $value) {
|
foreach ($this->getValues() as $sectionAndPropertyName => $value) {
|
||||||
list($section, $property) = explode('_', $sectionAndPropertyName);
|
list($section, $property) = explode('_', $sectionAndPropertyName);
|
||||||
if (isset($this->config->{$section})) {
|
if (! isset($sections[$section])) {
|
||||||
$this->config->{$section}->{$property} = $value;
|
$sections[$section] = array();
|
||||||
} else {
|
|
||||||
$this->config->{$section} = array($property => $value);
|
|
||||||
}
|
}
|
||||||
|
$sections[$section][$property] = $value;
|
||||||
|
}
|
||||||
|
foreach ($sections as $section => $config) {
|
||||||
|
$this->config->{$section} = $config;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->save()) {
|
if ($this->save()) {
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
<div class="controls">
|
||||||
|
<?= $this->tabs->showOnlyCloseButton() ?>
|
||||||
|
</div>
|
||||||
<h4><?= $this->translate('Create New Authentication Backend'); ?></h4>
|
<h4><?= $this->translate('Create New Authentication Backend'); ?></h4>
|
||||||
<p>
|
<p>
|
||||||
<?= $this->translate(
|
<?= $this->translate(
|
||||||
|
|
|
@ -1,2 +1,5 @@
|
||||||
|
<div class="controls">
|
||||||
|
<?= $this->tabs->showOnlyCloseButton() ?>
|
||||||
|
</div>
|
||||||
<h4><?= $this->translate('Edit Backend'); ?></h4>
|
<h4><?= $this->translate('Edit Backend'); ?></h4>
|
||||||
<?= $form; ?>
|
<?= $form; ?>
|
|
@ -1,2 +1,5 @@
|
||||||
|
<div class="controls">
|
||||||
|
<?= $this->tabs->showOnlyCloseButton() ?>
|
||||||
|
</div>
|
||||||
<h4><?= $this->translate('Remove Backend'); ?></h4>
|
<h4><?= $this->translate('Remove Backend'); ?></h4>
|
||||||
<?= $form; ?>
|
<?= $form; ?>
|
|
@ -1,3 +1,6 @@
|
||||||
|
<div class="controls">
|
||||||
|
<?= $this->tabs->showOnlyCloseButton() ?>
|
||||||
|
</div>
|
||||||
<h4><?= $this->translate('Create A New Resource'); ?></h4>
|
<h4><?= $this->translate('Create A New Resource'); ?></h4>
|
||||||
<p><?= $this->translate('Resources are entities that provide data to Icinga Web 2.'); ?></p>
|
<p><?= $this->translate('Resources are entities that provide data to Icinga Web 2.'); ?></p>
|
||||||
<?= $form; ?>
|
<?= $form; ?>
|
|
@ -1,2 +1,5 @@
|
||||||
|
<div class="controls">
|
||||||
|
<?= $this->tabs->showOnlyCloseButton() ?>
|
||||||
|
</div>
|
||||||
<h4><?= $this->translate('Edit Existing Resource'); ?></h4>
|
<h4><?= $this->translate('Edit Existing Resource'); ?></h4>
|
||||||
<?= $form; ?>
|
<?= $form; ?>
|
|
@ -1,2 +1,5 @@
|
||||||
|
<div class="controls">
|
||||||
|
<?= $this->tabs->showOnlyCloseButton() ?>
|
||||||
|
</div>
|
||||||
<h4><?= $this->translate('Remove Existing Resource'); ?></h4>
|
<h4><?= $this->translate('Remove Existing Resource'); ?></h4>
|
||||||
<?= $form; ?>
|
<?= $form; ?>
|
|
@ -4,10 +4,10 @@
|
||||||
|
|
||||||
namespace Icinga\Application;
|
namespace Icinga\Application;
|
||||||
|
|
||||||
|
use ErrorException;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Zend_Config;
|
use Zend_Config;
|
||||||
use Icinga\Application\Modules\Manager as ModuleManager;
|
use Icinga\Application\Modules\Manager as ModuleManager;
|
||||||
use Icinga\Application\Config;
|
|
||||||
use Icinga\Data\ResourceFactory;
|
use Icinga\Data\ResourceFactory;
|
||||||
use Icinga\Exception\ConfigurationError;
|
use Icinga\Exception\ConfigurationError;
|
||||||
use Icinga\Exception\NotReadableError;
|
use Icinga\Exception\NotReadableError;
|
||||||
|
@ -348,11 +348,7 @@ abstract class ApplicationBootstrap
|
||||||
Logger::create(
|
Logger::create(
|
||||||
new Zend_Config(
|
new Zend_Config(
|
||||||
array(
|
array(
|
||||||
'enable' => true,
|
'log' => 'syslog'
|
||||||
'level' => Logger::$ERROR,
|
|
||||||
'type' => 'syslog',
|
|
||||||
'facility' => 'LOG_USER',
|
|
||||||
'application' => 'icingaweb'
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -386,6 +382,17 @@ abstract class ApplicationBootstrap
|
||||||
error_reporting(E_ALL | E_STRICT);
|
error_reporting(E_ALL | E_STRICT);
|
||||||
ini_set('display_startup_errors', 1);
|
ini_set('display_startup_errors', 1);
|
||||||
ini_set('display_errors', 1);
|
ini_set('display_errors', 1);
|
||||||
|
set_error_handler(function ($errno, $errstr, $errfile, $errline) {
|
||||||
|
if (error_reporting() === 0) {
|
||||||
|
// Error was suppressed with the @-operator
|
||||||
|
return false; // Continue with the normal error handler
|
||||||
|
}
|
||||||
|
switch($errno) {
|
||||||
|
case E_STRICT:
|
||||||
|
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
|
||||||
|
}
|
||||||
|
return false; // Continue with the normal error handler
|
||||||
|
});
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,10 +51,9 @@ class Cli extends ApplicationBootstrap
|
||||||
Logger::create(
|
Logger::create(
|
||||||
new Zend_Config(
|
new Zend_Config(
|
||||||
array(
|
array(
|
||||||
'enable' => true,
|
'level' => Logger::INFO,
|
||||||
'level' => Logger::$INFO,
|
'log' => 'file',
|
||||||
'type' => 'file',
|
'file' => 'php://stderr'
|
||||||
'target' => 'php://stderr'
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
|
@ -6,61 +6,110 @@ namespace Icinga\Logger;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Zend_Config;
|
use Zend_Config;
|
||||||
use LogicException;
|
|
||||||
use Icinga\Exception\ConfigurationError;
|
use Icinga\Exception\ConfigurationError;
|
||||||
|
use Icinga\Logger\Writer\FileWriter;
|
||||||
|
use Icinga\Logger\Writer\SyslogWriter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Singleton logger
|
* Logger
|
||||||
*/
|
*/
|
||||||
class Logger
|
class Logger
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Debug message
|
||||||
|
*/
|
||||||
|
const DEBUG = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Informational message
|
||||||
|
*/
|
||||||
|
const INFO = 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Warning message
|
||||||
|
*/
|
||||||
|
const WARNING = 4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error message
|
||||||
|
*/
|
||||||
|
const ERROR = 8;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log levels
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public static $levels = array(
|
||||||
|
Logger::DEBUG => 'DEBUG',
|
||||||
|
Logger::INFO => 'INFO',
|
||||||
|
Logger::WARNING => 'WARNING',
|
||||||
|
Logger::ERROR => 'ERROR'
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This logger's instance
|
* This logger's instance
|
||||||
*
|
*
|
||||||
* @var Logger
|
* @var static
|
||||||
*/
|
*/
|
||||||
protected static $instance;
|
protected static $instance;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The log writer to use
|
* Log writer
|
||||||
*
|
*
|
||||||
* @var \Icinga\Logger\LogWriter
|
* @var \Icinga\Logger\LogWriter
|
||||||
*/
|
*/
|
||||||
protected $writer;
|
protected $writer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The configured type
|
* Maximum level to emit
|
||||||
*
|
|
||||||
* @string Type (syslog, file)
|
|
||||||
*/
|
|
||||||
protected $type = 'none';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The maximum severity to emit
|
|
||||||
*
|
*
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
protected $verbosity;
|
protected $level;
|
||||||
|
|
||||||
/**
|
|
||||||
* The supported severities
|
|
||||||
*/
|
|
||||||
public static $NONE = 0;
|
|
||||||
public static $ERROR = 1;
|
|
||||||
public static $WARNING = 2;
|
|
||||||
public static $INFO = 3;
|
|
||||||
public static $DEBUG = 4;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new logger object
|
* Create a new logger object
|
||||||
*
|
*
|
||||||
* @param Zend_Config $config
|
* @param Zend_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(Zend_Config $config)
|
||||||
{
|
{
|
||||||
$this->verbosity = $config->level;
|
if ($config->log === null) {
|
||||||
|
throw new ConfigurationError('Required logging configuration directive \'log\' missing');
|
||||||
|
}
|
||||||
|
|
||||||
if ($config->enable) {
|
if (($level = $config->level) !== null) {
|
||||||
|
if (is_numeric($level)) {
|
||||||
|
if (! isset(static::$levels[(int) $level])) {
|
||||||
|
throw new ConfigurationError(
|
||||||
|
'Can\'t set logging level %d. Logging level is not defined. Use one of %s or one of the'
|
||||||
|
. ' Logger\'s constants.',
|
||||||
|
$level,
|
||||||
|
implode(', ', array_keys(static::$levels))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$this->level = static::$levels[(int) $level];
|
||||||
|
} else {
|
||||||
|
$level = strtoupper($level);
|
||||||
|
$levels = array_flip(static::$levels);
|
||||||
|
if (! isset($levels[$level])) {
|
||||||
|
throw new ConfigurationError(
|
||||||
|
'Can\'t set logging level "%s". Logging level is not defined. Use one of %s.',
|
||||||
|
$level,
|
||||||
|
implode(', ', array_keys($levels))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$this->level = $levels[$level];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->level = static::ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strtolower($config->get('log', 'syslog')) !== 'none') {
|
||||||
$this->writer = $this->createWriter($config);
|
$this->writer = $this->createWriter($config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,14 +118,17 @@ class Logger
|
||||||
* Create a new logger object
|
* Create a new logger object
|
||||||
*
|
*
|
||||||
* @param Zend_Config $config
|
* @param Zend_Config $config
|
||||||
|
*
|
||||||
|
* @return static
|
||||||
*/
|
*/
|
||||||
public static function create(Zend_Config $config)
|
public static function create(Zend_Config $config)
|
||||||
{
|
{
|
||||||
static::$instance = new static($config);
|
static::$instance = new static($config);
|
||||||
|
return static::$instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a log writer
|
* Create a log writer
|
||||||
*
|
*
|
||||||
* @param Zend_Config $config The configuration to initialize the writer with
|
* @param Zend_Config $config The configuration to initialize the writer with
|
||||||
*
|
*
|
||||||
|
@ -85,34 +137,26 @@ class Logger
|
||||||
*/
|
*/
|
||||||
protected function createWriter(Zend_Config $config)
|
protected function createWriter(Zend_Config $config)
|
||||||
{
|
{
|
||||||
$class = 'Icinga\\Logger\\Writer\\' . ucfirst(strtolower($config->type)) . 'Writer';
|
$class = 'Icinga\\Logger\\Writer\\' . ucfirst(strtolower($config->log)) . 'Writer';
|
||||||
if (!class_exists($class)) {
|
if (! class_exists($class)) {
|
||||||
throw new ConfigurationError(
|
throw new ConfigurationError(
|
||||||
'Cannot find log writer of type "%s"',
|
'Cannot find log writer of type "%s"',
|
||||||
$config->type
|
$config->log
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$this->type = $config->type;
|
|
||||||
|
|
||||||
return new $class($config);
|
return new $class($config);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write a message to the log
|
* Log a message
|
||||||
*
|
*
|
||||||
* @param string $message The message to write
|
* @param int $level The logging level
|
||||||
* @param int $severity The severity to use
|
* @param string $message The log message
|
||||||
*
|
|
||||||
* @throws LogicException In case $severity equals self::$NONE
|
|
||||||
*/
|
*/
|
||||||
public function log($message, $severity)
|
public function log($level, $message)
|
||||||
{
|
{
|
||||||
if ($severity === static::$NONE) {
|
if ($this->writer !== null && $this->level >= $level) {
|
||||||
throw new LogicException("`None' (0) is not a valid severity to log messages");
|
$this->writer->log($level, $message);
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->writer !== null && $this->verbosity >= $severity) {
|
|
||||||
$this->writer->log($severity, $message);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,7 +214,7 @@ class Logger
|
||||||
public static function error()
|
public static function error()
|
||||||
{
|
{
|
||||||
if (static::$instance !== null && func_num_args() > 0) {
|
if (static::$instance !== null && func_num_args() > 0) {
|
||||||
static::$instance->log(static::formatMessage(func_get_args()), static::$ERROR);
|
static::$instance->log(static::ERROR, static::formatMessage(func_get_args()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,7 +226,7 @@ class Logger
|
||||||
public static function warning()
|
public static function warning()
|
||||||
{
|
{
|
||||||
if (static::$instance !== null && func_num_args() > 0) {
|
if (static::$instance !== null && func_num_args() > 0) {
|
||||||
static::$instance->log(static::formatMessage(func_get_args()), static::$WARNING);
|
static::$instance->log(static::WARNING, static::formatMessage(func_get_args()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,7 +238,7 @@ class Logger
|
||||||
public static function info()
|
public static function info()
|
||||||
{
|
{
|
||||||
if (static::$instance !== null && func_num_args() > 0) {
|
if (static::$instance !== null && func_num_args() > 0) {
|
||||||
static::$instance->log(static::formatMessage(func_get_args()), static::$INFO);
|
static::$instance->log(static::INFO, static::formatMessage(func_get_args()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,7 +250,7 @@ class Logger
|
||||||
public static function debug()
|
public static function debug()
|
||||||
{
|
{
|
||||||
if (static::$instance !== null && func_num_args() > 0) {
|
if (static::$instance !== null && func_num_args() > 0) {
|
||||||
static::$instance->log(static::formatMessage(func_get_args()), static::$DEBUG);
|
static::$instance->log(static::DEBUG, static::formatMessage(func_get_args()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,20 +264,30 @@ class Logger
|
||||||
return $this->writer;
|
return $this->writer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is the logger writing to Syslog?
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
public static function writesToSyslog()
|
public static function writesToSyslog()
|
||||||
{
|
{
|
||||||
return static::$instance && static::$instance->type === 'syslog';
|
return static::$instance && static::$instance instanceof SyslogWriter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is the logger writing to a file?
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
public static function writesToFile()
|
public static function writesToFile()
|
||||||
{
|
{
|
||||||
return static::$instance && static::$instance->type === 'file';
|
return static::$instance && static::$instance instanceof FileWriter;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get this' instance
|
* Get this' instance
|
||||||
*
|
*
|
||||||
* @return Logger
|
* @return static
|
||||||
*/
|
*/
|
||||||
public static function getInstance()
|
public static function getInstance()
|
||||||
{
|
{
|
||||||
|
|
|
@ -5,38 +5,43 @@
|
||||||
namespace Icinga\Logger\Writer;
|
namespace Icinga\Logger\Writer;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Icinga\Exception\IcingaException;
|
|
||||||
use Zend_Config;
|
use Zend_Config;
|
||||||
use Icinga\Util\File;
|
use Icinga\Exception\ConfigurationError;
|
||||||
use Icinga\Logger\Logger;
|
use Icinga\Logger\Logger;
|
||||||
use Icinga\Logger\LogWriter;
|
use Icinga\Logger\LogWriter;
|
||||||
use Icinga\Exception\ConfigurationError;
|
use Icinga\Util\File;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to write log messages to a file
|
* Log to a file
|
||||||
*/
|
*/
|
||||||
class FileWriter extends LogWriter
|
class FileWriter extends LogWriter
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The path to the file
|
* Path to the file
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $path;
|
protected $file;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new log writer initialized with the given configuration
|
* Create a new file log writer
|
||||||
*
|
*
|
||||||
* @throws ConfigurationError In case the log path does not exist
|
* @param Zend_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(Zend_Config $config)
|
||||||
{
|
{
|
||||||
$this->path = $config->target;
|
if ($config->file === null) {
|
||||||
|
throw new ConfigurationError('Required logging configuration directive \'file\' missing');
|
||||||
|
}
|
||||||
|
$this->file = $config->file;
|
||||||
|
|
||||||
if (substr($this->path, 0, 6) !== 'php://' && false === file_exists(dirname($this->path))) {
|
if (substr($this->file, 0, 6) !== 'php://' && ! file_exists(dirname($this->file))) {
|
||||||
throw new ConfigurationError(
|
throw new ConfigurationError(
|
||||||
'Log path "%s" does not exist',
|
'Log path "%s" does not exist',
|
||||||
dirname($this->path)
|
dirname($this->file)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,70 +50,32 @@ class FileWriter extends LogWriter
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw new ConfigurationError(
|
throw new ConfigurationError(
|
||||||
'Cannot write to log file "%s" (%s)',
|
'Cannot write to log file "%s" (%s)',
|
||||||
$this->path,
|
$this->file,
|
||||||
$e->getMessage()
|
$e->getMessage()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log a message with the given severity
|
* Log a message
|
||||||
*
|
*
|
||||||
* @param int $severity The severity to use
|
* @param int $level The logging level
|
||||||
* @param string $message The message to log
|
* @param string $message The log message
|
||||||
*/
|
*/
|
||||||
public function log($severity, $message)
|
public function log($level, $message)
|
||||||
{
|
{
|
||||||
$this->write(date('c') . ' ' . $this->getSeverityString($severity) . ' ' . $message . PHP_EOL);
|
$this->write(date('c') . ' - ' . Logger::$levels[$level] . ' - ' . $message . PHP_EOL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a string representation for the given severity
|
* Write a message to the log
|
||||||
*
|
*
|
||||||
* @param string $severity The severity to use
|
* @param string $message
|
||||||
*
|
|
||||||
* @return string The string representation of the severity
|
|
||||||
*
|
|
||||||
* @throws IcingaException In case the given severity is unknown
|
|
||||||
*/
|
*/
|
||||||
protected function getSeverityString($severity)
|
protected function write($message)
|
||||||
{
|
{
|
||||||
switch ($severity) {
|
$file = new File($this->file, 'a');
|
||||||
case Logger::$ERROR:
|
$file->fwrite($message);
|
||||||
return '- ERROR -';
|
|
||||||
case Logger::$WARNING:
|
|
||||||
return '- WARNING -';
|
|
||||||
case Logger::$INFO:
|
|
||||||
return '- INFO -';
|
|
||||||
case Logger::$DEBUG:
|
|
||||||
return '- DEBUG -';
|
|
||||||
default:
|
|
||||||
throw new IcingaException(
|
|
||||||
'Unknown severity "%s"',
|
|
||||||
$severity
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Write a message to the path
|
|
||||||
*
|
|
||||||
* @param string $text The message to write
|
|
||||||
*
|
|
||||||
* @throws Exception In case write acess to the path failed
|
|
||||||
*/
|
|
||||||
protected function write($text)
|
|
||||||
{
|
|
||||||
$file = new File($this->path, 'a');
|
|
||||||
$file->fwrite($text);
|
|
||||||
$file->fflush();
|
$file->fflush();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getPath()
|
|
||||||
{
|
|
||||||
return $this->path;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,27 +4,24 @@
|
||||||
|
|
||||||
namespace Icinga\Logger\Writer;
|
namespace Icinga\Logger\Writer;
|
||||||
|
|
||||||
use Exception;
|
|
||||||
use Zend_Config;
|
use Zend_Config;
|
||||||
use Icinga\Logger\Logger;
|
use Icinga\Logger\Logger;
|
||||||
use Icinga\Logger\LogWriter;
|
use Icinga\Logger\LogWriter;
|
||||||
use Icinga\Exception\ConfigurationError;
|
|
||||||
use Icinga\Exception\IcingaException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to write messages to syslog
|
* Log to the syslog service
|
||||||
*/
|
*/
|
||||||
class SyslogWriter extends LogWriter
|
class SyslogWriter extends LogWriter
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The facility where to write messages to
|
* Syslog facility
|
||||||
*
|
*
|
||||||
* @var string
|
* @var int
|
||||||
*/
|
*/
|
||||||
protected $facility;
|
protected $facility;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The prefix to prepend to each message
|
* Prefix to prepend to each message
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
|
@ -35,79 +32,42 @@ class SyslogWriter extends LogWriter
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $facilities = array(
|
public static $facilities = array(
|
||||||
'LOG_USER' => LOG_USER
|
'user' => LOG_USER
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new log writer initialized with the given configuration
|
* Log level to syslog severity map
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public static $severityMap = array(
|
||||||
|
Logger::ERROR => LOG_ERR,
|
||||||
|
Logger::WARNING => LOG_WARNING,
|
||||||
|
Logger::INFO => LOG_INFO,
|
||||||
|
Logger::DEBUG => LOG_DEBUG
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new syslog log writer
|
||||||
|
*
|
||||||
|
* @param Zend_Config $config
|
||||||
*/
|
*/
|
||||||
public function __construct(Zend_Config $config)
|
public function __construct(Zend_Config $config)
|
||||||
{
|
{
|
||||||
if (!array_key_exists($config->facility, $this->facilities)) {
|
$this->ident = $config->get('application', 'icingaweb');
|
||||||
throw new ConfigurationError(
|
$this->facility = static::$facilities['user'];
|
||||||
'Cannot create syslog writer with unknown facility "%s"',
|
|
||||||
$config->facility
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->ident = $config->application;
|
|
||||||
$this->facility = $this->facilities[$config->facility];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log a message with the given severity
|
* Log a message
|
||||||
*
|
*
|
||||||
* @param int $severity The severity to use
|
* @param int $level The logging level
|
||||||
* @param string $message The message to log
|
* @param string $message The log message
|
||||||
*
|
|
||||||
* @throws Exception In case the given severity cannot be mapped to a valid syslog priority
|
|
||||||
*/
|
*/
|
||||||
public function log($severity, $message)
|
public function log($level, $message)
|
||||||
{
|
{
|
||||||
$priorities = array(
|
openlog($this->ident, LOG_PID, $this->facility);
|
||||||
Logger::$ERROR => LOG_ERR,
|
syslog(static::$severityMap[$level], $message);
|
||||||
Logger::$WARNING => LOG_WARNING,
|
|
||||||
Logger::$INFO => LOG_INFO,
|
|
||||||
Logger::$DEBUG => LOG_DEBUG
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!array_key_exists($severity, $priorities)) {
|
|
||||||
throw new IcingaException(
|
|
||||||
'Severity "%s" cannot be mapped to a valid syslog priority',
|
|
||||||
$severity
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->open();
|
|
||||||
$this->write($priorities[$severity], $message);
|
|
||||||
$this->close();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Open a new syslog connection
|
|
||||||
*/
|
|
||||||
protected function open()
|
|
||||||
{
|
|
||||||
openlog($this->ident, 0, $this->facility);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Write a message to the syslog connection
|
|
||||||
*
|
|
||||||
* @param int $priority The priority to use
|
|
||||||
* @param string $message The message to write
|
|
||||||
*/
|
|
||||||
protected function write($priority, $message)
|
|
||||||
{
|
|
||||||
syslog($priority, $message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Close the syslog connection
|
|
||||||
*/
|
|
||||||
protected function close()
|
|
||||||
{
|
|
||||||
closelog();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,7 +131,7 @@ class File extends SplFileObject
|
||||||
set_error_handler(
|
set_error_handler(
|
||||||
function ($errno, $errstr, $errfile, $errline) {
|
function ($errno, $errstr, $errfile, $errline) {
|
||||||
restore_error_handler();
|
restore_error_handler();
|
||||||
throw new ErrorException($errno, $errstr, $errfile, $errline);
|
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
|
||||||
},
|
},
|
||||||
E_WARNING
|
E_WARNING
|
||||||
);
|
);
|
||||||
|
|
|
@ -74,6 +74,13 @@ EOT;
|
||||||
*/
|
*/
|
||||||
private $dropdownTabs = array();
|
private $dropdownTabs = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether only the close-button should by rendered for this tab
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
private $closeButtonOnly = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the tabs should contain a close-button
|
* Whether the tabs should contain a close-button
|
||||||
*
|
*
|
||||||
|
@ -275,14 +282,19 @@ EOT;
|
||||||
*/
|
*/
|
||||||
public function render()
|
public function render()
|
||||||
{
|
{
|
||||||
if (empty($this->tabs)) {
|
if (empty($this->tabs) || true === $this->closeButtonOnly) {
|
||||||
return '';
|
$tabs = '';
|
||||||
|
$drop = '';
|
||||||
|
} else {
|
||||||
|
$tabs = $this->renderTabs();
|
||||||
|
$drop = $this->renderDropdownTabs();
|
||||||
}
|
}
|
||||||
|
$close = $this->closeTab ? $this->renderCloseTab() : '';
|
||||||
|
|
||||||
$html = $this->baseTpl;
|
$html = $this->baseTpl;
|
||||||
$html = str_replace('{TABS}', $this->renderTabs(), $html);
|
$html = str_replace('{TABS}', $tabs, $html);
|
||||||
$html = str_replace('{DROPDOWN}', $this->renderDropdownTabs(), $html);
|
$html = str_replace('{DROPDOWN}', $drop, $html);
|
||||||
$html = str_replace('{CLOSE}', $this->closeTab ? $this->renderCloseTab() : '', $html);
|
$html = str_replace('{CLOSE}', $close, $html);
|
||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -318,6 +330,18 @@ EOT;
|
||||||
return $this->tabs;
|
return $this->tabs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to hide all elements except of the close button
|
||||||
|
*
|
||||||
|
* @param bool $value
|
||||||
|
* @return Tabs fluent interface
|
||||||
|
*/
|
||||||
|
public function showOnlyCloseButton($value = true)
|
||||||
|
{
|
||||||
|
$this->closeButtonOnly = $value;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply a Tabextension on this tabs object
|
* Apply a Tabextension on this tabs object
|
||||||
*
|
*
|
||||||
|
|
|
@ -259,7 +259,11 @@ class Monitoring_AlertsummaryController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
$out = new stdClass();
|
$out = new stdClass();
|
||||||
$out->avg = sprintf('%.2f', array_sum($slots) / count($slots));
|
if (! empty($slots)) {
|
||||||
|
$out->avg = sprintf('%.2f', array_sum($slots) / count($slots));
|
||||||
|
} else {
|
||||||
|
$out->avg = '0.0';
|
||||||
|
}
|
||||||
$out->last = array_shift($slots);
|
$out->last = array_shift($slots);
|
||||||
|
|
||||||
return $out;
|
return $out;
|
||||||
|
@ -275,7 +279,7 @@ class Monitoring_AlertsummaryController extends Controller
|
||||||
$interval = $this->getInterval();
|
$interval = $this->getInterval();
|
||||||
|
|
||||||
$query = $this->backend->select()->from(
|
$query = $this->backend->select()->from(
|
||||||
'eventhistory',
|
'EventHistory',
|
||||||
array(
|
array(
|
||||||
'host_name',
|
'host_name',
|
||||||
'service_description',
|
'service_description',
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
<div class="controls">
|
||||||
|
<?= $this->tabs->showOnlyCloseButton() ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<h1><?= $title ?></h1>
|
<h1><?= $title ?></h1>
|
||||||
<table class="objectlist">
|
<table class="objectlist">
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
<div class="controls">
|
||||||
|
<?= $this->tabs->showOnlyCloseButton() ?>
|
||||||
|
</div>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<h1><?= $title ?></h1>
|
<h1><?= $title ?></h1>
|
||||||
<?php if ((bool) $programStatus->notifications_enabled === false): ?>
|
<?php if ((bool) $programStatus->notifications_enabled === false): ?>
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
<?php $contactHelper = $this->getHelper('ContactFlags') ?>
|
<?php $contactHelper = $this->getHelper('ContactFlags') ?>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
|
<?= $this->tabs ?>
|
||||||
<h1><?= $this->translate('Contact details') ?></h1>
|
<h1><?= $this->translate('Contact details') ?></h1>
|
||||||
<div class="circular" style="margin-top: 1em; margin-left: 2em; width: 120px; height: 120px; float: left; background-image: url('<?=
|
<div class="circular" style="margin-top: 1em; margin-left: 2em; width: 120px; height: 120px; float: left; background-image: url('<?=
|
||||||
$this->href('static/gravatar', array('email' => $contact->contact_email))
|
$this->href('static/gravatar', array('email' => $contact->contact_email))
|
||||||
|
|
|
@ -8,6 +8,7 @@ $firstRow = !$beingExtended;
|
||||||
?>
|
?>
|
||||||
<?php if (!$beingExtended): ?>
|
<?php if (!$beingExtended): ?>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
|
<?= $this->tabs ?>
|
||||||
<div style="margin: 1em;" class="dontprint">
|
<div style="margin: 1em;" class="dontprint">
|
||||||
<?= $intervalBox; ?>
|
<?= $intervalBox; ?>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -16,6 +16,7 @@ abstract class IcingaCommand
|
||||||
*/
|
*/
|
||||||
public function getName()
|
public function getName()
|
||||||
{
|
{
|
||||||
return substr_replace(end(explode('\\', get_called_class())), '', -7); // Remove 'Command' Suffix
|
$nsParts = explode('\\', get_called_class());
|
||||||
|
return substr_replace(end($nsParts), '', -7); // Remove 'Command' Suffix
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -723,9 +723,6 @@
|
||||||
}
|
}
|
||||||
this.icinga.ui.assignUniqueContainerIds();
|
this.icinga.ui.assignUniqueContainerIds();
|
||||||
|
|
||||||
if (scrollPos !== false) {
|
|
||||||
$container.scrollTop(scrollPos);
|
|
||||||
}
|
|
||||||
if (origFocus) {
|
if (origFocus) {
|
||||||
$(origFocus).focus();
|
$(origFocus).focus();
|
||||||
}
|
}
|
||||||
|
@ -733,6 +730,9 @@
|
||||||
// TODO: this.icinga.events.refreshContainer(container);
|
// TODO: this.icinga.events.refreshContainer(container);
|
||||||
$container.trigger('rendered');
|
$container.trigger('rendered');
|
||||||
|
|
||||||
|
if (scrollPos !== false) {
|
||||||
|
$container.scrollTop(scrollPos);
|
||||||
|
}
|
||||||
var icinga = this.icinga;
|
var icinga = this.icinga;
|
||||||
//icinga.events.applyHandlers($container);
|
//icinga.events.applyHandlers($container);
|
||||||
icinga.ui.initializeControls($container);
|
icinga.ui.initializeControls($container);
|
||||||
|
|
|
@ -9,7 +9,7 @@ use Icinga\Logger\Logger;
|
||||||
use Icinga\Test\BaseTestCase;
|
use Icinga\Test\BaseTestCase;
|
||||||
use Icinga\Logger\Writer\FileWriter;
|
use Icinga\Logger\Writer\FileWriter;
|
||||||
|
|
||||||
class LoggerTest extends BaseTestCase
|
class StreamWriterTest extends BaseTestCase
|
||||||
{
|
{
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
|
@ -27,7 +27,7 @@ class LoggerTest extends BaseTestCase
|
||||||
|
|
||||||
public function testWhetherStreamWriterCreatesMissingFiles()
|
public function testWhetherStreamWriterCreatesMissingFiles()
|
||||||
{
|
{
|
||||||
new FileWriter(new Zend_Config(array('target' => $this->target)));
|
new FileWriter(new Zend_Config(array('file' => $this->target)));
|
||||||
$this->assertFileExists($this->target, 'StreamWriter does not create missing files on initialization');
|
$this->assertFileExists($this->target, 'StreamWriter does not create missing files on initialization');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,8 +36,8 @@ class LoggerTest extends BaseTestCase
|
||||||
*/
|
*/
|
||||||
public function testWhetherStreamWriterWritesMessages()
|
public function testWhetherStreamWriterWritesMessages()
|
||||||
{
|
{
|
||||||
$writer = new FileWriter(new Zend_Config(array('target' => $this->target)));
|
$writer = new FileWriter(new Zend_Config(array('file' => $this->target)));
|
||||||
$writer->log(Logger::$ERROR, 'This is a test error');
|
$writer->log(Logger::ERROR, 'This is a test error');
|
||||||
$log = file_get_contents($this->target);
|
$log = file_get_contents($this->target);
|
||||||
$this->assertContains('This is a test error', $log, 'StreamWriter does not write log messages');
|
$this->assertContains('This is a test error', $log, 'StreamWriter does not write log messages');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue