General settings

You can use the following directives throughout the configuration file. The NXLog Agent configuration parser processes these directives and substitutes values before loading the configuration.

define

Use this directive to configure a constant or macro to be used later. Refer to a define by surrounding the name with percent signs (%). Enclose a group of statements with curly braces ({}).

Example 1. Using the define Directive

This configuration shows three defines: BASEDIR is a constant, IMPORTANT is a statement, and WARN_DROP is a group of statements.

nxlog.conf
define BASEDIR /var/log
define IMPORTANT if $raw_event =~ /important/ \
                    $Message = 'IMPORTANT ' + $raw_event;
define WARN_DROP { log_warning("dropping message"); drop(); }

<Input messages>
    Module    im_file
    File      '%BASEDIR%/messages'
</Input>

<Input proftpd>
    Module    im_file
    File      '%BASEDIR%/proftpd.log'
    <Exec>
        %IMPORTANT%
        if $raw_event =~ /dropme/ %WARN_DROP%
    </Exec>
</Input>
envvar

This directive works like define, except that the value is retrieved from the environment.

Example 2. Using the envvar Directive

This example is like the previous one, but BASEDIR is fetched from the environment instead.

nxlog.conf
envvar BASEDIR

<Input file>
    Module    im_file
    File      '%BASEDIR%/messages'
</Input>
include

This directive allows a specified file or files to be included in the current NXLog Agent configuration. Wildcarded filenames are supported.

The SpoolDir directive only takes effect after the configuration is parsed, so relative paths specified with the include directive must be relative to the NXLog Agent working directory.

The examples below provide various ways of using the include directive.

Example 3. Using the include Directive

This example includes a file relative to the working directory.

nxlog.conf
include modules/module1.conf

In case multiple .conf files are to be defined, they can be saved in the nxlog.d directory and then automatically included in the NXLog Agent configuration along with the nxlog.conf file. Adding .conf files in the nxlog.d directory extends the NXLog Agent configuration, without needing to modify the main nxlog.conf file.

This solution could be useful to specify OS-specific configuration snippets (like windows2003.conf) or application-specific snippets (such as syslog.conf).

Including subdirectories inside the configuration directory is not supported.

Example 4. Including Files With Wildcarded Names

This example includes all matching files from the nxlog.d directory and uses absolute paths on Unix-like systems and Windows.

nxlog.conf
include /etc/nxlog.d/*.conf
nxlog.conf
include C:\Program Files\nxlog\conf\nxlog.d\*.conf
include_stdout

Use this directive to load dynamic configuration from the standard output of a command or script. include_stdout behaves like a command-line interface and accepts a path to a command or script file. It does not support arguments or execution of external scripts, such as PowerShell, directly. However, you can encapsulate scripts in a command file.

Example 5. Using the include_stdout directive

This example executes a bash script to load dynamic NXLog Agent configuration.

nxlog.conf
include_stdout /opt/nxlog/etc/fetch_conf.sh
setenv

This directive sets an environment variable for the nxlog process. The value must be in the format <VAR_NAME>=<VAR_VALUE>.

Example 6. Using the setenv directive

This example creates an environment variable named KRB5_KTNAME and assigns it the value C:\Program Files\nxlog\krb\krb5.keytab.

nxlog.conf
setenv KRB5_KTNAME=C:\Program Files\nxlog\krb\krb5.keytab