Chat now with support
Chat with Support

syslog-ng Premium Edition 6.0.21 - Administration Guide

Preface Chapter 1. Introduction to syslog-ng Chapter 2. The concepts of syslog-ng Chapter 3. Installing syslog-ng Chapter 4. The syslog-ng PE quick-start guide Chapter 5. The syslog-ng PE configuration file Chapter 6. Collecting log messages — sources and source drivers Chapter 7. Sending and storing log messages — destinations and destination drivers Chapter 8. Routing messages: log paths, reliability, and filters Chapter 9. Global options of syslog-ng PE Chapter 10. TLS-encrypted message transfer Chapter 12.  Reliable Log Transfer Protocol™ Chapter 13. Reliability and minimizing the loss of log messages Chapter 14. Manipulating messages Chapter 15. Parsing and segmenting structured messages Chapter 16. Processing message content with a pattern database Chapter 17. Statistics and metrics of syslog-ng Chapter 18. Multithreading and scaling in syslog-ng PE Chapter 19. Troubleshooting syslog-ng Chapter 20. Best practices and examples

Collecting messages from tables or relational database

The sql() driver collects messages from an SQL database. Currently the Microsoft SQL (MSSQL), MySQL, Oracle and PostgreSQL databases are supported.

The sql() driver has the following required parameters: database(), host(), table(), type(), uid-column(), datetime-column() or date-column() and time-column().

Declaration: 

sql(options);

Note that the sql() source driver has the following restrictions and limitations:

  • The sql() source driver does not monitor rotated tables. Therefore, every source can follow only one table.

  • Timestamps columns with timezone are not supported. The syslog-ng PE application will retrieve the timestamp from these columns, but without the timezone information.

  • The sql() source driver ignores the log-msg-size() option, that is, messages read from the SQL database can be longer than the maximal message length set in the log-msg-size() option.

  • There is an ID column that is the monotonically increasing unique ID of the monitored table. It is not possible to use more than one ID column as complex ID.

Example 6.22. Using a MySQL source

With the following configuration, syslog-ng PE reads the records from the test_log table ordered by the id column.

The test_log table has the following structure:

CREATE TABLE “test_log” (
  “id” BIGINT NOT NULL AUTO_INCREMENT,
  “timestamp” TIMESTAMP NOT NULL,
  “host” VARCHAR(64) NOT NULL,
  “program” VARCHAR(64) NOT NULL,
  “log” VARCHAR(1024) NOT NULL
  );

The matching syslog-ng PE configuration that reads this table is the following:

source s_mysql { sql(
                type("mysql")
                host("10.140.32.29")
                username("user")
                password("secret")
                database("test_db")
                table("test_log")
                datetime-column("timestamp")
                uid-column("id")
                message-template("${.sql.id} ${.sql.log}")
                program-template("${.sql.program}")
                host-template("${.sql.host}")
                fast-follow-mode(yes)

);};

Supported SQL sources by platform

NOTE:

If a particular database is not supported on a platform you are using it, use the sql() source on a different syslog-ng PE host to retrieve the records remotely.

Table 6.3. Supported SQL sources by platform

Platform \ Database MSSQL MySQL PgSQL Oracle
AIX -
FreeBSD 8 -
FreeBSD 9 -
FreeBSD 10 -
HP-UX 11v2_on IA64 - -
Linux (linux_glibc236): CentOS 5
Linux (linux_glibc236): CentOS 6
Linux (linux_glibc236): CentOS 7
Linux (linux_glibc236): Debian 7
Linux (linux_glibc236): openSUSE 11
Linux (linux_glibc236): Oracle Linux 5
Linux (linux_glibc236): Oracle Linux 6
Linux (linux_glibc236): Oracle Linux 7
Linux (linux_glibc236): SLES 11
Linux (linux_glibc236): Red Hat EL 5
Linux (linux_glibc236): Red Hat EL 6
Linux (linux_glibc236): Red Hat EL 7
Linux (linux_glibc236): Ubuntu 12.04
Linux (linux_glibc236): Ubuntu 14.04
Solaris 10 on SPARC and SPARC64
Solaris 11 on SPARC and SPARC64
Solaris 10 on x86_64 -
Solaris 11 on x86_64 -

sql() source options

The sql() driver has the following options.

archive-query()
Type: string
Default:

Description: The SQL-like statement which is executed after syslog-ng PE has queried a batch of records (as set in the log-fetch-limit() option). This statement can be used for example to archive or delete the records processed by syslog-ng PE. Note that the user account that syslog-ng PE uses to access the database requires the appropriate privileges to execute the statement. If executing the statement fails, syslog-ng PE will log the error message returned by the database, and continue processing the other records.

For details on customizing queries, see the section called “Customizing SQL queries”.

Caution:

The syslog-ng PE application does not validate or limit the contents of customized queries. Consequently, queries performed with a user with write-access can potentially modify or even harm the database. Use customized queries with care, and only for your own responsibility.

Example 6.23. A sample archive query

The following statement deletes the records already retreived from the database if the table is read from the beginning.

archive-query("DELETE FROM test_logs WHERE id <= $last_read_uid")

columns()
Type: string list
Default: empty

Description: The list of the name of the columns that will be queried. The default value is empty, meaning that all of the columns will be queried.

Example 6.24. SQL source option columns

columns("id","date","message")


connect-query()
Type: string
Default:

Description: The SQL-like statement which is executed after syslog-ng PE has successfully connected to the database.

For details on customizing queries, see the section called “Customizing SQL queries”.

Caution:

The syslog-ng PE application does not validate or limit the contents of customized queries. Consequently, queries performed with a user with write-access can potentially modify or even harm the database. Use customized queries with care, and only for your own responsibility.

Example 6.25. A sample connect query

connect-query("SET COLLATION_CONNECTION='utf8_general_ci'")

database()
Type: string
Default: logs

Description: Name of the database that stores the logs. Macros cannot be used in database name. Also, when using an Oracle database, you cannot use the same database() settings in more than one destination.

date-column(col_name, [format])
Type: date, string
Default:

Description: The column containing the date of the logrecord. The format value has to be in strptime format. For details, see the strptime manual page (man strptime).

NOTE:

If the type of the column is string, this is a required parameter.

datetime-column(col_name, [format])
Type: string
Default:

The following column types are supported:

  • MySQL: timestamp, datetime, int

  • PostgreSQL: timestamp, int

  • Oracle: timestamp, int

  • MSSQL: datetime, int

Description: The column containing the timestamp. If the type is int, it is considered to contain a UNIX timestamp. The format value is required if the type is string, and has to be in strptime format. For details, see the strptime manual page (man strptime).

Example 6.26. SQL source option datetime-column(col_name, [format])

datetime("timestampcol", "%Y-%m-%d")


default-facility()
Type: facility string
Default: local0

Description: This parameter assigns a facility value to the messages received from the sql source.

default-priority()
Type: priority string
Default: info

Description: This parameter assigns an emergency level to the messages received from the sql source.

fast-follow-mode()
Type: yes|no
Default: yes

Description: If set to yes, syslog-ng PE reads the database table as fast as possible, until it reaches the last record. After this, it will execute only one query in follow-freq() time. If it is set to no, syslog-ng PE executes only one query in follow-freq() time.

fetch-query()
Type: string
Default: Default value is generated in running time of syslog-ng

Description: The SQL-like statement used to collect the records from the database.

NOTE:

If this parameter is defined, syslog-ng PE does not check or validate it whether it is correct. Ensure that the customized statements are correct.

For details on customizing queries, see the section called “Customizing SQL queries”.

Caution:

The syslog-ng PE application does not validate or limit the contents of customized queries. Consequently, queries performed with a user with write-access can potentially modify or even harm the database. Use customized queries with care, and only for your own responsibility.

Example 6.27. A sample fetch query

fetch-query("SELECT * FROM $table WHERE id > $last_read_uid AND test_logs.log LIKE '%ERROR%' ORDER BY $uid")

The default fetch queries are the following:

  • MSSQL:

    SELECT TOP $fetch_limit $columns FROM $table WHERE $uid > '$last_read_uid' ORDER BY $uid 
  • MySQL:

    SELECT $columns FROM $table WHERE $uid > '$last_read_uid' ORDER BY $uid LIMIT 0,$fetch_limit 
  • Oracle:

    SELECT $columns FROM (SELECT $table.*, Row_Number() OVER (ORDER BY $uid) FetchRow FROM $table WHERE $uid > '$last_read_uid' ) WHERE FetchRow BETWEEN 0 AND $fetch_limit 
  • PostgreSQL:

    SELECT $columns FROM $table WHERE $uid > '$last_read_uid' ORDER BY $uid LIMIT $fetch_limit 
follow-freq()
Type: number (seconds)
Default: 10

Indicates that the source should be checked periodically. This is useful for SQL sources which always indicate readability, even though no new records were appended. If this value is higher than zero, syslog-ng will not attempt to use poll() on the SQL source, but checks whether the SQL source changed every time the follow-freq() interval (in seconds) has elapsed. Floating-point numbers (for example 1.5) can be used as well.

host()
Type: hostname or IP address
Default: n/a

Description: Hostname of the database server. Note that Oracle destinations do not use this parameter, but retrieve the hostname from the /etc/tnsnames.ora file.

NOTE:

If you specify host="localhost", syslog-ng will use a socket to connect to the local database server. Use host="127.0.0.1" to force TCP communication between syslog-ng and the local database server.

To specify the socket to use, set and export the MYSQL_UNIX_PORT environment variable, for example MYSQL_UNIX_PORT=/var/lib/mysql/mysql.sock; export MYSQL_UNIX_PORT.

host-template()
Type: string
Default: Empty string

Description: The template for defining the HOST part of the message. If the host-template() option is not specified, the value of the host() option will be used in the HOST part of the message.

NOTE:

This option requires the option keep-hostname() to be enabled: keep-hostname(yes).

log-fetch-limit()
Type:
Default: 100

Description: The maximum number of messages fetched from a source during a single poll loop. The destination queues might fill up before flow-control could stop reading if log-fetch-limit() is too high.

log-iw-size()
Type: number (messages)
Default: 1000

Description: The size of the initial window, this value is used during flow control. If the max-connections() option is set, the log-iw-size() will be divided by the number of connections, otherwise log-iw-size() is divided by 10 (the default value of the max-connections() option). The resulting number is the initial window size of each connection. For optimal performance when receiving messages from syslog-ng PE clients, make sure that the window size is larger than the flush-lines() option set in the destination of your clients.

Example 6.28. Initial window size of a connection

If log-iw-size(1000) and max-connections(10), then each connection will have an initial window size of 100.


max-uid-query()
Type: string
Default: "SELECT max($uid) FROM $table"

Description: Used for retrieving the ID of the last row (that is, the last row of the last fetch) from the database source.

NOTE:

If this parameter is defined, syslog-ng PE does not check or validate whether it is correct. Ensure that the customized statements are correct.

This option is mandatory if read-old-records(no) and fetch-query() is defined.

NOTE:

When fetch-query() is defined, the default value will be:

"SELECT MAX($uid) FROM ( <fetch-query()> )"

Following a restart or reload of syslog-ng PE, if no new data has arrived since the last fetch, the custom query defined in fetch-query() will fetch everything starting from the very beginning. To avoid this and retrieve only the ID of the last row, replace the above value with something similar:

"SELECT max($uid) FROM $table"

This option cannot be used if read-old-records(yes).

message-template()
Type: string
Default:

Description: The alias of the template() parameter.

password()
Type: string
Default: n/a

Description: Password of the database user.

port()
Type: number (port number)
Default: 1433 TCP for MSSQL, 3306 TCP for MySQL, 1521 for Oracle, and 5432 TCP for PostgreSQL

Description: The port number to connect to.

prefix()
Type: string
Default: ".sql"

Description: This prefix will be added to the name of the macros created from the database columns.

Example 6.29. SQL source option prefix()

If a database column is called column1, and the prefix option is set as prefix("customprefix."), the macro for the column will be called customprefix.column1.


program-template()
Type: string
Default: Empty string

Description: The template for defining the PROGRAM part of the message. If not specified, the PROGRAM message part will be empty.

read-old-records()
Type: yes|no
Default: yes

Description:

  • If syslog-ng PE reads the database for the first time:
    • If set to yes, syslog-ng PE starts reading the records from the beginning of the database.
    • If set to no, syslog-ng PE only reads the new records in the database.
  • If syslog-ng PE has read the database before: If syslog-ng PE has read the database before, the read-old-records() option has created a persist entry during the first reading.

    • If set to yes, syslog-ng PE reads the last_read_uid from the persist file, and reads every record from the sql table where the uid is greater than the last_read_uid. Next, syslog-ng PE starts polling the database and updates the last_read_uid with the most recent uid from the database.

    • If set to no, syslog-ng PE first runs a select max(uid) SQL query for the table, then updates the last_read_uid with the value from the SQL query. After that, syslog-ng PE starts polling the database, starting from this updated last_read_uid value.

(missing or bad snippet)
table()
Type: string
Default:

Description: The name of the monitored table. Only a single literal name is accepted, macros cannot be used in the name of the table. Monitoring rotated tables is not supported.

table-init-query()
Type: string
Default:

Description: The SQL-like statement which is executed before fetching the first batch of records.

For details on customizing queries, see the section called “Customizing SQL queries”.

Caution:

The syslog-ng PE application does not validate or limit the contents of customized queries. Consequently, queries performed with a user with write-access can potentially modify or even harm the database. Use customized queries with care, and only for your own responsibility.

tags()
Type: string
Default:

Description: Label the messages received from the source with custom tags. Tags must be unique, and enclosed between double quotes. When adding multiple tags, separate them with comma, for example tags("dmz", "router"). This option is available only in syslog-ng 3.1 and later.

template()
Type: string
Default:

Description: The template of the message (${MSG}) to be generated. If not specified, the following template will be used: "$(format-welf --key <prefix>*)") where <prefix> is the value of the prefix() option. This template converts the retrieved records into the WebTrends Enhanced Log file Format (WELF).

NOTE:

The format-welf function does not keep the order of columns between queries.

Example 6.30. SQL source option template()

Using the default template for a table that has two columns (id and message) The result of the first query is the following: '.sql.id=12 .sql.message="test message"', whereas the result of the second query can be: '.sql.message="test message" .sql.id=12 '


time-column(col_name, [format])
Type: time, string
Default:

Description: The column containing the time of the logrecord. The format value has to be in strptime format.

NOTE:

If the type of the column is string, this is a required parameter.

time-reopen()
Accepted values: number (seconds)
Default: 60

Description: The time to wait in seconds before a dead connection is reestablished.

time-zone()
Type: timezone in +/-HH:MM format
Default:

Description: The default timezone, if set. If this option is not set, the default timezone is the local timezone.

type()
Type: mssql, mysql, oracle, or pgsql
Default:

Description: Specifies the type of the database, that is, the DBI database driver to use. Use the mssql option to send logs to an MSSQL database. For details, see the examples of the databases on the following sections.

uid-column()
Type: string
Default:

Description: The monotonically increasing unique ID of the monitored table (for example auto_increment). This column must be a type where the greater (>) operation is interpreted.

NOTE:

The value of the first record of this column should not be 0: syslog-ng PE will skip this value.

use-syslogng-pid()
Type: yes or no
Default: no

Description: If the value of this option is yes, then the PID value of the message will be overridden with the PID of the running syslog-ng process.

username()
Type: string
Default: n/a

Description: Name of the database user.

Customizing SQL queries

Every query executed by the SQL source can be customized. These customized queries are similar to SQL statements, but in can also refer to syslog-ng PE-specific variables with the prefix $. For example, $table is the name of the table.

Caution:

The syslog-ng PE application does not validate or limit the contents of customized queries. Consequently, queries performed with a user with write-access can potentially modify or even harm the database. Use customized queries with care, and only for your own responsibility.

The available variables are the following:

NOTE:

The variables in the statement are not macro references.

  • $uid: The name of the uid-column().

  • $table: The name of the table() option.

  • $last_read_uid: The uid value of the last read record.

  • $columns: Reach the columns() option of the SQL source (the default is *). If columns is defined in the configuration (for example columns("id" "message")), then the value of this variable will be a comma separated list (for example "id,message").

  • $fetch_limit: Reach the value of the log-fetch-limit() option.

Example 6.31. SQL source fetch-query

The following queries records that are older than the last record:

SELECT * FROM $table WHERE $table.$uid > $last_read_uid ORDER BY $table.$uid

Collecting messages on Sun Solaris

Solaris uses its STREAMS framework to send messages to the syslogd process. Solaris 2.5.1 and above uses an IPC called door in addition to STREAMS, to confirm the delivery of a message. The syslog-ng application supports the IPC mechanism via the door() option (see below).

NOTE:

The sun-streams() driver must be enabled when the syslog-ng application is compiled (see ./configure --help).

The sun-streams() driver has a single required argument specifying the STREAMS device to open, and the door() option. For the list of available optional parameters, see the section called “sun-streams() source options”.

Declaration: 

sun-streams(<name_of_the_streams_device> door(<filename_of_the_door>));

Example 6.32. Using the sun-streams() driver

source s_stream { sun-streams("/dev/log" door("/etc/.syslog_door")); };

sun-streams() source options

The sun-streams() driver has the following options.

door()
Type: string
Default: none

Description: Specifies the filename of a door to open, needed on Solaris above 2.5.1.

flags()
Type: assume-utf8, empty-lines, expect-hostname, kernel, no-multi-line, no-parse, dont-store-legacy-msghdr, syslog-protocol, validate-utf8
Default: empty set

Description: Specifies the log parsing options of the source.

  • assume-utf8: The assume-utf8 flag assumes that the incoming messages are UTF-8 encoded, but does not verify the encoding. If you explicitly want to validate the UTF-8 encoding of the incoming message, use the validate-utf8 flag.

  • dont-store-legacy-msghdr: By default, syslog-ng stores the original incoming header of the log message. This is useful of the original format of a non-syslog-compliant message must be retained (syslog-ng automatically corrects minor header errors, for example, adds a whitespace before msg in the following message: Jan 22 10:06:11 host program:msg). If you do not want to store the original header of the message, enable the dont-store-legacy-msghdr flag.

  • empty-lines: Use the empty-lines flag to keep the empty lines of the messages. By default, syslog-ng PE removes empty lines automatically.

  • expect-hostname: If the expect-hostname flag is enabled, syslog-ng PE will assume that the log message contains a hostname and parse the message accordingly. This is the default behavior for TCP sources. Note that pipe sources use the no-hostname flag by default.

  • kernel: The kernel flag makes the source default to the LOG_KERN | LOG_NOTICE priority if not specified otherwise.

  • no-hostname: Enable the no-hostname flag if the log message does not include the hostname of the sender host. That way syslog-ng PE assumes that the first part of the message header is ${PROGRAM} instead of ${HOST}. For example:

    source s_dell { network(port(2000) flags(no-hostname)); };
  • no-multi-line: The no-multi-line flag disables line-breaking in the messages: the entire message is converted to a single line. Note that this happens only if the underlying transport method actually supports multi-line messages. Currently the rltp, syslog(), network(), unix-dgram() drivers support multi-line messages.

  • no-parse: By default, syslog-ng PE parses incoming messages as syslog messages. The no-parse flag completely disables syslog message parsing and processes the complete line as the message part of a syslog message. The syslog-ng PE application will generate a new syslog header (timestamp, host, and so on) automatically and put the entire incoming message into the MSG part of the syslog message. This flag is useful for parsing messages not complying to the syslog format.

    If you are using the flags(no-parse) option, then syslog message parsing is completely disabled, and the entire incoming message is treated as the ${MESSAGE} part of a syslog message. In this case, syslog-ng PE generates a new syslog header (timestamp, host, and so on) automatically. Note that since flags(no-parse) disables message parsing, it interferes with other flags, for example, disables flags(no-multi-line).

  • syslog-protocol: The syslog-protocol flag specifies that incoming messages are expected to be formatted according to the new IETF syslog protocol standard (RFC5424), but without the frame header. Note that this flag is not needed for the syslog driver, which handles only messages that have a frame header.

  • validate-utf8: The validate-utf8 flag enables encoding-verification for messages formatted according to the new IETF syslog standard (for details, see the section called “IETF-syslog messages”). If theBOM[8]character is missing, but the message is otherwise UTF-8 compliant, syslog-ng automatically adds the BOM character to the message.

follow-freq()
Type: number (seconds)
Default: 1

Description: Indicates that the source should be checked periodically. This is useful for files which always indicate readability, even though no new lines were appended. If this value is higher than zero, syslog-ng will not attempt to use poll() on the file, but checks whether the file changed every time the follow-freq() interval (in seconds) has elapsed. Floating-point numbers (for example 1.5) can be used as well.

keep-timestamp()
Type: yes or no
Default: yes

Description: Specifies whether syslog-ng should accept the timestamp received from the sending application or client. If disabled, the time of reception will be used instead. This option can be specified globally, and per-source as well. The local setting of the source overrides the global option if available.

Caution:

To use the S_ macros, the keep-timestamp() option must be enabled (this is the default behavior of syslog-ng PE).

log-fetch-limit()
Type: number (messages)
Default: 10

Description: The maximum number of messages fetched from a source during a single poll loop. The destination queues might fill up before flow-control could stop reading if log-fetch-limit() is too high.

log-iw-size()
Type: number (messages)
Default: 1000

Description: The size of the initial window, this value is used during flow control. If the max-connections() option is set, the log-iw-size() will be divided by the number of connections, otherwise log-iw-size() is divided by 10 (the default value of the max-connections() option). The resulting number is the initial window size of each connection. For optimal performance when receiving messages from syslog-ng PE clients, make sure that the window size is larger than the flush-lines() option set in the destination of your clients.

Example 6.33. Initial window size of a connection

If log-iw-size(1000) and max-connections(10), then each connection will have an initial window size of 100.


log-msg-size()
Type: number (bytes)
Default: Use the global log-msg-size() option, which defaults to 65535.

Description: Specifies the maximum length of incoming log messages. Uses the value of the global option if not specified. For details on how encoding affects the size of the message, see the section called “Message size and encoding”.

log-prefix() (DEPRECATED)
Type: string
Default:

Description: A string added to the beginning of every log message. It can be used to add an arbitrary string to any log source, though it is most commonly used for adding kernel: to the kernel messages on Linux. NOTE: This option is deprecated. Use program-override() instead.

optional()
Type: yes or no
Default:

Description: Instruct syslog-ng to ignore the error if a specific source cannot be initialized. No other attempts to initialize the source will be made until the configuration is reloaded. This option currently applies to the pipe(), unix-dgram, and unix-stream drivers.

pad-size()
Type: number (bytes)
Default: 0

Description: Specifies input padding. Some operating systems (such as HP-UX) pad all messages to block boundary. This option can be used to specify the block size. (HP-UX uses 2048 bytes). The syslog-ng PE application will pad reads from the associated device to the number of bytes set in pad-size(). Mostly used on HP-UX where /dev/log is a named pipe and every write is padded to 2048 bytes. If pad-size() was given and the incoming message does not fit into pad-size(), syslog-ng will not read anymore from this pipe and displays the following error message:

Padding was set, and couldn't read enough bytes
program-override()
Type: string
Default:

Description: Replaces the ${PROGRAM} part of the message with the parameter string. For example, to mark every message coming from the kernel, include the program-override("kernel") option in the source containing /proc/kmsg.

tags()
Type: string
Default:

Description: Label the messages received from the source with custom tags. Tags must be unique, and enclosed between double quotes. When adding multiple tags, separate them with comma, for example tags("dmz", "router"). This option is available only in syslog-ng 3.1 and later.

time-zone()
Type: name of the timezone, or the timezone offset
Default:

Description: The default timezone for messages read from the source. Applies only if no timezone is specified within the message itself.

The timezone can be specified as using the name of the (for example time-zone("Europe/Budapest")), or as the timezone offset in +/-HH:MM format (for example +01:00). On Linux and UNIX platforms, the valid timezone names are listed under the /usr/share/zoneinfo directory.

use-syslogng-pid()
Type: yes or no
Default: no

Description: If the value of this option is yes, then the PID value of the message will be overridden with the PID of the running syslog-ng process.



[8] The byte order mark (BOM) is a Unicode character used to signal the byte-order of the message text.

Collecting messages using the IETF syslog protocol (syslog() driver)

The syslog() driver can receive messages from the network using the standard IETF-syslog protocol (as described in RFC5424-26). UDP, TCP, and TLS-encrypted TCP can all be used to transport the messages.

NOTE:

The syslog() driver can also receive BSD-syslog-formatted messages (described in RFC 3164, see the section called “BSD-syslog or legacy-syslog messages”) if they are sent using the IETF-syslog protocol.

In syslog-ng PE versions 3.1 and earlier, the syslog() driver could handle only messages in the IETF-syslog (RFC 5424-26) format.

For the list of available optional parameters, see the section called “syslog() source options”.

Declaration: 

syslog(ip() port() transport() options());

Example 6.34. Using the syslog() driver

TCP source listening on the localhost on port 1999.

source s_syslog { syslog(ip(127.0.0.1) port(1999) transport("tcp")); };

UDP source with defaults.

source s_udp { syslog( transport("udp")); };

Encrypted source where the client is also authenticated. For details on the encryption settings, see the section called “TLS options”.

source s_syslog_tls{ syslog(
    ip(10.100.20.40)
    transport("tls")
    tls(
    peer-verify(required-trusted)
    ca-dir('/opt/syslog-ng/etc/syslog-ng/keys/ca.d/')
    key-file('/opt/syslog-ng/etc/syslog-ng/keys/server_privatekey.pem')
    cert-file('/opt/syslog-ng/etc/syslog-ng/keys/server_certificate.pem')
    )
    );};

Caution:

When receiving messages using the UDP protocol, increase the size of the UDP receive buffer on the receiver host (that is, the syslog-ng PE server or relay receiving the messages). Note that on certain platforms, for example, on Red Hat Enterprise Linux 5, even low message load (~200 messages per second) can result in message loss, unless the so-rcvbuf() option of the source is increased. In such cases, you will need to increase the net.core.rmem_max parameter of the host (for example, to 1024000), but do not modify net.core.rmem_default parameter.

As a general rule, increase the so-rcvbuf() so that the buffer size in kilobytes is higher than the rate of incoming messages per second. For example, to receive 2000 messages per second, set the so-rcvbuf() at least to 2 097 152 bytes.

syslog() source options

The syslog() driver has the following options.

encoding()
Type: string
Default:

Description: Specifies the characterset (encoding, for example UTF-8) of messages using the legacy BSD-syslog protocol. To list the available character sets on a host, execute the iconv -l command. For details on how encoding affects the size of the message, see the section called “Message size and encoding”.

flags()
Type: assume-utf8, empty-lines, expect-hostname, kernel, no-multi-line, no-parse, dont-store-legacy-msghdr, syslog-protocol, validate-utf8
Default: empty set

Description: Specifies the log parsing options of the source.

  • assume-utf8: The assume-utf8 flag assumes that the incoming messages are UTF-8 encoded, but does not verify the encoding. If you explicitly want to validate the UTF-8 encoding of the incoming message, use the validate-utf8 flag.

  • dont-store-legacy-msghdr: By default, syslog-ng stores the original incoming header of the log message. This is useful of the original format of a non-syslog-compliant message must be retained (syslog-ng automatically corrects minor header errors, for example, adds a whitespace before msg in the following message: Jan 22 10:06:11 host program:msg). If you do not want to store the original header of the message, enable the dont-store-legacy-msghdr flag.

  • empty-lines: Use the empty-lines flag to keep the empty lines of the messages. By default, syslog-ng PE removes empty lines automatically.

  • expect-hostname: If the expect-hostname flag is enabled, syslog-ng PE will assume that the log message contains a hostname and parse the message accordingly. This is the default behavior for TCP sources. Note that pipe sources use the no-hostname flag by default.

  • kernel: The kernel flag makes the source default to the LOG_KERN | LOG_NOTICE priority if not specified otherwise.

  • no-hostname: Enable the no-hostname flag if the log message does not include the hostname of the sender host. That way syslog-ng PE assumes that the first part of the message header is ${PROGRAM} instead of ${HOST}. For example:

    source s_dell { network(port(2000) flags(no-hostname)); };
  • no-multi-line: The no-multi-line flag disables line-breaking in the messages: the entire message is converted to a single line. Note that this happens only if the underlying transport method actually supports multi-line messages. Currently the rltp, syslog(), network(), unix-dgram() drivers support multi-line messages.

  • no-parse: By default, syslog-ng PE parses incoming messages as syslog messages. The no-parse flag completely disables syslog message parsing and processes the complete line as the message part of a syslog message. The syslog-ng PE application will generate a new syslog header (timestamp, host, and so on) automatically and put the entire incoming message into the MSG part of the syslog message. This flag is useful for parsing messages not complying to the syslog format.

    If you are using the flags(no-parse) option, then syslog message parsing is completely disabled, and the entire incoming message is treated as the ${MESSAGE} part of a syslog message. In this case, syslog-ng PE generates a new syslog header (timestamp, host, and so on) automatically. Note that since flags(no-parse) disables message parsing, it interferes with other flags, for example, disables flags(no-multi-line).

  • syslog-protocol: The syslog-protocol flag specifies that incoming messages are expected to be formatted according to the new IETF syslog protocol standard (RFC5424), but without the frame header. Note that this flag is not needed for the syslog driver, which handles only messages that have a frame header.

  • validate-utf8: The validate-utf8 flag enables encoding-verification for messages formatted according to the new IETF syslog standard (for details, see the section called “IETF-syslog messages”). If theBOM[9]character is missing, but the message is otherwise UTF-8 compliant, syslog-ng automatically adds the BOM character to the message.

host-override()
Type: string
Default:

Description: Replaces the ${HOST} part of the message with the parameter string.

ip() or localip()
Type: string
Default: 0.0.0.0

Description: The IP address to bind to. By default, syslog-ng PE listens on every available interface. Note that this is not the address where messages are accepted from.

If you specify a multicast bind address and use the udp transport, syslog-ng PE automatically joins the necessary multicast group. TCP does not support multicasting.

ip-protocol()
Type: number (IP version)
Default: 4

Description: Determines the internet protocol version of the given driver (network() or syslog()). The possible values are 4 and 6, corresponding to IPv4 and IPv6. The default value is 4.

ip-tos()
Type: number (type of service)
Default: 0

Description: Specifies the Type-of-Service value of outgoing packets.

ip-ttl()
Type: number (hops)
Default: 0

Description: Specifies the Time-To-Live value of outgoing packets.

keep-alive()
Type: yes or no
Default: yes

Description: Specifies whether connections to sources should be closed when syslog-ng is forced to reload its configuration (upon the receipt of a SIGHUP signal). Note that this applies to the server (source) side of the syslog-ng connections, client-side (destination) connections are always reopened after receiving a HUP signal unless the keep-alive option is enabled for the destination.

keep-hostname()
Type: yes or no
Default: no

Description: Enable or disable hostname rewriting.

  • If enabled (keep-hostname(yes)), syslog-ng PE assumes that the incoming log message was sent by the host specified in the HOST field of the message.

  • If disabled (keep-hostname(no)), syslog-ng PE rewrites the HOST field of the message, either to the IP address (if the use-dns() parameter is set to no), or to the hostname (if the use-dns() parameter is set to yes and the IP address can be resolved to a hostname) of the host sending the message to syslog-ng PE. For details on using name resolution in syslog-ng PE, see the section called “Using name resolution in syslog-ng”.

NOTE:

If the log message does not contain a hostname in its HOST field, syslog-ng PE automatically adds a hostname to the message.

  • For messages received from the network, this hostname is the address of the host that sent the message (this means the address of the last hop if the message was transferred via a relay).

  • For messages received from the local host, syslog-ng PE adds the name of the host.

This option can be specified globally, and per-source as well. The local setting of the source overrides the global option if available.

NOTE:

When relaying messages, enable this option on the syslog-ng PE server and also on every relay, otherwise syslog-ng PE will treat incoming messages as if they were sent by the last relay.

keep-timestamp()
Type: yes or no
Default: yes

Description: Specifies whether syslog-ng should accept the timestamp received from the sending application or client. If disabled, the time of reception will be used instead. This option can be specified globally, and per-source as well. The local setting of the source overrides the global option if available.

Caution:

To use the S_ macros, the keep-timestamp() option must be enabled (this is the default behavior of syslog-ng PE).

log-fetch-limit()
Type: number (messages)
Default: 10

Description: The maximum number of messages fetched from a source during a single poll loop. The destination queues might fill up before flow-control could stop reading if log-fetch-limit() is too high.

log-iw-size()
Type: number (messages)
Default: 1000

Description: The size of the initial window, this value is used during flow control. If the max-connections() option is set, the log-iw-size() will be divided by the number of connections, otherwise log-iw-size() is divided by 10 (the default value of the max-connections() option). The resulting number is the initial window size of each connection. For optimal performance when receiving messages from syslog-ng PE clients, make sure that the window size is larger than the flush-lines() option set in the destination of your clients.

Example 6.35. Initial window size of a connection

If log-iw-size(1000) and max-connections(10), then each connection will have an initial window size of 100.


log-msg-size()
Type: number (bytes)
Default: Use the global log-msg-size() option, which defaults to 65535.

Description: Specifies the maximum length of incoming log messages. Uses the value of the global option if not specified. For details on how encoding affects the size of the message, see the section called “Message size and encoding”.

max-connections()
Type: number (simultaneous connections)
Default: 10

Description: Specifies the maximum number of simultaneous connections.

multi-line-garbage()
Type: regular expression
Default: empty string

Description: Use the multi-line-garbage() option when processing multi-line messages that contain unneeded parts between the messages. Specify a string or regular expression that matches the beginning of the unneeded message parts. If the multi-line-garbage() option is set, syslog-ng PE ignores the lines between the line matching the multi-line-garbage() and the next line matching multi-line-prefix(). See also the multi-line-prefix() option.

When receiving multi-line messages from a source when the multi-line-garbage() option is set, but no matching line is received between two lines that match multi-line-prefix(), syslog-ng PE will continue to process the incoming lines as a single message until a line matching multi-line-garbage() is received.

Caution:

If the multi-line-garbage() option is set, syslog-ng PE discards lines between the line matching the multi-line-garbage() and the next line matching multi-line-prefix().

NOTE:

Starting with syslog-ng PE version 3.2.1, a message is considered complete if no new lines arrive to the message for 10 seconds, even if no line matching the multi-line-garbage() option is received.

multi-line-prefix()
Type: regular expression
Default: empty string

Description: Use the multi-line-prefix() option to process multi-line messages, that is, log messages that contain newline characters (for example, Tomcat logs). Specify a string or regular expression that matches the beginning of the log messages. Use as simple regular expressions as possible, because complex regular expressions can severely reduce the rate of processing multi-line messages. If the multi-line-prefix() option is set, syslog-ng PE ignores newline characters from the source until a line matches the regular expression again, and treats the lines between the matching lines as a single message. See also the multi-line-garbage() option.

NOTE:

Starting with syslog-ng PE version 3.2.1, a message is considered complete if no new lines arrive to the message for 10 seconds, even if no line matching the multi-line-garbage() option is received.

TIP:
  • To make multi-line messages more readable when written to a file, use a template in the destination and instead of the ${MESSAGE} macro, use the following: $(indent-multi-line ${MESSAGE}). This expression inserts a tab after every newline character (except when a tab is already present), indenting every line of the message after the first. For example:

    destination d_file {
        file ("/var/log/messages"
            template("${ISODATE} ${HOST} $(indent-multi-line ${MESSAGE})\n") );
    };

    For details on using templates, see the section called “Templates and macros”.

  • To actually convert the lines of multi-line messages to single line (by replacing the newline characters with whitespaces), use the flags(no-multi-line) option in the source.

Example 6.36. Processing Tomcat logs

The log messages of the Apache Tomcat server are a typical example for multi-line log messages. The messages start with the date and time of the query in the YYYY.MM.DD HH:MM:SS format, as you can see in the following example.

2010.06.09. 12:07:39 org.apache.catalina.startup.Catalina start
SEVERE: Catalina.start:
LifecycleException:  service.getName(): "Catalina";  Protocol handler start failed: java.net.BindException: Address already in use<null>:8080
       at org.apache.catalina.connector.Connector.start(Connector.java:1138)
       at org.apache.catalina.core.StandardService.start(StandardService.java:531)
       at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
       at org.apache.catalina.startup.Catalina.start(Catalina.java:583)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:597)
       at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:597)
       at org.apache.commons.daemon.support.DaemonLoader.start(DaemonLoader.java:177)
2010.06.09. 12:07:39 org.apache.catalina.startup.Catalina start
INFO: Server startup in 1206 ms
2010.06.09. 12:45:08 org.apache.coyote.http11.Http11Protocol pause
INFO: Pausing Coyote HTTP/1.1 on http-8080
2010.06.09. 12:45:09 org.apache.catalina.core.StandardService stop
INFO: Stopping service Catalina

To process these messages, specify a regular expression matching the timestamp of the messages in the multi-line-prefix() option. Such an expression is the following:

source s_file{ file("/var/log/tomcat6/catalina.2010-06-09.log" follow-freq(0) multi-line-prefix("[0-9]{4}\.[0-9]{2}\.[0-9]{2}\.") flags(no-parse));
};

Note that the flags(no-parse) is needed to avoid syslog-ng PE trying to interpret the date in the message.


Caution:

If you receive messages using the UDP protocol, do not use multi-line processing. If every line of a multi-line message is received in the same UDP packet, everything is fine, but if a multi-line message is fragmented into multiple UDP packets, the order they are received (thus the way how they are processed) cannot be guaranteed, and causes problems.

pad-size()
Type: number (bytes)
Default: 0

Description: Specifies input padding. Some operating systems (such as HP-UX) pad all messages to block boundary. This option can be used to specify the block size. (HP-UX uses 2048 bytes). The syslog-ng PE application will pad reads from the associated device to the number of bytes set in pad-size(). Mostly used on HP-UX where /dev/log is a named pipe and every write is padded to 2048 bytes. If pad-size() was given and the incoming message does not fit into pad-size(), syslog-ng will not read anymore from this pipe and displays the following error message:

Padding was set, and couldn't read enough bytes
port() or localport()
Type: number (port number)
Default:

In case of TCP transport: 601

In case of UDP transport: 514

Description: The port number to bind to.

program-override()
Type: string
Default:

Description: Replaces the ${PROGRAM} part of the message with the parameter string. For example, to mark every message coming from the kernel, include the program-override("kernel") option in the source containing /proc/kmsg.

so-broadcast()
Type: yes or no
Default: no

Description: This option controls the SO_BROADCAST socket option required to make syslog-ng send messages to a broadcast address. For details, see the socket(7) manual page.

so-keepalive()
Type: yes or no
Default: no

Description: Enables keep-alive messages, keeping the socket open. This only effects TCP and UNIX-stream sockets. For details, see the socket(7) manual page.

so-rcvbuf()
Type: number (bytes)
Default: 0

Description: Specifies the size of the socket receive buffer in bytes. For details, see the socket(7) manual page.

Caution:

When receiving messages using the UDP protocol, increase the size of the UDP receive buffer on the receiver host (that is, the syslog-ng PE server or relay receiving the messages). Note that on certain platforms, for example, on Red Hat Enterprise Linux 5, even low message load (~200 messages per second) can result in message loss, unless the so-rcvbuf() option of the source is increased. In such cases, you will need to increase the net.core.rmem_max parameter of the host (for example, to 1024000), but do not modify net.core.rmem_default parameter.

As a general rule, increase the so-rcvbuf() so that the buffer size in kilobytes is higher than the rate of incoming messages per second. For example, to receive 2000 messages per second, set the so-rcvbuf() at least to 2 097 152 bytes.

so-sndbuf()
Type: number (bytes)
Default: 0

Description: Specifies the size of the socket send buffer in bytes. For details, see the socket(7) manual page.

tags()
Type: string
Default:

Description: Label the messages received from the source with custom tags. Tags must be unique, and enclosed between double quotes. When adding multiple tags, separate them with comma, for example tags("dmz", "router"). This option is available only in syslog-ng 3.1 and later.

time-zone()
Type: name of the timezone, or the timezone offset
Default:

Description: The default timezone for messages read from the source. Applies only if no timezone is specified within the message itself.

The timezone can be specified as using the name of the (for example time-zone("Europe/Budapest")), or as the timezone offset in +/-HH:MM format (for example +01:00). On Linux and UNIX platforms, the valid timezone names are listed under the /usr/share/zoneinfo directory.

transport()
Type: rltp, udp, tcp, or tls
Default: tcp

Description: Specifies the protocol used to receive messages from the source.

Caution:

When receiving messages using the UDP protocol, increase the size of the UDP receive buffer on the receiver host (that is, the syslog-ng PE server or relay receiving the messages). Note that on certain platforms, for example, on Red Hat Enterprise Linux 5, even low message load (~200 messages per second) can result in message loss, unless the so-rcvbuf() option of the source is increased. In such cases, you will need to increase the net.core.rmem_max parameter of the host (for example, to 1024000), but do not modify net.core.rmem_default parameter.

As a general rule, increase the so-rcvbuf() so that the buffer size in kilobytes is higher than the rate of incoming messages per second. For example, to receive 2000 messages per second, set the so-rcvbuf() at least to 2 097 152 bytes.

tls()
Type: tls options
Default: n/a

Description: This option sets various options related to TLS encryption, for example, key/certificate files and trusted CA locations. TLS can be used only with tcp-based transport protocols. For details, see the section called “TLS options”.

use-dns()
Type: yes, no, persist_only
Default: yes

Description: Enable or disable DNS usage. The persist_only option attempts to resolve hostnames locally from file (for example from /etc/hosts). The syslog-ng PE application blocks on DNS queries, so enabling DNS may lead to a Denial of Service attack. To prevent DoS, protect your syslog-ng network endpoint with firewall rules, and make sure that all hosts which may get to syslog-ng are resolvable. This option can be specified globally, and per-source as well. The local setting of the source overrides the global option if available.

NOTE:

This option has no effect if the keep-hostname() option is enabled (keep-hostname(yes)) and the message contains a hostname.

use-fqdn()
Type: yes or no
Default: no

Description: Add Fully Qualified Domain Name instead of short hostname. This option can be specified globally, and per-source as well. The local setting of the source overrides the global option if available.

NOTE:

This option has no effect if the keep-hostname() option is enabled (keep-hostname(yes)) and the message contains a hostname.

use-syslogng-pid()
Type: yes or no
Default: no

Description: If the value of this option is yes, then the PID value of the message will be overridden with the PID of the running syslog-ng process.



[9] The byte order mark (BOM) is a Unicode character used to signal the byte-order of the message text.

Collecting the system-specific log messages of a platform

Starting with version 4 F1, syslog-ng PE can automatically collect the system-specific log messages of the host on a number of platforms using the system() driver. If the system() driver is included in the syslog-ng PE configuration file, syslog-ng PE automatically adds the following sources to the syslog-ng PE configuration.

NOTE:

syslog-ng PE versions 4.1-5.0 used an external script to generate the system() source, but this was problematic in certain situations, for example, when the host used a strict AppArmor profile. Therefore, the system() source is now generated internally in syslog-ng PE.

The system() driver is also used in the default configuration file of syslog-ng PE. For details on the default configuration file, see Example 4.1, “The default configuration file of syslog-ng PE”.

Caution:

If syslog-ng PE does not recognize the platform it is installed on, it does not add any sources.

Table 6.4. Sources automatically added by syslog-ng Premium Edition

Platform Message source
AIX
unix-dgram("/dev/log");
FreeBSD
unix-dgram("/var/run/log");
unix-dgram("/var/run/logpriv" perm(0600));
file("/dev/klog" follow-freq(0) program-override("kernel") flags(no-parse));
HP-UX
pipe("/dev/log" pad-size(2048));
Linux
unix-dgram("/dev/log");
file("/proc/kmsg" program-override("kernel") flags(kernel));
Solaris 8
sun-streams("/dev/log");
Solaris 9
sun-streams("/dev/log" door("/etc/.syslog_door"));
Solaris 10
sun-streams("/dev/log" door("/var/run/syslog_door"));

Related Documents

The document was helpful.

Select Rating

I easily found the information I needed.

Select Rating