{"id":351,"date":"2025-02-12T21:31:53","date_gmt":"2025-02-12T21:31:53","guid":{"rendered":"https:\/\/blog.lottabytes.com\/?p=351"},"modified":"2025-02-13T17:17:34","modified_gmt":"2025-02-13T17:17:34","slug":"different-logging-approaches","status":"publish","type":"post","link":"https:\/\/blog.lottabytes.com\/index.php\/2025\/02\/12\/different-logging-approaches\/","title":{"rendered":"Different Logging Approaches"},"content":{"rendered":"\n<p>There are many common approaches to logging.  However, since my home environment is running SecurityOnion (SO), I&#8217;m going to focus on three common ones and show how to do an end-to-end configuration with SO.  If you&#8217;re curious about Filebeat, I&#8217;ve already <a href=\"https:\/\/blog.lottabytes.com\/index.php\/2023\/03\/17\/ingesting-external-logs-via-security-onions-elasticsearch\/\" data-type=\"post\" data-id=\"251\">written about it here<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Fluentd<\/h2>\n\n\n\n<p>Fluentd is extremely popular, while providing many options and granular configuration.  That said, it&#8217;s also more work to get started as opposed to the other options that we&#8217;ll discuss.<\/p>\n\n\n\n<p>To get this working you will need to do a few things on the Security Onion side:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Configure an Elastic role with minimal permissions to allow event ingestion.<\/li>\n\n\n\n<li>Create an Elastic user and assign to the newly created role.<\/li>\n\n\n\n<li>Open up the SO firewall to allow Elasticsearch on port 9200.  This is accomplished using the <em>Administration &gt; Configuration &gt; Firewall<\/em> settings.<\/li>\n<\/ol>\n\n\n\n<p>Here&#8217;s the role definition, with associated permissions.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"625\" src=\"https:\/\/blog.lottabytes.com\/wp-content\/uploads\/2025\/02\/image-1-1024x625.png\" alt=\"\" class=\"wp-image-355\" srcset=\"https:\/\/blog.lottabytes.com\/wp-content\/uploads\/2025\/02\/image-1-1024x625.png 1024w, https:\/\/blog.lottabytes.com\/wp-content\/uploads\/2025\/02\/image-1-300x183.png 300w, https:\/\/blog.lottabytes.com\/wp-content\/uploads\/2025\/02\/image-1-768x469.png 768w, https:\/\/blog.lottabytes.com\/wp-content\/uploads\/2025\/02\/image-1.png 1233w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>You can now deploy your Fluentd agent.  I&#8217;m using Ubuntu in this example.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Download the binary\nwget https:\/\/s3.amazonaws.com\/packages.treasuredata.com\/lts\/5\/ubuntu\/jammy\/pool\/contrib\/f\/fluent-package\/fluent-package_5.0.5-1_amd64.deb\n\n# Install Fluentd, which becomes the fluend.service\nsudo dpkg -i fluent-package_5.0.5-1_amd64.deb\n\n# Create the td-agent directory to store position files\nsudo mkdir \/var\/log\/td-agent\nsudo chown _fluentd:_fluentd \/var\/log\/td-agent\/\n\n# Grant the _fluentd user access to read system log files as part of the adm group\nsudo usermod _fluentd -aG adm<\/code><\/pre>\n\n\n\n<p>Next, we need to configure Fluentd (\/etc\/fluentd\/fluentd.conf).  Here&#8217;s a working configuration.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;system> \n  log_level error\n&lt;\/system>\n\n&lt;source>\n  @type tail\n  path \/var\/log\/syslog\n  pos_file \/var\/log\/td-agent\/syslog.pos\n  tag system.log\n  &lt;parse>\n    @type syslog\n    keep_time_key true\n  &lt;\/parse>\n&lt;\/source>\n\n&lt;source>\n  @type tail\n  path \/var\/log\/auth.log\n  pos_file \/var\/log\/td-agent\/auth.pos\n  tag system.auth\n  &lt;parse>\n    @type syslog\n    keep_time_key true\n  &lt;\/parse>\n&lt;\/source>\n\n&lt;filter system.log>\n  @type record_transformer\n  &lt;record>\n    file_location \"\/var\/log\/syslog\"\n  &lt;\/record>\n&lt;\/filter>\n\n&lt;filter system.auth>\n  @type record_transformer\n  &lt;record>\n    file_location \"\/var\/log\/auth.log\"\n    security_event \"true\"\n  &lt;\/record>\n&lt;\/filter>\n\n# The timestamp for syslog doesn't work, as there isn't a year.  The below is a quick workaround to append a new, slightly less accurate timestamp that allows SO to parse it and show time-series data.\n&lt;filter system.*>\n  @type record_transformer\n  enable_ruby true\n  &lt;record>\n    timestamp ${Time.now.utc.iso8601}\n  &lt;\/record>\n&lt;\/filter>\n\n## DOCS: https:\/\/docs.fluentd.org\/output\/elasticsearch\n&lt;match system.* wazuh.*>\n  @type elasticsearch\n  host sec-onion-master.server.com\n  port 9200\n  # This causes it to break, because the permissions are required on the logstash index\n  # logstash_format true\n  user \"filebeat_user\"\n  password \"L0gging123!\"\n  scheme https\n  reconnect_on_error true\n  index_name \"fluentd-\"\n  &lt;buffer tag, time>\n    flush_interval 60s\n    timekey 1m\n    timekey_wait 1m\n  &lt;\/buffer>\n  ssl_verify false\n&lt;\/match>\n<\/code><\/pre>\n\n\n\n<p>When you run into issues you can view the troubleshooting logs at \/var\/log\/fluent\/fluentd.log.  However, be cautioned, often it&#8217;s not very informative, even at a debug log level.<\/p>\n\n\n\n<p>Once things are working, you should be able to create a new Data View against the index_name that you specified in the above file.  This should then show you your incoming logs.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"294\" height=\"412\" src=\"https:\/\/blog.lottabytes.com\/wp-content\/uploads\/2025\/02\/image-2.png\" alt=\"\" class=\"wp-image-358\" srcset=\"https:\/\/blog.lottabytes.com\/wp-content\/uploads\/2025\/02\/image-2.png 294w, https:\/\/blog.lottabytes.com\/wp-content\/uploads\/2025\/02\/image-2-214x300.png 214w\" sizes=\"auto, (max-width: 294px) 100vw, 294px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"360\" src=\"https:\/\/blog.lottabytes.com\/wp-content\/uploads\/2025\/02\/image-4-1024x360.png\" alt=\"\" class=\"wp-image-365\" srcset=\"https:\/\/blog.lottabytes.com\/wp-content\/uploads\/2025\/02\/image-4-1024x360.png 1024w, https:\/\/blog.lottabytes.com\/wp-content\/uploads\/2025\/02\/image-4-300x105.png 300w, https:\/\/blog.lottabytes.com\/wp-content\/uploads\/2025\/02\/image-4-768x270.png 768w, https:\/\/blog.lottabytes.com\/wp-content\/uploads\/2025\/02\/image-4-1536x540.png 1536w, https:\/\/blog.lottabytes.com\/wp-content\/uploads\/2025\/02\/image-4.png 1588w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">rSyslog<\/h2>\n\n\n\n<p>Syslog has been around for a long time, and in my experience is primarily used by networking devices to send events.  However, it&#8217;s still fully supported to use on a client OS.  <\/p>\n\n\n\n<p>First, open the firewall.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"547\" src=\"https:\/\/blog.lottabytes.com\/wp-content\/uploads\/2025\/02\/image-1024x547.png\" alt=\"\" class=\"wp-image-352\" srcset=\"https:\/\/blog.lottabytes.com\/wp-content\/uploads\/2025\/02\/image-1024x547.png 1024w, https:\/\/blog.lottabytes.com\/wp-content\/uploads\/2025\/02\/image-300x160.png 300w, https:\/\/blog.lottabytes.com\/wp-content\/uploads\/2025\/02\/image-768x410.png 768w, https:\/\/blog.lottabytes.com\/wp-content\/uploads\/2025\/02\/image.png 1199w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Once this is opened, you can update the \/etc\/rsyslog\/rsyslog.conf file to begin forwarding log events.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \/etc\/rsyslog.conf configuration file for rsyslog\n#\n# For more information install rsyslog-doc and see\n# \/usr\/share\/doc\/rsyslog-doc\/html\/configuration\/index.html\n#\n# Default logging rules can be found in \/etc\/rsyslog.d\/50-default.conf\n\n\n#################\n#### MODULES ####\n#################\n\nmodule(load=\"imuxsock\") # provides support for local system logging\nmodule(load=\"imklog\" permitnonkernelfacility=\"on\")\n\n###########################\n#### GLOBAL DIRECTIVES ####\n###########################\n\n$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat\n$RepeatedMsgReduction on\n\n#\n# Set the default permissions for all log files.\n#\n$FileOwner syslog\n$FileGroup adm\n$FileCreateMode 0640\n$DirCreateMode 0755\n$Umask 0022\n$PrivDropToUser syslog\n$PrivDropToGroup syslog\n\n$WorkDirectory \/var\/spool\/rsyslog\n\n$IncludeConfig \/etc\/rsyslog.d\/*.conf\n\n# Add in your Security Onion Server here:\n*.* @@sec-onion-master.server.com:514\n<\/code><\/pre>\n\n\n\n<p>All the incoming logs (which can be configured via the files in \/etc\/rsyslog.d\/) will show up in the<em> logs-* <\/em>view, and can easily be filtered using the <em>data_stream.dataset = syslog<\/em> parameter.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"337\" src=\"https:\/\/blog.lottabytes.com\/wp-content\/uploads\/2025\/02\/image-3-1024x337.png\" alt=\"\" class=\"wp-image-360\" srcset=\"https:\/\/blog.lottabytes.com\/wp-content\/uploads\/2025\/02\/image-3-1024x337.png 1024w, https:\/\/blog.lottabytes.com\/wp-content\/uploads\/2025\/02\/image-3-300x99.png 300w, https:\/\/blog.lottabytes.com\/wp-content\/uploads\/2025\/02\/image-3-768x252.png 768w, https:\/\/blog.lottabytes.com\/wp-content\/uploads\/2025\/02\/image-3-1536x505.png 1536w, https:\/\/blog.lottabytes.com\/wp-content\/uploads\/2025\/02\/image-3.png 1585w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>That&#8217;s it!  Now you have three different methods to forward logs to your Security Onion (or other Elastic-based) server.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are many common approaches to logging. However, since my home environment is running SecurityOnion (SO), I&#8217;m going to focus on three common ones and show how to do an end-to-end configuration with SO. If you&#8217;re curious about Filebeat, I&#8217;ve already written about it here. Fluentd Fluentd is extremely popular, while providing many options and &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.lottabytes.com\/index.php\/2025\/02\/12\/different-logging-approaches\/\" class=\"more-link\">Read more<span class=\"screen-reader-text\"> &#8220;Different Logging Approaches&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[69,83,84,86,82,51,85],"class_list":["post-351","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-elasticsearch","tag-filebeat","tag-fluentd","tag-getting-started","tag-logging","tag-security-onion","tag-syslog"],"_links":{"self":[{"href":"https:\/\/blog.lottabytes.com\/index.php\/wp-json\/wp\/v2\/posts\/351","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.lottabytes.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.lottabytes.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.lottabytes.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.lottabytes.com\/index.php\/wp-json\/wp\/v2\/comments?post=351"}],"version-history":[{"count":9,"href":"https:\/\/blog.lottabytes.com\/index.php\/wp-json\/wp\/v2\/posts\/351\/revisions"}],"predecessor-version":[{"id":366,"href":"https:\/\/blog.lottabytes.com\/index.php\/wp-json\/wp\/v2\/posts\/351\/revisions\/366"}],"wp:attachment":[{"href":"https:\/\/blog.lottabytes.com\/index.php\/wp-json\/wp\/v2\/media?parent=351"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.lottabytes.com\/index.php\/wp-json\/wp\/v2\/categories?post=351"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.lottabytes.com\/index.php\/wp-json\/wp\/v2\/tags?post=351"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}