The following sections describe some methods that can be useful to simplify the management of large-scale syslog-ng installations.
The syslog-ng application supports including external files in its configuration file, so parts of its configuration can be managed separately. To include the contents of a file in the syslog-ng configuration, use the following syntax:
@include "<filename>"
This imports the entire file into the configuration of syslog-ng OSE, at the location of the include statement. The <filename> can be one of the following:
A filename, optionally with full path. The filename (not the path) can include UNIX-style wildcard characters (*, ?). When using wildcard characters, syslog-ng OSE will include every matching file. For details on using wildcard characters, see Options of regular expressions.
A directory. When including a directory, syslog-ng OSE will try to include every file from the directory, except files beginning with a ~ (tilde) or a . (dot) character. Including a directory is not recursive. The files are included in alphabetic order, first files beginning with uppercase characters, then files beginning with lowercase characters. For example, if the directory contains the a.conf, B. conf, c.conf, D.conf files, they will be included in the following order: B.conf, D. conf, a.conf, c.conf.
When including configuration files, consider the following points:
The default path where syslog-ng OSE looks for the file depends on where syslog-ng OSE is installed. The syslog-ng --version command displays this path as Include-Path.
Defining an object twice is not allowed, unless you use the @define allow-config-dups 1 definition in the configuration file. If an object is defined twice (for example, the original syslog-ng configuration file and the file imported into this configuration file both define the same option, source, or other object), then the object that is defined later in the configuration file will be effective. For example, if you set a global option at the beginning of the configuration file, and later include a file that defines the same option with a different value, then the option defined in the imported file will be used.
Files can be embedded into each other: the included files can contain include statements as well, up to a maximum depth of 15 levels.
You cannot include complete configuration files into each other, only configuration snippets can be included. This means that the included file cannot have a @version statement.
Include statements can only be used at top level of the configuration file. For example, the following is correct:
@version: 3.25 @include "example.conf"
But the following is not:
source s_example { @include "example.conf" };
|
Caution:
The syslog-ng application will not start if it cannot find a file that is to be included in its configuration. Always double-check the filenames, paths, and access rights when including configuration files, and use the --syntax-only command-line option to check your configuration. |
The syslog-ng OSE application can automatically execute scripts when it is started, and can include the output of such script in the configuration file. To create and use a script that generates a part of the syslog-ng OSE configuration file (actually, a configuration block), complete the following steps. The steps include examples for collecting Apache access log files (access.log) from subdirectories, but you can create any script that creates a valid syslog-ng OSE configuration snippet.
Navigate to the directory where you have installed syslog-ng OSE (for example, /opt/syslog-ng/share/include/scl/), and create a new directory, for example, apache-access-logs. The name of the directory will be used in the syslog-ng OSE configuration file as well, so use a descriptive name.
Create a file called plugin.conf in this new directory.
Edit the plugin.conf file and add the following line:
@module confgen context(source) name(<directory-name>) exec("`scl-root`/<directory-name>/<my-script>")
Replace <directory-name> with the name of the directory (for example, apache-access-logs), and <my-script> with the filename of your script (for example, apache-access-logs.sh). You can reference the script in your syslog-ng OSE configuration file as a configuration block using the value name option.
The context option determines the type of the configuration snippet that the script generates, and must be one of the following: destination, filter, log, parser, rewrite, root, source. The root blocks can be used in the "root" context of the configuration file, that is, outside any other statements. In the example, context(source) means that the output of the script will be used within a source statement.
You can pass parameters to the script. In the script these parameters are available as environment variables, and have the confgen_ prefix. For example, passing the --myparameter parameter becomes available in the script as the confgen_myparameter environment variable.
Write a script that generates the output you need, and formats it to a configuration snippet that syslog-ng OSE can use. The filename of the script must match with the filename used in plugin.conf, for example, apache-access-logs.sh.
The following example checks the /var/log/apache2/ directory and its subdirectories, and creates a source driver for every directory that contains an access.log file.
#!/bin/bash for i in `find /var/log/apache2/ -type d`; do echo "file(\"$i/access.log\" flags(no-parse) program-override(\"apache2\"));"; done;
The script generates an output similar to this one, where service* is the actual name of a subdirectory:
file("/var/log/apache2/service1/access.log" flags(no-parse) program-override("apache2")); file("/var/log/apache2/service2/access.log" flags(no-parse) program-override("apache2"));
Include the plugin.conf file in the syslog-ng.conf file — or a file already included into syslog-ng.conf. Version
Add the block you defined in the plugin.conf file to your syslog-ng OSE configuration file. You can reference the block using the value of the name option from the plugin.conf file, followed by parentheses, for example, apache-access-logs(). Make sure to use the block in the appropriate context of the configuration file, for example, within a source statement if the value of the context option in the plugin.conf file is source.
@include "scl.conf" ... source s_apache { file("/var/log/apache2/access.log" flags(no-parse) program-override("apache2")); file("/var/log/apache2/error.log" flags(no-parse) program-override("apache2")); file("/var/log/apache2/ssl.log" flags(no-parse) program-override("apache2")); apache-access-logs(); }; log { source(s_apache); destination(d_central); }; ...
Check if your modified syslog-ng OSE configuration file is syntactically correct using the syslog-ng --syntax-only command.
If your modified configuration is syntactically correct, load the new configuration file using the syslog-ng-ctl reload command.
© 2025 One Identity LLC. ALL RIGHTS RESERVED. 利用規約 プライバシー Cookie Preference Center