rsyslog is since version 6.1.3 capable of using a output module called "ommongodb" to write log messages to mongodb. To achieve this, several packages are needed:
mongodb mongodb-server php-pecl-mongo libmongo-client libglib2.0-dev
These and of course rsyslog are needed. The packages are easily installed via a package manager. And the installation steps for rsyslog are the usual ones. Except for the "Configure". Please make sure to include "–enable-ommongodb". And the other features you plan to use of course.
./configure --libdir=/usr/lib --sbindir=/usr/sbin --enable-ommongodb make make install
After this, you need to make some adjustments to the rsyslog.conf. You need to load the module of course and configure an action:
module (load="ommongodb") *.* action(type="ommongodb" server="127.0.0.1")
In this case we send everything to the local MongoDB server. With the default settings, this should work directly. No username or password is needed if it isn’t configured in MongoDB. And the "db" and "collection" will automatically be created. The default database that rsyslog will use is "syslog" and the default name for the collection is "log". These can be changed by various parameters.
To review what is written to the database, simply open a command line and enter "mongo". This is to open the MongoDB Shell. You now need to change the database that is used with
That way all further commands will be used on the database that rsyslog uses. Next we let the shell show us the entries:
Please make sure to use the exact command. Of course there are a lot of other commands that you may find useful. Or information on how to secure the database. Please refer to the MongoDB documentation for that.