[icinga-checkins] icinga.org: icingaweb2/master: Allow to configure the Syslog facility

git at icinga.org git at icinga.org
Mon Oct 24 11:58:54 CEST 2016


Module: icingaweb2
Branch: master
Commit: 52e6293b9602ccc1f45cf090cd4d9144b43416ac
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=52e6293b9602ccc1f45cf090cd4d9144b43416ac

Author: Alexander A. Klimov <alexander.klimov at icinga.com>
Date:   Fri Oct 21 17:09:22 2016 +0200

Allow to configure the Syslog facility

refs #11214

---

 .../forms/Config/General/LoggingConfigForm.php     |   61 +++++++++++++++-----
 .../Application/Logger/Writer/SyslogWriter.php     |   32 +++++++++-
 2 files changed, 75 insertions(+), 18 deletions(-)

diff --git a/application/forms/Config/General/LoggingConfigForm.php b/application/forms/Config/General/LoggingConfigForm.php
index 35cd37a..cf2228f 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 b138707..f26a074 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];
     }
 
     /**



More information about the icinga-checkins mailing list