Rsyslog

From Wikipedia, the free encyclopedia:

''Rsyslog is an open source software used on UNIX and Unix-like computer systems for forwarding log messages in an IP network. It implements the basic syslog protocol, extends it with content-based filtering, rich filtering capabilities, flexible configuration options and adds important features such as using TCP for transport.''

Emerge
Install :

Add rsyslog to default run level:

After the emerge has finished, rsyslog should work out of the box with the default configuration; at least for local logging.

Start rsyslog by running:

Check file for syslog entries:

Configuration
Basic rsyslog configuration:

Typically messages are logged to files, the file has to be specified with full pathname. Rsyslog uses a simple syntax to filter incoming messages. Syslog messages are classified by facility and severity. According to RFC5424 following severity groups have been defined:

Facility
List of facilities used by rsyslog. Most facilities names are self explanatory. Facilities local0 - local7 common usage is f.e. as network logs facilities for nodes and network equipment. Generally it depends on the situation how to classify logs and put them to facilities. See facilities more as a tool rather than a directive to follow.

Facilities can be adjusted to meet the needs of the user:

Filtering
List of filtering examples *.* -/var/log/syslog *.crit -/var/log/critical mail.none;authpriv.none;cron.none -/var/log/messages
 * Redirect all incoming messages from all facilities and with all severeties to
 * Filter out messages with severity critical and save to file
 * Do NOT redirect facilities mail, authentication and cron and mail to, look for the keyword none

Local logging
Enable local logging from all facilities, to see local events at all. $ModLoad imuxsock.so

Remote logging
To use remote logging to a syslog server, specify a client to log to a specific server or servers. And a server to receive messages sent by clients. Before configuring choose the protocol. Syslog messages can be sent using UDP or TCP. UDP is the default protocol and supported on most platforms. Not all platforms support TCP for syslog.

Client
To enable syslog UDP messages sending add following line to the file. In this example rsyslog sends all facilities and all priorities *.* using protocol UDP @ to remote server 192.168.20.254

*.*      @192.168.20.254

To enable TCP support for syslog messages, put following line to the rsyslog configuraton file, TCP is enabled by adding @@.

*.*      @@192.168.20.254

If desired, hostnames can be substituted in for IP addresses.

Below a example syslog client configuration to send syslog messages to a remote server via TCP.

Server
To Provide UDP log reception and run the server on port 514. Running syslog with UDP is the default configuration.

$ModLoad imudp $UDPServerRun 514

UDP is not a reliable protocol. For more reliability run the server with TCP logging support.

$ModLoad imtcp $InputTCPServerRun 10514

A simple configuration would look like this one:

Database logging
Rsyslog supports logging to following databases:


 * MariaDB
 * MySQL
 * PostgreSQL
 * Oracle

After choosing the database logs will be stored to a proper USE flag needs to be enabled and rsyslog has to be rebuild before continuing. This example uses a MySQL database.

The package ships a SQL script named createDB.sql to create the database layout.

Import the file to create the "Syslog" database.

Create a datebase user for the Syslog database: mysql> grant ALL ON Syslog.* to rsyslog-user@localhost identified by - 'MySecretPassword'; flush privileges;

To provide SQL database logging support, enable the needed module in

$ModLoad ommysql.so

Tell rsyslog to forward all data to the database, add following to the end of the file:

*.* :ommysql:localhost,Syslog,rsyslog-user,MySecretPassword

Finally Restart the rsyslog server to adapt new settings

Templates
Many vendors format their syslog messages differently. If the network equipment logs to a central rsyslog server the difference in logging will be easy to notice. After some time of log dumping it will be difficult to filter the syslog server messages for a certain
 * Date
 * Facility
 * Severity
 * Host
 * Syslogtag
 * ProcessID
 * MessageType
 * Message

To unify syslog messages to a certain or preferred format, Rsyslog uses templates which parse arriving messages and "rewrites" them to the desired format.

To maintain a simple and modular configuration, templates are stored within the directory. To include files stored within the rsyslog.d directory add following line to file:

$IncludeConfig /etc/rsyslog.d/*.conf

Templates should be stored to the directory.

Here a simple template for a cisco IOS host which logs to rsyslogd:

Here a simple template for a ScreenOS host which logs to rsyslogd:

Here a simple template for Linux host which logs to rsyslogd:

Configure rsyslogd which predefined template to apply to which facility, add following template references to the end of the file: local4.* :ommysql:localhost,Syslog,rsyslog-user,MySecretPassword;mysql_cisco local5.* :ommysql:localhost,Syslog,rsyslog-user,MySecretPassword;mysql_netscreen *.*;local4.none;local5.none :ommysql:localhost,Syslog,rsyslog-user,MySecretPassword;mysql_linux
 * All messages arriving at facility local4, are Cisco IOS messages:
 * All messages arriving at facility local5, are ScreenOS messages:
 * All messages arriving at syslog consider as Linux messages, and ignore local4 and local5 facilities which have their own templates.

The following is an example of how the file could look on a syslog server with working templates:

Reload rsyslog server to apply new changes.

Further examples can be found here.

Troubleshooting
Check if a syslog process is running

Verify network configuration

Verify with the command logger, if messages are arriving in at the syslogserver

Following message should appear in the file if rsyslog is working properly:

External resources

 * Rsyslog Templates HOWTO
 * Rsyslog page on Freecode
 * Rsyslog configuration samples
 * RFC 5424