A source is where syslog-ng receives log messages. Sources consist of one or more drivers, each defining where and how messages are received.
To define a source, add a source statement to the syslog-ng configuration file using the following syntax:
source <identifier> { source-driver(params); source-driver(params); ... };
![]() |
Example 3.3. A simple source statement |
|---|---|
|
The following source statement receives messages on the TCP port
source s_demo_tcp { tcp(ip(10.1.2.3) port(1999)); };
|
![]() |
Example 3.4. A source statement using two source drivers |
|---|---|
|
The following source statement receives messages on the
source s_demo_two_drivers {
tcp(ip(10.1.2.3) port(1999));
udp(ip(10.1.2.3) port(1999)); };
|
Define a source only once. The same source can be used in several log paths.
Duplicating sources causes syslog-ng to open the source (TCP/IP port, file, etc.) more
than once, which might cause problems. For example, include the
/dev/log file source only in one source statement, and use this
statement in more than one log path if needed.
To collect log messages on a specific platform, it is important to know how the native
syslogd communicates on that platform. The following table
summarizes the operation methods of syslogd on some of the tested
platforms:
| Platform | Method |
|---|---|
| Linux | A SOCK_STREAM unix socket named
/dev/log; some of the distributions switched
over to using SOCK_DGRAM, though applications
still work with either method. |
| BSD flavors | A SOCK_DGRAM unix socket named
/var/run/log. |
| Solaris (2.5 or below) | An SVR4 style STREAMS device named
/dev/log. |
| Solaris (2.6 or above) | In addition to the STREAMS device used in
earlier versions, 2.6 uses a new multithreaded IPC method called door.
By default the door used by syslogd is
/etc/.syslog_door. |
| HP-UX 11 or later | HP-UX uses a named pipe called /dev/log that is
padded to 2048 bytes, e.g., source s_hp-ux {pipe ("/dev/log"
pad_size(2048)}. |
| AIX 5.2 and 5.3 | A SOCK_STREAM or
SOCK_DGRAM unix socket called
/dev/log. |
Table 3.1. Communication methods used between the applications and syslogd
Each possible communication mechanism has a corresponding source driver in syslog-ng.
For example, to open a unix socket with SOCK_DGRAM style
communication use the driver unix-dgram. The same socket using
the SOCK_STREAM style — as used under Linux —
is called unix-stream.
![]() |
Example 3.6. Source statement on a Linux based operating system |
|---|---|
|
The following source statement collects the following log messages:
source s_demo {
internal();
udp(ip(0.0.0.0) port(514));
unix-stream("/dev/log"); };
|
The following table lists the source drivers available in syslog-ng.
| Name | Description |
|---|---|
| internal() | Messages generated internally in syslog-ng. |
| file() | Opens the specified file and reads messages. |
| pipe(), fifo | Opens the specified named pipe and reads messages. |
| program() | Opens the specified application and reads messages from its standard output. |
| sun-stream(), sun-streams() | Opens the specified STREAMS device on Solaris
systems and reads incoming messages. |
| syslog() | Listens for incoming messages using the new IETF-standard syslog protocol. |
| tcp(), tcp6() | Listens on the specified TCP port for incoming messages using the BSD-syslog protocol over IPv4 and IPv6 networks, respectively. |
| udp(), udp6() | Listens on the specified UDP port for incoming messages using the BSD-syslog protocol over IPv4 and IPv6 networks, respectively. |
| unix-dgram() | Opens the specified unix socket in SOCK_DGRAM
mode and listens for incoming messages. |
| unix-stream() | Opens the specified unix socket in SOCK_STREAM
mode and listens for incoming messages. |
Table 3.2. Source drivers available in syslog-ng
For a complete description of the parameters of the above drivers, see Section 8.1, “Source drivers”.
All messages generated internally by syslog-ng use this special source. To collect warnings, errors and notices from syslog-ng itself, include this source in one of your source statements.
internal()
The syslog-ng application will issue a warning upon startup if none of the defined log paths reference this driver.
Periodically, syslog-ng sends a message containing statistics about the
received messages, and about any lost messages since the last such message. It
includes a processed entry for every source and
destination, listing the number of messages received or sent, and a
dropped entry including the IP address of the server
for every destination where syslog-ng has lost messages. The
center(received) entry shows the total number of
messages received from every configured sources.
The following is a sample log statistics message for a configuration that has
a single source (s_local) and a network and a local file
destination (d_network and
d_local, respectively). All incoming messages are sent to
both destinations.
Log statistics;
dropped='tcp(AF_INET(192.168.10.1:514))=6439',
processed='center(received)=234413',
processed='destination(d_tcp)=234413',
processed='destination(d_local)=234413',
processed='source(s_local)=234413'
Log statistics can be also retrieved on-demand using the echo STATS |
nc -U var/run/syslog-ng.ctl command. This returns a list of source
groups and destinations, as well as the number of processed messages for each.
The verbosity of the statistics can be set using the
stats_level() option. See Section 8.9, “Global options” for details.
![]() |
Note |
|---|---|
To query the statistics, you need the OpenBSD-style netcat application. The netcat included in most Linux distributions is a GNU-style version that is not suitable to query the statistics of syslog-ng. An alternative is to use the socat application: echo STATS | socat -vv UNIX-CONNECT:/opt/syslog-ng/var/run/syslog-ng.ctl -. |
Collects log messages from plain-text files, e.g., from the logfiles of an Apache webserver.
The syslog-ng application notices if a file is renamed or replaced with a new file, so it can correctly follow the file even if logrotation is used. When syslog-ng is restarted, it records the position of the last sent log message, and continues to send messages from this position after the restart.
The file driver has a single required parameter specifying the file to open. For the list of available optional parameters, see Section 8.1.2, “file()”.
Declaration:
file(filename);
In syslog-ng PE, the filename (but not the pathname)
may include wildcard characters (e.g., *). Note that when
using wildcards in filenames, always set how often syslog-ng should check the file
for new messages using the follow_freq() parameter.
When using wildcards, syslog-ng PE monitors every matching file, and can receive new log messages from any of the files. However, monitoring (polling) many files (i.e., more than ten) has a significant overhead and may affect performance. On Linux this overhead is not so significant, because syslog-ng PE uses the inotify feature of the kernel.
The kernel usually sends log messages to a special file
(/dev/kmsg on BSDs, /proc/kmsg on
Linux). The file() driver reads log messages from such files.
The syslog-ng application can periodically check the file for new log messages if
the follow_freq() option is set.
![]() |
Note |
|---|---|
|
On Linux, the When using syslog-ng to read messages from the |
The pipe driver opens a named pipe with the specified name and listens for messages. It is used as the native message delivery protocol on HP-UX.
The pipe driver has a single required parameter, specifying the filename of the pipe to open. For the list of available optional parameters, see Section 8.1.3, “pipe()”.
Declaration:
pipe(filename);
![]() |
Note |
|---|---|
As of syslog-ng Open Source Edition 3.0.2, pipes are created automatically. In earlier versions, you had to create the pipe using the mkfifo(1) command. |
Pipe is very similar to the file() driver, but there are a
few differences, for example pipe() opens its argument in
read-write mode, therefore it is not recommended to be used on special files like
/proc/kmsg.
![]() |
Warning |
|---|---|
It is not recommended to use |
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 |
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 Section 8.1.5, “sun-streams() driver”.
Declaration:
sun-streams(name_of_the_streams_device door(filename_of_the_door));
The syslog() driver enables to receive messages from the
network using the new standard syslog protocol and message format (also called
IETF-syslog protocol; described in RFC 5424-28, see Section 2.19.2, “IETF-syslog messages”). UDP, TCP, and TLS-encrypted TCP can
all be used to transport the messages.
For the list of available optional parameters, see Section 8.1.6, “syslog()”.
Declaration:
syslog(ip() port() transport() options());
![]() |
Example 3.13. 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. See Section 8.10, “TLS options” for details on the encryption settings. 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')
)
);};
|
The tcp(), tcp6(),
udp(), udp6() drivers can receive
messages from the network using the TCP and UDP networking protocols. The
tcp6() and udp6() drivers use the
IPv6 network protocol, while tcp() and
udp() use IPv4.
UDP is a simple datagram oriented protocol, which provides "best effort service" to transfer messages between hosts. It may lose messages, and no attempt is made at the protocol level to retransmit such lost messages. The BSD-syslog protocol traditionally uses UDP.
TCP provides connection-oriented service, which basically means that the path of the messages is flow-controlled. Along this path, each message is acknowledged, and retransmission is done for lost packets. Generally it is safer to use TCP, because lost connections can be detected, and no messages get lost, assuming that the TCP connection does not break. When a TCP connection is broken the 'in-transit' messages that were sent by syslog-ng but not yet received on the other side are lost. (Basically these messages are still sitting in the socket buffer of the sending host and syslog-ng has no information about the fate of these messages).
The tcp() and udp() drivers do not
have any required parameters. By default they bind to the
0.0.0.0:514 address, which means that syslog-ng will listen
on all available interfaces, port 514. To limit accepted connections to only one
interface, use the localip() parameter as described below.
For the list of available optional parameters, see Section 8.1.7, “tcp(), tcp6(), udp() and udp6()”.
Declaration:
tcp([options]);
udp([options]);
![]() |
Note |
|---|---|
The tcp port 514 is reserved for use with rshell, so select a different port if syslog-ng and rshell is used at the same time. |
If you specify a multicast bind address to udp() and
udp6(), syslog-ng will automatically join the necessary
multicast group. TCP does not support multicasting.
The syslog-ng Premium Edition application supports TLS (Transport Layer Security, also known as SSL) for the tcp() and tcp6() drivers. See the TLS-specific options below and Section 3.13, “Encrypting log messages with TLS” for details. For the list of available optional parameters, see Section 8.1.5, “sun-streams() driver”.
![]() |
Example 3.14. Using the udp() and tcp() drivers |
|---|---|
|
A simple udp() source with default settings. source s_udp { udp(); };# An UDP source with default settings.
A TCP source listening on the localhost interface, with a limited number of connections allowed. source s_tcp { tcp(ip(127.0.0.1) port(1999) max-connections(10)); };
A TCP source listening on a TLS-encrypted channel. source s_tcp { tcp(ip(127.0.0.1) port(1999)
tls(peer-verify('required-trusted')
key_file('/opt/syslog-ng/etc/syslog-ng/syslog-ng.key')
cert_file('/opt/syslog-ng/etc/syslog-ng/syslog-ng.crt')));
};
A TCP source listening for messages using the IETF-syslog message format. Note
that for transferring IETF-syslog messages, generally you are recommended to use
the source s_tcp_syslog { tcp(ip(127.0.0.1) port(1999) flags(syslog-protocol) ); };
|
The unix-stream() and unix-dgram()
drivers open an AF_UNIX socket and start listening on it for
messages. The unix-stream() driver is primarily used on Linux
and uses SOCK_STREAM semantics (connection oriented, no
messages are lost); while unix-dgram() is used on BSDs and
uses SOCK_DGRAM semantics: this may result in lost local
messages if the system is overloaded.
To avoid denial of service attacks when using connection-oriented protocols, the
number of simultaneously accepted connections should be limited. This can be
achieved using the max-connections() parameter. The default
value of this parameter is quite strict, you might have to increase it on a busy
system.
Both unix-stream and unix-dgram have a single required argument that specifies the filename of the socket to create. For the list of available optional parameters, see Section 8.1.8, “unix-stream() and unix-dgram()”
Declaration:
unix-stream(filename [options]);
unix-dgram(filename [options]);
![]() |
Note |
|---|---|
|
The difference between the unix-stream and unix-dgram drivers is similar to the difference between the TCP and UDP network protocols. Use the following guidelines to select which driver to use in a particular situation:
Choose unix-stream if you would choose TCP (stream) instead of UDP (datagram). The unix-stream driver offers the following features:
Increased reliability
Ordered delivery of messages
Client-side notification of failures
Choose unix-dgram if you would choose TCP (stream) over UDP (datagram). The unix-dgram driver offers the following features:
Decreased possibility of Dos by opening too many connections (a local vulnerability)
Less overhead
However, the client does not notice if a message is lost when using the unix-dgram driver.
© 2007-2010 BalaBit IT Security
Please send your comments or documentation bugs to: documentation@balabit.com