How to Parse Syslog Messages
Last updated
Was this helpful?
Last updated
Was this helpful?
Syslog is a popular protocol that virtually runs on every server. It is used to collect all kinds of logs. The problem with syslog
is that services have a wide range of log formats, and no single parser can parse all syslog
messages effectively.
In this tutorial, we will show how to use Fluentd to filter and parse different syslog
messages robustly.
A basic understanding of Fluentd
A running instance of rsyslogd
In this guide, we assume you are running on Ubuntu.
rsyslogd
Create /etc/rsyslogd.d/90-fluentd.conf
and append the following line:
Then restart the rsyslogd
service:
This tells rsyslogd
to forward logs to port 5140 to which Fluentd will listen.
In this section, we will evolve our Fluentd configuration step-by-step.
syslog
MessagesFirst, let's configure Fluentd to listen to syslog messages.
Open /etc/fluent/fluentd.conf
and put the following configuration:
This is the most basic setup: it listens to all syslog messages and outputs them to the standard output.
Now please restart fluentd
:
Let's confirm data is coming in:
syslog
Messages from sudo
Now, let's look at a sudo
message like this one:
For security reasons, it is worth knowing which user performed what using sudo
. In order to do so, we need to parse the message field. In other words, we need to extract syslog
messages from sudo
and handle them differently.
Here is the final configuration:
Then restart fluentd
:
Let's execute some comment with sudo
:
Now, you should have a line like this in /var/log/fluent/fluentd.log
:
There it is, as you can see in the line!
Fluentd makes it easy to ingest syslog
events. You can immediately send data to the output systems like MongoDB and Elasticsearch, but also you can do filtering and further parsing inside Fluentd before passing the processed data onto the output destinations.
For this purpose, we can use the filter plugin. It examines the fields of events, and filter them based on regular expression patterns. In the following example, Fluentd filters out events that come from sudo
and contain command data:
Now let's extract some information from syslog
messages. For this purpose, we use another plugin called . With this plugin, you can parse the content of a field using a regular expression.
If this article is incorrect or outdated, or omits critical information, please . is an open-source project under . All components are available under the Apache 2 License.