diff --git a/application/forms/Config/General/LoggingConfigForm.php b/application/forms/Config/General/LoggingConfigForm.php index 35cd37a89..cf2228f7c 100644 --- a/application/forms/Config/General/LoggingConfigForm.php +++ b/application/forms/Config/General/LoggingConfigForm.php @@ -4,6 +4,7 @@ namespace Icinga\Forms\Config\General; use Icinga\Application\Logger; +use Icinga\Application\Platform; use Icinga\Web\Form; /** @@ -90,22 +91,50 @@ class LoggingConfigForm extends Form ) ) ); - /* - * Note(el): Since we provide only one possible value for the syslog facility, I opt against exposing - * this configuration. - */ -// $this->addElement( -// 'select', -// 'logging_facility', -// array( -// 'required' => true, -// 'label' => $this->translate('Facility'), -// 'description' => $this->translate('The syslog facility to utilize.'), -// 'multiOptions' => array( -// 'user' => 'LOG_USER' -// ) -// ) -// ); + + if (Platform::isWindows()) { + /* @see https://secure.php.net/manual/en/function.openlog.php */ + $this->addElement( + 'hidden', + 'logging_facility', + array( + 'value' => 'user', + 'disabled' => true + ) + ); + } else { + $this->addElement( + 'select', + 'logging_facility', + array( + 'required' => true, + 'label' => $this->translate('Facility'), + 'description' => $this->translate('The syslog facility to utilize.'), + 'value' => 'user', + 'multiOptions' => array( + 'auth' => 'LOG_AUTH', + 'authpriv' => 'LOG_AUTHPRIV', + 'cron' => 'LOG_CRON', + 'daemon' => 'LOG_DAEMON', + 'kern' => 'LOG_KERN', + 'local0' => 'LOG_LOCAL0', + 'local1' => 'LOG_LOCAL1', + 'local2' => 'LOG_LOCAL2', + 'local3' => 'LOG_LOCAL3', + 'local4' => 'LOG_LOCAL4', + 'local5' => 'LOG_LOCAL5', + 'local6' => 'LOG_LOCAL6', + 'local7' => 'LOG_LOCAL7', + 'lpr' => 'LOG_LPR', + 'mail' => 'LOG_MAIL', + 'news' => 'LOG_NEWS', + 'syslog' => 'LOG_SYSLOG', + 'user' => 'LOG_USER', + 'uucp' => 'LOG_UUCP' + ) + ) + ); + } } elseif (isset($formData['logging_log']) && $formData['logging_log'] === 'file') { $this->addElement( 'text', diff --git a/library/Icinga/Application/Logger/Writer/SyslogWriter.php b/library/Icinga/Application/Logger/Writer/SyslogWriter.php index b1387078c..f26a07412 100644 --- a/library/Icinga/Application/Logger/Writer/SyslogWriter.php +++ b/library/Icinga/Application/Logger/Writer/SyslogWriter.php @@ -6,6 +6,7 @@ namespace Icinga\Application\Logger\Writer; use Icinga\Data\ConfigObject; use Icinga\Application\Logger; use Icinga\Application\Logger\LogWriter; +use Icinga\Exception\ConfigurationError; /** * Log to the syslog service @@ -32,7 +33,25 @@ class SyslogWriter extends LogWriter * @var array */ public static $facilities = array( - 'user' => LOG_USER + 'auth' => LOG_AUTH, + 'authpriv' => LOG_AUTHPRIV, + 'cron' => LOG_CRON, + 'daemon' => LOG_DAEMON, + 'kern' => LOG_KERN, + 'local0' => LOG_LOCAL0, + 'local1' => LOG_LOCAL1, + 'local2' => LOG_LOCAL2, + 'local3' => LOG_LOCAL3, + 'local4' => LOG_LOCAL4, + 'local5' => LOG_LOCAL5, + 'local6' => LOG_LOCAL6, + 'local7' => LOG_LOCAL7, + 'lpr' => LOG_LPR, + 'mail' => LOG_MAIL, + 'news' => LOG_NEWS, + 'syslog' => LOG_SYSLOG, + 'user' => LOG_USER, + 'uucp' => LOG_UUCP ); /** @@ -55,7 +74,16 @@ class SyslogWriter extends LogWriter public function __construct(ConfigObject $config) { $this->ident = $config->get('application', 'icingaweb2'); - $this->facility = static::$facilities['user']; + + $configuredFacility = $config->get('facility', 'user'); + if (! isset(static::$facilities[$configuredFacility])) { + throw new ConfigurationError( + 'Invalid logging facility: "%s" (expected one of: %s)', + $configuredFacility, + implode(', ', array_keys(static::$facilities)) + ); + } + $this->facility = static::$facilities[$configuredFacility]; } /**