Starting with syslog-ng PE7.0, every configuration object is a log expression. Every configuration object is essentially a configuration block, and can include multiple objects. To reference the block, only the top-level object must be referenced. That way you can use embedded log statements, junctions and in-line object definitions within source, destination, filter, rewrite and parser definitions. For example, a source can include a rewrite rule to modify the messages received by the source, and that combination can be used as a simple source in a log statement. This feature allows you to preprocess the log messages very close to the source itself.
To embed multiple objects into a configuration object, use the following syntax. Note that you must enclose the configuration block between braces instead of parenthesis.
<type-of-top-level-object> <name-of-top-level-object> {
channel {
<configuration-objects>
};
};
Example: Using channels
For example, to process a log file in a specific way, you can define the required processing rules (parsers and rewrite expressions) and combine them in a single object:
source s_apache {
channel {
source { file("/var/log/apache/error.log"); };
parser(p_apache_parser);
};
};
log { source(s_apache); ... };
The s_apache source uses a file source (the error log of an Apache webserver) and references a specific parser to process the messages of the error log. The log statement references only the s_apache source, and any other object in the log statement can already use the results of the p_apache_parserparser.
NOTE: You must start the object definition with a channel even if you will use a junction, for example:
parser demo-parser() {
channel {
junction {
channel { ... };
channel { ... };
};
};
};
If you want to embed configuration objects into sources or destinations, always use channels, otherwise the source or destination will not behave as expected. For example, the following configuration is good:
source s_filtered_hosts {
channel{
source {
pipe("/dev/pipe");
syslog(
ip(192.168.0.1)
transport("tcp")
);
syslog(
ip(127.0.0.1)
transport("tcp")
);
};
filter {
netmask(10.0.0.0/16);
};
};
};;
Starting with syslog-ng PE version 4 F1, it is possible to define global variables in the configuration file. Global variables are actually name-value pairs. When syslog-ng processes the configuration file during startup, it automatically replaces `name` with value. To define a global variable, use the following syntax:
@define name "value"
The value can be any string, but special characters must be escaped.To use the variable, insert the name of the variable enclosed between backticks (`, similarly to using variables in Linux or UNIX shells) anywhere in the configuration file. If backticks are meant literally, repeat the backticks to escape them. For example, ``not-substituted-value``.
The value of the global variable can be also specified using the following methods:
-
Without any quotes, as long as the value does not contain any spaces or special characters. In other word, it contains only the following characters: a-zA-Z0-9_..
-
Between apostrophes, in case the value does not contain apostrophes.
-
Between double quotes, in which case special characters must be escaped using backslashes (\).
TIP: The environmental variables of the host are automatically imported and can be used as global variables.
Example: Using global variables
For example, if an application is creating multiple log files in a directory, you can store the path in a global variable, and use it in your source definitions.
@define mypath "/opt/myapp/logs"
source s_myapp_1 {
file("`mypath`/access.log"
follow-freq(1)
);
};
source s_myapp_2 {
file("`mypath`/error.log"
follow-freq(1)
);
};
source s_myapp_3 {
file("`mypath`/debug.log"
follow-freq(1)
);
};
The syslog-ng PE application will interpret this as:
@define mypath "/opt/myapp/logs"
source s_myapp_1 {
file("/opt/myapp/logs/access.log"
follow-freq(1)
);
};
source s_myapp_2 {
file("/opt/myapp/logs/error.log"
follow-freq(1)
);
};
source s_myapp_3 {
file("/opt/myapp/logs/debug.log"
follow-freq(1)
);
};
Every time syslog-ng is started, or its configuration is reloaded, it automatically logs the SHA-1 fingerprint of its configuration file using the internal() message source. That way any modification of the configuration of your syslog-ng clients is visible in the central logs. Note that the log message does not contain the exact change, nor can the configuration file be retrieved from the fingerprint. Only the fact of the configuration change can be detected.
NOTE: Modular configuration files that are included in the main configuration file of syslog-ng PE are included when the fingerprint is calculated. However, other external files (for example, scripts used in program sources or destinations) are excluded, therefore their modifications do not change the fingerprint.
The fingerprint can be examined with the logchksign command-line application, which detects that the fingerprint was indeed generated by a syslog-ng application. Just paste the hashes from the log message after the logchksign command like in the following example:
bin/logchksign "cfg-fingerprint='832ef664ff79df8afc66cd955c0c8aaa3c343f31', cfg-nonce-ndx='0', cfg-signature='785223cfa19ad52b855550be141b00306347b0a9'"
To increase its flexibility and simplify the development of additional modules, the syslog-ng PE application is modular. The majority of syslog-ng PE's functionality is in separate modules. As a result, it is also possible to fine-tune the resource requirements of syslog-ng PE (for example, by loading only the modules that are actually used in the configuration, or simply omitting modules that are not used but require large amount of memory).
Each module contains one or more plugins that add some functionality to syslog-ng PE (for example, a destination or a source driver).
-
To display the list of available modules, run the syslog-ng --version command.
-
To display the description of the available modules, run the syslog-ng --module-registry command.
-
To customize which modules syslog-ng PE automatically loads when syslog-ng PE starts, use the --default-modules command-line option of syslog-ng PE.
-
To request loading a module from the syslog-ng PE configuration file, see Loading modules.
For details on the command-line parameters of syslog-ng PE mentioned in the previous list, see the syslog-ng PE man page at The syslog-ng manual page.