FLUENT-BIT

FluentBit collects, parses, and filters messages from containers and stores them in Loki. The fluent-bit.conf and parsers.conf configuration files are located in /opt/dppm/planr/logging/fluent-bit.

[SERVICE]
    Flush        5
    Daemon       Off
    Parsers_File parsers.conf

[INPUT]
    Name        forward
    Listen      0.0.0.0
    Port        24224


[FILTER]
    Name         parser
    Parser       docker
    Match        *
    Key_Name     log
    Reserve_Data true
    Preserve_Key false

[Output]
    Name grafana-loki
    Match planr
    Url ${LOKI_URL}
    RemoveKeys container_id,log
    Labels {service_name="planr"}
    LabelKeys level,source
    BatchWait 1s
    BatchSize 1001024
    LineFormat json

The SERVICE section defines the general Fluent Bit settings:

  • Flush 5 — interval, in seconds, at which Fluent Bit sends collected data (logs) to Loki;
  • Daemon Off — specifies that Fluent Bit does not run in the background as a daemon;
  • Parsers_File parsers.conf — specifies the file containing parser definitions (log formats).

The INPUT section defines the input data, specifying where Fluent Bit receives logs from.

  • Name forward — input plugin used by Fluent Bit to receive data. Here, the forward plugin receives data over the network using the Fluentd Forward protocol;
  • Listen 0.0.0.0 — specifies that Fluent Bit listens on all available network interfaces;
  • Port 24224 — port on which Fluent Bit receives incoming data.

FILTER processes and modifies incoming data before sending it to outputs. This example uses a parser to process data from Docker containers.

  • Name parser — filter type. The parser filter applies parsers to process data;
  • Parser docker — specifies the parser for Docker logs;
  • Match _ — pattern used to match incoming data to the filter. The _ character indicates that the filter applies to all input data;
  • Key_Name log — specifies the data field to parse, in this case the field named log;
  • Reserve_Data true — retains the original data after processing by the filter;
  • Preserve_Key false — removes the original field, log in this case, after parsing.

OUTPUT sends data to Grafana Loki.

  • Name grafana-loki — plugin for sending data to Grafana Loki, which collects and stores logs;
  • Match * — sends all data (all log streams);
  • Url ${LOKI_URL} — destination URL defined in docker-compose.yml: LOKI_URL=http://loki:3100/loki/api/v1/push;
  • RemoveKeys container_id — removes container_id keys from outgoing data to avoid sending unnecessary fields to Loki;
  • Labels {service_name="planr"} — adds the static label service_name="planr" to each log stream. Loki uses these labels to simplify log searches and filtering;
  • LabelKeys level, source — specifies which log keys to use as dynamic labels. Here, labels are added based on the level (log level) and source (data source) fields;
  • BatchWait 1s — Fluent Bit waits 1 second before sending a batch of data;
  • BatchSize 1001024 — maximum batch size: 1 MB (1001024 bytes);
  • LineFormat json — sends data in JSON format.

To save logs to a file, edit fluent-bit.conf and add another Output section:

[Output]
    Name file
    Match *
    Path /fluent-bit/log/output_test
  • Name file — the file output plugin writes data received through an input plugin to a file;
  • Match * — sends all data (all log streams);
  • Path — directory path for storing files.

Next, modify docker-compose.yml. To mount a local folder in the container's file system, map the host folder to a folder in the container in the volumes section of the fluent-bit service definition in /opt/dppm/planr/docker-compose.yml. For example:

fluent-bit:
    image: grafana/fluent-bit-plugin-loki:3.1.0
    container_name: fluent-bit
    restart: *default-restart-policy
    environment:
      - LOKI_URL=http://loki:3100/loki/api/v1/push
    volumes:
    # When using Portainer, specify the absolute path to the configuration files.
    # For example:
      # - /opt/dppm/planr/logging/fluent-bit:/fluent-bit/etc/
      # - ./logging/fluent-bit:/fluent-bit/etc/
      - ./logging/output_test:/fluent-bit/log/output_test
    networks:
      planr:
        ipv4_address: ${DOCKER_NETWORK_PREFIX:-172.41.0}.254
    profiles : ['logging', 'all']

Here, ./logging/output_test is the local folder, and /fluent-bit/log/output_test is the folder for storing logs in the container. Run ./start.sh to apply the changes.

Configuring Fluent Bit to Send Logs to rsyslog or syslog-ng

If you use the rsyslog or syslog-ng logging service, add the following sections to the Fluent Bit configuration:

[FILTER]
    Name   rewrite_tag
    Match  planr
    Rule   $log.command_name (auth.(local|kerberos|openid|saml|validateApiKey|logout))|(user.(setState|setPassword|create|register|disconnect|delete|import|changeForgottenPassword))|(admin.(create|delete|setState|setPassword))|(role.(create|update|delete)) InfoSec true

The rewrite_tag filter:

  • Name rewrite_tag — specifies the filter type used to change tags;
  • Match planr — applies the filter to logs tagged planr;
  • Rule — defines a rule that checks whether the log.command_name field contains the specified values.
[FILTER]
    Name modify
    Match InfoSec
    Add hostname localhost
    Add appname Plan-R
    # Add vendor Digital_Practices
    # Add product Plan-R

The modify filter modifies logs tagged InfoSec:

  • Name modify — specifies the filter type used to modify log fields;
  • Match InfoSec — applies the filter to logs tagged InfoSec;
  • Add hostname localhost — adds a hostname field with the value localhost;
  • Add appname Plan-R — adds an appname field with the value Plan-R;
  • The vendor and product lines are commented out. Uncomment them to add these fields to the logs.
[OUTPUT]
    name                 syslog
    match                InfoSec
    host                 your_host
    port                 514
    mode                 tcp
    syslog_format        rfc5424
    syslog_maxsize       2048
    syslog_hostname_key  hostname
    syslog_appname_key   appname
    syslog_message_key   log

The syslog output plugin:

  • name syslog — specifies the output type: Syslog;
  • match InfoSec — sends only logs tagged InfoSec to the output;
  • host — server to which logs are sent;
  • port 514 — standard Syslog port for sending messages;
  • mode tcp — uses TCP to transmit data;
  • syslog_format rfc5424 — Syslog message format defined by RFC5424;
  • syslog_maxsize 2048 — maximum log message size: 2048 bytes;
  • syslog_hostname_key hostname — key of the hostname field used in Syslog messages;
  • syslog_appname_key appname — key of the appname field used in logs, Plan-R in this case;
  • syslog_message_key log — key containing the main log message.

Also, in the rsyslog configuration file /etc/rsyslog.conf, uncomment the following sections that open UDP/TCP port 514 used by the rsyslog (syslog-ng) service.

register image

After making the changes, restart rsyslog using:

sudo systemctl restart rsyslog

For more information about configuring Fluent Bit, see https://docs.fluentbit.io/manual/concepts/data-pipeline

Configuring System Event Forwarding via Syslog Using Wazuh SIEM as an Example

Wazuh is a modern, multifunctional, open-source SIEM system that combines intrusion detection, protection of information systems against a wide range of threats, and security event management in a single solution.

Sending All System Events

To configure fluent-bit to send all logs (events) in syslog format to the Wazuh monitoring system, add another OUTPUT section to fluent-bit.conf.

[OUTPUT]
    name                 syslog
    match                *
    host                 your_wazuh_host
    port                 514
    mode                 udp
    syslog_format        rfc5424
    syslog_maxsize       2048
    syslog_hostname_key  hostname
    syslog_appname_key   appname
    syslog_message_key   log

where:

  • name syslog — specifies the output type: Syslog;
  • match — sends all logs to the output;
  • host your_wazuh_host — host where the Wazuh monitoring system is deployed;
  • port 514 — standard Syslog port for sending messages;
  • mode udp — uses UDP to transmit data;
  • syslog_format rfc5424 — Syslog message format defined by RFC5424;
  • syslog_maxsize 2048 — maximum log message size: 2048 bytes;
  • syslog_hostname_key hostname — key of the hostname field used in Syslog messages (optional);
  • syslog_appname_key appname — key of the appname field used in logs, Plan-R in this case;
  • syslog_message_key log — key containing the main log message.

Attention! This example uses UDP port 514 to send logs. Ensure that this port is open on your Wazuh server by running the following command in the terminal:

netstat -pnltu | grep 514

After changing the configuration, restart fluent-bit.

For more information about configuring the syslog output plugin, see the official Fluent Bit documentation: https://docs.fluentbit.io/manual/pipeline/outputs/syslog

Filtering System Events Sent to Wazuh

To filter PLAN-R system events sent to the Wazuh monitoring system, configure fluent-bit to send only the required logs (events) in syslog format. Follow Configuring Fluent Bit to Send Logs to rsyslog or syslog-ng, skipping the paragraph about configuring rsyslog (syslog-ng).

The fluent-bit configuration should then contain the following sections:

[FILTER]
    Name   rewrite_tag
    Match  planr
    Rule   $log.command_name (auth.(local|kerberos|openid|saml|validateApiKey|logout))|(user.(setState|setPassword|create|register|disconnect|delete|import|changeForgottenPassword))|(admin.(create|delete|setState|setPassword))|(role.(create|update|delete)) InfoSec true

[FILTER]
    Name modify
    Match InfoSec
    Add hostname localhost
    Add appname Plan-R
    # Add vendor Digital_Practices
    # Add product Plan-R    

[OUTPUT]
    name                 syslog
    match                InfoSec
    host                 your_wazuh_host
    port                 514
    mode                 udp
    syslog_format        rfc5424
    syslog_maxsize       2048
    syslog_hostname_key  hostname
    syslog_appname_key   appname
    syslog_message_key   log

Here, host your_wazuh_host specifies the host where the Wazuh monitoring system is deployed.

Attention! This example uses UDP port 514 to send logs. Ensure that this port is open on your Wazuh server by running the following command in the terminal:

netstat -pnltu | grep 514

After changing the configuration, restart fluent-bit.

In this example, the rewrite_tag filter is preconfigured to accept specific commands. You can add the required commands to the Rule line. Rule defines a rule that checks whether the log.command_name field contains the specified values. For the complete command list, see System Event List.

For example, to send the "Test an Active Directory realm connection" event to the Wazuh logs:

Command Description
activedirectory.test Test an Active Directory realm connection

configure the rewrite_tag filter as follows:

[FILTER]
    Name   rewrite_tag
    Match  planr
    Rule   $log.command_name (activedirectory.test) InfoSec true

where:

  • Name rewrite_tag — specifies the filter type used to change tags;
  • Match planr — applies the filter to logs tagged planr;
  • Rule $log.command_name (activedirectory.test) InfoSec true — defines a rule that checks the command_name field within the log structure. The rule matches if the value is the event (command) name activedirectory.test;
  • InfoSec — new tag assigned to the record when the condition is met. The record receives the InfoSec tag instead of the original planr tag;
  • true — retains the original record with its original tag, planr, while its copy receives the new tag, InfoSec.

register image

Add the required commands (events) to the rule using the following syntax:

Rule   $log.command_name (activedirectory.test)|(user.getByIds)|(license.load) InfoSec true

For more information about configuring the rewrite tag filter, see the official Fluent Bit documentation: https://docs.fluentbit.io/manual/pipeline/filters/rewrite-tag

Configuring wazuh-manager

Next, edit wazuh_manager.conf. Depending on the deployment method, this configuration file may be located at /your_host/wazuh-docker/single-node/config/wazuh_cluster/wazuh_manager.conf. This example uses a Docker deployment of Wazuh. In the global section of wazuh_manager.conf, change the value in <logall_json>no</logall_json> to yes. Also add another remote section to wazuh_manager.conf:

  <remote>
    <connection>syslog</connection>
    <port>514</port>
    <protocol>udp</protocol>
    <allowed-ips>your_fluent-bit_host</allowed-ips>
  </remote>

where:

  • <connection> specifies the incoming connection type;
  • <port> specifies the port used to listen for incoming Syslog messages from endpoints. This example uses port 514;
  • <protocol> specifies the protocol used to listen for incoming Syslog messages from endpoints. Allowed values: tcp or udp. This example uses udp;
  • <allowed-ips> specifies the IP address or network range of endpoints forwarding events to the Wazuh server;
  • your_fluent-bit_host specifies the host from which Fluent Bit sends logs to Wazuh.

The modified wazuh_manager.conf file should look as follows:

register imagewazuh_manager.conf configuration

Restart wazuh-manager to apply the changes.

Configuring Filebeat

Next, modify filebeat.yml. In this example, Wazuh is installed in Docker, so filebeat.yml is located at /var/lib/docker/volumes/single-node_filebeat_etc/_data/filebeat.yml. Set archives:enabled to true in filebeat.yml:

register imagefilebeat.yml configuration

Restart the wazuh-indexer and wazuh-manager containers to apply the changes. If Wazuh is installed without Docker, restart filebeat and wazuh-manager by running:

systemctl restart filebeat

systemctl restart wazuh-manager

Now configure the display of logs sent from fluent-bit in syslog format in wazuh-dashboard. Open Dashboards Management, select Index patterns, and click Create index pattern.

register imagewazuh-dashboard interface

Set Index pattern name to wazuh-archives-*, enable Include system and hidden indices, and click Next step.

register imagewazuh-dashboard interface. Index pattern name

In the next step, set Time field to @timestamp and click Create index pattern.

register imagewazuh-dashboard interface. Create index pattern

Next, open Discover in wazuh-dashboard, select the wazuh-archives-* index you created in Index patterns, and click Refresh. Logs from fluent-bit should appear in the output.

register imagewazuh-dashboard interface. Discover

Let's examine the log contents in more detail. The log shown above was generated by the "Test an Active Directory realm connection" system event. It contains the following important information:

  • "level":"info" — indicates an informational message;
  • "time":1744203465051 — timestamp;
  • "client_ip":"172.41.0.1" — IP address from which the resource was accessed;
  • "command_name":"activedirectory.test" — name of the executed command;
  • "user_id":"594b7360-3364-4273-b460-fbc13f5a5807" — user identifier;
  • "user_login":"superadmin" — user login;
  • "request_source":"admin" — request source.

608.0-5d1f26c7