Purpose:
The AxoSyslog 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 AxoSyslog 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 AxoSyslog configuration snippet.
Steps:
-
Navigate to the directory where you have installed AxoSyslog (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 AxoSyslog configuration file as well, so use a descriptive name. -
Create a file called
plugin.confin this new directory. -
Edit the
plugin.conffile 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 AxoSyslog configuration file as a configuration block using the valuenameoption.The
contextoption 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. Therootblocks 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--myparameterparameter becomes available in the script as theconfgen_myparameterenvironment variable. -
Write a script that generates the output you need, and formats it to a configuration snippet that AxoSyslog 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 anaccess.logfile.#!/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.conffile in thesyslog-ng.conffile — or a file already included intosyslog-ng.conf. Version 3.7 and newer automatically includes the*.conffiles from the<directory-where-syslog-ng-is-installed>/scl/*/directories. For details on including configuration files, see Including configuration files. -
Add the block you defined in the
plugin.conffile to your AxoSyslog configuration file. You can reference the block using the value of thenameoption from theplugin.conffile, 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 thecontextoption in theplugin.conffile 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 AxoSyslog configuration file is syntactically correct using the
syslog-ng --syntax-onlycommand. -
If your modified configuration is syntactically correct, load the new configuration file using the
syslog-ng-ctl reloadcommand.