tuto:monitoring:graylog_to_crowdsec

Ceci est une ancienne révision du document !


Bridge Graylog and Crodwsec

Crowdsec's architecture allows running several agents, each parsing the local logs on the server it's running, and sending events to a local API. While this approach works and is flexible, it might not be the most efficient. In my case, all my server are already sending their logs to a Graylog instance. Running one crowdsec agent on all of those VM would be a waist :

  • I really like the idea behind the Journal (systemd-journald), it's very conveniant. But it has a major drawback : it's slow has hell ! Better have everything on SSD, or reading the journal will slows everything down. As I already have journalbeat collecting logs from the Journal, I prefer not adding another Journal reader, which will slows things down even further
  • Let's assume we have 40 VM on which we'd like crowdsec agent running. This means something like 40x80MB = 3.2GB of RAM, just for crowdsec
  • I have to manage crowdsec conf on those 40 VM. Of course, ansible to the rescue, it wouldn't require manual config everywhere, but I'd still have to setup which logs to parse on which VM, which scenario to apply etc.

So, I looked for an alternative setup, and here's what I came with :-)

As I already have all my logs in Graylog, it'd be better to send this stream of logs to a single crowdsec installation. But, for now, crowdsec doesn't have network logs input, it can only reads files and the Journal (I've opened a ticket for this). So, the idea is to somehow forward the logs I want fro Graylog to a small daemon, which would write logs for crowdsec to consume.

I wrote a small perl daemon, named g2cs (Graylog to Crowdsec). It's available here. It'll simply listen on a UDP port, waiting for messages to consume from Graylog. It assumes the logs are sent using the CEF format (so, this is the format we'll choose later, for Graylog output). Using a structured log format between Graylog and g2cs allows some filtering in g2cs (for example, to recognize nginx log and put them in a dedicated file, separated from the general syslog). This daemon is very simple

perl g2cs.pl --port 514 --logdir /tmp/crowdsec/ --maxlines 20000
  • Port is the port number g2cs will listen on
  • logdir is where it'll write logs for crowdsec to consume. Inside this logdir, g2cs will create sub directories, like :
  • tuto/monitoring/graylog_to_crowdsec.1614953782.txt.gz
  • Dernière modification: 05/03/2021 15:16
  • de dani