rsyslog

The rocket-fast system for log processing

Newbie guide to rsyslog

Written by Jan Gerhards

Here are some different guides for people, who never worked with rsyslog. First I’ll explain, how to install rsyslog. Besides, I will explain how to install some packages, which you will need to install rsyslog. There are two important ones and some minor ones. After that, I will show how to do some easy configurations. Questions like how can I configure a module? Or How can I configure the input? Will be answered. In the example I will configure rsyslog to receive messages, filter them for one specific IP and store only the messages in a file. In the end I’ll explain something about easy rulesets. In my example I will try the same like I did with the configuration, but I will work with rulesets.

Before you begin

Please note, there are many ways to distribute rsyslog. But, make sure that the platform you build rsyslog on is the same platform as where it should be used. You cannot build rsyslog on CentOS and use it on Ubuntu. The differences between the platforms are just to big. The same applies to different versions of the same platform. When building on a older platform and using it on a newer version, this may work, but with restrictions. Whereas building on a newer version and using it on a older version will probably not work at all. So, if you build rsyslog from Source and want to use it on another machine, make sure the platform is the same.

Preliminary actions

There are generally two very often needed packages, that you have to install before rsyslog: libestr and libee. These can be downloaded here:

Libestr:       http://libestr.adiscon.com/download/

Libee:         http://www.libee.org/download/

Both are being installed the same, so here is only one step-by-step instruction.

  1. Download the file
    Just download libestr or libee and “cd” into the folder, where you want them.
  2. “tar xzf” the file
    after you “cd” to the folder, where the file is, type “tar xzf -name of file”. Your command line should look like this:

     tar xzf -name of file-
  3. “Cd” into the new folder
    “cd” into the made directory. It will have the same name like the downloaded file. Your command line should look like this:

     cd -name of file-
  4. Run “./configure configure –libdir=/usr/lib –includedir=/usr/include”
    After you “cd” into that file, just run ” ./configure –libdir=/usr/lib –includedir=/usr/include”. Your command line should look like this:

     ./configure --libdir=/usr/lib --includedir=/usr/include
  5. Type “sudo make”
    Just type this and let the Computer work. Your command line should look like this:

     sudo make
  6. Type “sudo make install”
    This is the last step. Like with “sudo make”, just let the computer work. Your command line should look like this

     sudo make install
  7. The package should work now
    Congratulation! You have installed the package! If it doesn’t work properly, you should check if you followed every step right and if you have, contact the support.

There might also be some other packages like libjson0-dev, uuid-dev, bison, flex, libz-dev or python-docutils. These you’ll have to install before installing rsyslog, too. This guide was made on Ubuntu, so if you use any other system, they might be named differently. You can install them with the command

sudo apt-get install -package name-

After you got all the packages, you can install rsyslog. Here is a How to for installing rsyslog.

 

How to install rsyslog

In this guide is explained how to install rsyslog with the download from the homepage.

 

  1. Download rsyslog
    You can download rsyslog from the rsyslog webpage at http://www.rsyslog.com/download/
  2. “tar xzf” the file
    Open a terminal.  Then you “cd” to where you want the file and then type “tar xzf -name of downloaded file”. Your command line should look like this:

    tar xzf -name of downloaded file-
  3. “cd” into the new folder
    Then “cd” into the made directory. The new directory will have the same name like the downloaded file. Your command line should look like this:

     cd -name of file-
  4. Type “./configure –prefix=/usr”
    You just need to run “./configure –prefix=/usr”. There might be an Error that you need to install some packages to precede with installing. For two specific packages I’ve explained how to install them, because you will need them often. Your command line should look like this:

    ./configure --prefix=/usr
  5. Run “sudo make”
    it’s easy, just run “sudo make” and let the computer work. Your command line should look like this:

     sudo make
  6. Run “sudo make install”
    Just like “sudo make”. Type it, press enter and let the Computer work. Again, there might be some missing packages. Just install them. Your command line should look like this:

     sudo make install
  7. Rsyslog should now be installed
    Congratulation! You have installed rsyslog! You can check the version of rsyslog by typing: “rsyslogd -v”.
    If it doesn’t work properly, you should check if you followed every step right and if you have, contact the support.

 

Now after you installed rsyslog, you have to configure it. How to do this is explained here.

 

Configure rsyslog

In this part I’ll explain some basic configuration steps for rsyslog. We configure rsyslog to recive UDP messages, to filter them depending on the IP of the host and to store them in a file.

  1. How to configure the module
    The module has to be configured first. The general line for this configuration is: “module (load=”im-type of protocol-”). So in our example, where we want UDP, it will look like this:

    Module (load=”imudp”)
  2. How to configure the input for rsyslog
    For the input, you have to give two different information to rsyslog. The first information needed is the protocol type of the input; in my example again UDP. Like in the first line there is an “im-” in front of the protocol-type. The other information is to configure a port for rsyslog, in my example 514. These two information are together in only one line. The line is: “Input (type=”-protocol of input-“port=”-number of port-“). This means for my example, the line has to be

    Input (type=”imudp” port=”514”)
  3. How to configure a filter for fromhost-IPs and store them in a file
    A filter always has, like a normal conditional sentence, an “if…then” part. If you want to configure it to do something with all notes from a specific IP, between “if” and “then” will be the property “$fromhost-ip ==”-IP, you want to filter-”. After this stays a “then” and after the “then” follows an action in brackets, which I will explain later. In my example I want only the notes from the host with the IP 172.19.1.135. So the line will be

    If $fromhost-ip == “172.19.1.135” then [

    After this we have to tell the computer, what to do if that case is given. In this example we want him to store these messages in the file “/var/log/network1.log”. This is an action with the type “omfile”. To configure the file where to store the messages, the action is “action (type=”omfile” File=”-filename-“). So in this example, it will look like this:

    Action (type=”omfile” file=”/var/log/network1.log”)
    ]

 

All the lines together now are

Module (load=“imudp“)

Input (type=”imudp” port=”514”)
If $fromhost-ip == “172.19.1.135“ then [
Action (type=”omfile” File=”/var/log/network1.log”)
]

All in all it means: The input for rsyslog will listen to syslog via UDP on port 514. If the IP from the Computer, which sends the messages, is 172.19.1.135, then the action in the brackets will get activated for these. In the action the messages will be stored in the file /var/log/network1.log.

 

Rsyslog and rulesets

Rulesets are a bit more complicated. A ruleset is a set of rules, as the name implies. These are bound to an input. This works by adding an option to the input, namely “ruleset=”-rulesetname-“”. For example, if I want to bind a ruleset “rs1” to a input the line will look like this:

Input (type=”imudp” port=”514” ruleset=”rs1”)

But you still have to define, what the ruleset should do. In this guide I will limit myself to explain, how to create a ruleset, which has one action: to store all the messages in a file. In my example I want to store the messages in the file /var/log/network1.log”.

You define a ruleset like the normal configuration. To define it, you first name it with ruleset (name=”-rulesetname-“). After this you write what it does, in my example the action action (type=”omfile” file=”/var/log/network1.log”). This action you write in these curly brackets: {}.

So my full example looks like this

Module (load=”imudp”)

Input (type=”imudp” port=”514” ruleset=”rs1”)

Ruleset (name=”rs1”) {
Action (type=”omfile” file=”/var/log/network1.log”)
}

In that second example for configurations you can see, how to store all messages from the input into a file by using a ruleset. A rulesset can consist of multiple rules, but without binding it to the input it is useless. It can be bound to an input multiple times or even other rulesets can be called.

 

Final Conclusion

In this guide I explained how to install rsyslog, how to configure it and how to use rulesets. After you read this guide you are able to do exactly this: you can install rsyslog, configure it and have basic knowlege about rulesets. If you want to learn more about rsyslog, how to configure it or about rulesets, you can find information in the other guides or in the documentation.

6 thoughts on “Newbie guide to rsyslog

  1. I Don’t get it…

    I tried following the steps above, but turned out I had to find all those source packages to get rsyslog to compile… So after 3 hours of trying to hunt everything down, I just went with installing rsyslog from the Adiscon repository. It installs fine, but when I tried the config above:

    Module (load=“imupd“)

    Input (type=”imudp” port=”514”)
    If $fromhost-ip == “172.19.1.135“ then [
    Action (type=”omfile” File=”/var/log/network1.log”)
    ]

    I get errors:

    2013-09-25T17:07:48.438379-04:00 whml29128 rsyslogd: [origin software="rsyslogd" swVersion="7.4.4″ x-pid="5494″ x-info="http://www.rsyslog.com"] start
    2013-09-25T17:07:48.435870-04:00 whml29128 rsyslogd-2066: could not load module ‘/lib64/rsyslog/imupd.so’, dlopen: /lib64/rsyslog/imupd.so: cannot open shared object file: No such file or directory
    [try http://www.rsyslog.com/e/2066 ]
    2013-09-25T17:07:48.435958-04:00 whml29128 rsyslogd-2209: input module name ‘imudp’ is unknown [try http://www.rsyslog.com/e/2209 ]
    2013-09-25T17:07:48.435962-04:00 whml29128 rsyslogd-2207: error during parsing file /etc/rsyslog.conf, on or before line 3: parameter ‘port’ not known — typo in config file? [try http://www.rsyslog.com/e/2207 ]
    2013-09-25T17:07:48.435970-04:00 whml29128 rsyslogd-2207: error during parsing file /etc/rsyslog.conf, on or before line 5: invalid character ‘[‘ – is there an invalid escape sequence somewhere? [try http://www.rsyslog.com/e/2207 ]
    2013-09-25T17:07:48.436024-04:00 whml29128 rsyslogd-2207: error during parsing file /etc/rsyslog.conf, on or before line 7: invalid character ‘]’ – is there an invalid escape sequence somewhere? [try http://www.rsyslog.com/e/2207 ]

    the other rsyslog config I had (which was full of backslashes and harder to understand) works, but I like how clearer your config looks and I really did enjoy the way you explained it. But that doesn’t help if it doesn’t work…

    At one point I even started thinking that there might be different versions of Rsyslog by different people?

    What am I missing here???

    Thanks!

    Yannick.

  2. You possibly need to specify different folder to install the modules in. You can check your /usr/lib folder if the modules are existing there.

    Try to do the configure with "–libdir=/usr/lib64 –sbindir=/usr/sbin" instead of –prefix=/usr.

  3. I always got #011 instead of blank character. such like

    MSWinEventLog#0111#011Security#011911311#011 Feb 28 13:49:01 2014#0114624#011Microsoft-Windows-Security-Auditing#011RESOURCEPRO0\Freya_Lu#011N/A#011Success Audit#011RSP-FSClus-A.resourcepro0.resourcepro.com#011Logon#011#011An account was successfully logged on

    would you please help me find out the way to change #011 instead of blank character.

  4. Ahh, I see my mistake, thanks Bjorn!

    Sorry for not replying earlier, I didn’t get any notifications for replies to my comment… Just happened to pass by today…

    Y.

  5. Given that this is a beginner’s guide, it will be nice if you can explain what is "the module" and the location of the module configuration file.

Comments are closed.