Logstash Output Options for Syslog and Custom Logs

Author

Reads 614

An artist's illustration of artificial intelligence (AI). This image represents storage of collected data in AI. It was created by Wes Cockx as part of the Visualising AI project launched ...
Credit: pexels.com, An artist's illustration of artificial intelligence (AI). This image represents storage of collected data in AI. It was created by Wes Cockx as part of the Visualising AI project launched ...

You can send your logs to a syslog server using the syslog output plugin, which is useful for sending logs to a centralized log server.

The syslog output plugin can send logs to a remote syslog server, and it also supports TCP and UDP protocols for sending logs.

To send logs to a custom log location, you can use the file output plugin, which is a simple way to write logs to a file.

The file output plugin supports a variety of options, including the ability to rotate logs and use a custom log format.

See what others are reading: Logstash Syslog Input

Installation and Setup

To install the Logstash output plugin, you can simply use the command to download the latest gem for the output plugin and install it in logstash.

If you need to install the plugin manually, you can use the command to download the latest gem and install it.

The process is straightforward and can be completed with just a few keystrokes, making it easy to get started with the Logstash output plugin.

Discover more: Install Logstash

Docker

Black and white image of a lumberjack cutting a tree log with a chainsaw in a forest.
Credit: pexels.com, Black and white image of a lumberjack cutting a tree log with a chainsaw in a forest.

We provide a Docker image on Docker Hub that contains Logstash and the Loki output plugin already pre-installed.

To run Logstash in Docker, you can use the command below.

A fresh viewpoint: Logstash Docker Container

Configuration

Configuration is a crucial step in setting up Logstash output. To configure Logstash to forward logs to Microsoft Sentinel, you'll need to retrieve specific values such as client_app_Id, client_app_secret, tenant_id, data_collection_endpoint, and dcr_immutable_id.

You can find these values by following the tutorial in the relevant section, and store them securely in a Logstash KeyStore for security reasons. It's recommended to store sensitive information separately from your Logstash configuration file.

Here's a list of required values and how to retrieve them:

Remember to replace the output section of your Logstash configuration file with the example provided, and make sure to change the create_sample_file attribute to false.

Create DCR Resources for Custom Table Ingestion

To create DCR resources for ingestion into a custom table, you'll need to review the prerequisites.

A detailed view of an industrial refinery featuring pipelines and large steel structures.
Credit: pexels.com, A detailed view of an industrial refinery featuring pipelines and large steel structures.

First, configure the application according to the requirements. This will ensure that you're setting up the right foundation for the custom table ingestion process.

Add a custom log table to store the ingested data. This table will serve as the destination for the logs.

To parse and filter sample data, use the sample file created in the previous section. This file will help you understand the format and structure of the data.

Collect information from the DCR (Data Collection Repository) to get the necessary details for the ingestion process.

Assign permissions to the DCR to ensure that the data is accessible and can be ingested correctly.

Here are the steps to create DCR resources for custom table ingestion:

  1. Review the prerequisites.
  2. Configure the application.
  3. Add a custom log table.
  4. Parse and filter sample data using the sample file.
  5. Collect information from the DCR.
  6. Assign permissions to the DCR.

Usage and Configuration

To configure Logstash to forward logs to Loki, you simply add the loki output to your Logstash configuration file. By default, Loki will create an entry from event fields it receives, using the message and @timestamp fields to form the Loki entry log line and timestamp.

A Person Using a Digital Tablet on the Marble Table Top
Credit: pexels.com, A Person Using a Digital Tablet on the Marble Table Top

You can use a different property for the log line by using the configuration property message_field. If you also need to change the timestamp value, use the Logstash date filter to change the @timestamp field.

All other fields (except nested fields) will form the label set (key value pairs) attached to the log line. This means you're responsible for mutating and dropping high cardinality labels such as client IPs. You can usually do so by using a mutate filter.

Here are some common fields that can be used as labels:

You can also include nested fields or metadata fields (starting with @) by renaming them. For example, when using Filebeat with the add_kubernetes_metadata processor, it will attach Kubernetes metadata to your events like this:

{

"container_name": "example-container",

"namespace": "example-namespace",

"pod": "example-pod",

"host": "example-host"

}

To extract these Kubernetes fields into labels, you can use a filter like this:

mutate {

add_field => {

"cluster" => "%{[container_name]}"

"job" => "%{[namespace]}"

"type" => "stream"

}

}

Plugins and Integrations

Credit: youtube.com, Demo - How to send data from Logstash to AWS S3 | Logstash S3 output plugin |Logstash-S3 Integration

Logstash output plugins are the final stage in the event pipeline, sending event data to a particular destination.

To deploy a plugin, you'll need to review the prerequisites, install the plugin, and create a sample file. This is a crucial step in setting up the plugin.

The Microsoft Sentinel output plugin, for example, requires creating required DCR-related resources and configuring the Logstash configuration file.

Here's a brief overview of the deployment process for the Microsoft Sentinel output plugin:

  1. Review the prerequisites
  2. Install the plugin
  3. Create a sample file
  4. Create the required DCR-related resources
  5. Configure Logstash configuration file
  6. Restart Logstash
  7. View incoming logs in Microsoft Sentinel
  8. Monitor output plugin audit logs

Deploy Microsoft Sentinel Plugin

Deploying the Microsoft Sentinel plugin is a straightforward process. First, review the prerequisites to ensure you have everything you need.

To set up the plugin, start by installing the plugin itself. This is a crucial step, as it allows you to use the plugin's functionality.

Next, create a sample file to test the plugin. This will help you verify that the plugin is working correctly.

After installing the plugin, you'll need to create the required DCR-related resources. This will give you the necessary configuration to use the plugin.

Credit: youtube.com, Building Microsoft Sentinel Integrations - Part 1: Onboarding

You'll also need to configure the Logstash configuration file. This file will tell Logstash how to use the plugin and what data to send to Microsoft Sentinel.

Once you've configured the file, restart Logstash to apply the changes. This will activate the plugin and start sending data to Microsoft Sentinel.

Finally, view the incoming logs in Microsoft Sentinel to see the data being collected. This will give you a sense of what's working and what might need further configuration.

To keep track of the plugin's performance, monitor the output plugin audit logs. This will help you identify any issues or areas for improvement.

For another approach, see: Outputting Figma as Html File

Configure Downstream HTTP Input

To configure the downstream Logstash to use HTTP input, you'll need to set a custom port and specify the additional codecs. The minimum configuration requires the port option and the additional_codecs option, which should be set to application/json to be json_lines.

The port option allows you to choose a specific port for the downstream Logstash to receive connections on. This is useful if you want to customize the port number to avoid conflicts with other services.

Here are the required options for the downstream HTTP input:

  • port - To set a custom port.
  • additional_codecs - To set application/json to be json_lines.

By configuring the downstream Logstash with these options, you'll be able to receive data from the upstream Logstash, which we'll cover in the next section.

Email Plugin

A Man Looking at a Computer Screen with Data
Credit: pexels.com, A Man Looking at a Computer Screen with Data

The Email Plugin is a great way to send notifications and alerts from your Logstash pipeline. It allows you to send emails to specific recipients.

You can specify the fully-qualified email address to send the email to, which is a required field. The address can also be a comma-separated string of addresses, for example: "[email protected], [email protected]".

The Email Plugin also allows you to specify the fully-qualified email address(es) to include as CC or BCC. These fields accept several addresses like the "to" field.

You can set the content-type and/or charset of the HTML part for multipart messages, which is useful for sending emails with attachments. However, please note that this feature may not be functional (KH).

The Email Plugin also provides a debug mode, which is useful for troubleshooting issues. You can set the debug mode to "true" to enable it.

Here are some common settings for the Email Plugin:

You can also use dynamic fields from the event with the %{fieldname} syntax to populate the email with data from your pipeline.

Plugins

Credit: youtube.com, 5. Plugin Integrations​

Plugins are a crucial part of Logstash, allowing you to send event data to various destinations. This can be achieved through output plugins, which are the final stage in the event pipeline.

To configure an output plugin, you'll need to add it to your Logstash configuration file. For example, to forward logs to Loki, you simply add the loki output as documented. This will create an entry from event fields it receives.

The loki output plugin can be customized to suit your needs. By default, Loki will use the message and @timestamp fields to form the log line and timestamp. However, you can change this by using the configuration property message_field.

Some output plugins, like the Microsoft Sentinel output plugin, require additional configuration steps. To deploy this plugin, you'll need to review the prerequisites, install the plugin, create a sample file, and create the required DCR-related resources.

Here are some common output plugins and their required configuration options:

By understanding the different types of output plugins and their configuration options, you can effectively integrate Logstash with various tools and services.

Tcp

Close-up of a man using a chainsaw to cut a large tree log outdoors.
Credit: pexels.com, Close-up of a man using a chainsaw to cut a large tree log outdoors.

Tcp is a plugin that reads events over a TCP socket, with each event assumed to be one line of text.

The plugin also supports the use of an optional SSL certificate, which is available in the codec with the default value of "line".

Kafka

Kafka is a powerful tool for handling data ingestion and storage in a message queue.

You'll typically use Kafka as a message queue for your Logstash shipping instances.

The only required configuration for the Kafka plugin is the topic name.

Here's an interesting read: Logstash Kafka Input

Usage and Troubleshooting

Logstash output is a powerful tool, but it's not immune to issues. A common problem is the "connection timeout" error, which occurs when the output plugin takes too long to write to the destination.

To troubleshoot this, check the timeout settings in your output configuration. By default, the timeout is 30 seconds, but you can adjust this value to suit your needs.

If you're experiencing issues with data not being written to the destination, make sure the output plugin is properly configured and the destination is accessible.

Restart

Business Data Graph on Monitor
Credit: pexels.com, Business Data Graph on Monitor

Restarting your system can be a straightforward process, but it's essential to do it correctly to avoid any issues.

To restart Logstash, simply follow the instructions provided in the relevant documentation.

Restarting Logstash with the updated output plugin configuration is crucial to ensure data is ingested to the right table according to your DCR configuration.

Known Issues

Using Logstash on a Docker image of Lite Ubuntu can trigger a warning.

You can resolve this issue by installing the netbase package within your Dockerfile.

If your environment's event rate is low, consider increasing the value of plugin_flush_interval to 60 or more. This allows each worker to batch more events before uploading to the Data Collection Endpoint (DCE).

Version and Release

With Logstash output, it's essential to understand the different versions and their capabilities. Version 1.1.0 and greater allow you to specify a list of labels to allow list via the include_fields configuration.

This feature enables more flexibility in data processing, especially when working with complex data structures. Version 1.2.0 and greater also introduce structured metadata via the metadata_fields configuration, which can be a game-changer for data analysis and visualization.

The following versions and their corresponding features are worth noting:

  • Version 1.1.0 and greater: include_fields configuration for specifying a list of labels to allow list
  • Version 1.2.0 and greater: metadata_fields configuration for specifying structured metadata

Version Notes

Professional recording studio featuring audio mix console and monitors for music production.
Credit: pexels.com, Professional recording studio featuring audio mix console and monitors for music production.

In terms of version notes, it's worth noting that version 1.1.0 and greater of this plugin allows for specifying a list of labels to allow list via the include_fields configuration.

Version 1.1.0 and greater of this plugin is a significant update, enabling users to tailor their experience with more precision.

Here are the key version notes to keep in mind:

  • Version 1.1.0 and greater: include_fields configuration for allowing list of labels
  • Version 1.2.0 and greater: metadata_fields configuration for structured metadata

Version 1.2.0 and greater brings another important feature, structured metadata via the metadata_fields configuration.

1.0.0

The 1.0.0 release marked a significant milestone for the Logstash output plugin for Microsoft Sentinel. This initial release utilized Data Collection Rules (DCRs) with Azure Monitor's Logs Ingestion API.

The plugin's functionality was built on top of this API, enabling users to leverage the power of Azure Monitor for their log ingestion needs. This integration provided a robust solution for managing and analyzing logs.

Here are the key features of the 1.0.0 release:

  • The initial release for the Logstash output plugin for Microsoft Sentinel.
  • This plugin uses Data Collection Rules (DCRs) with Azure Monitor's Logs Ingestion API.

Output and Logging

To monitor the output and logging of Logstash, you can enable the appropriate Logstash log file. This will help you keep track of connectivity and activity.

Credit: youtube.com, Elasticsearch 8.x: Fleet Server + Logstash Output

If you're not seeing any data in the log file, you can generate and send some events locally through the input and filter plugins to test the output plugin.

The email output plugin sends emails when an output is received. You can customize it with various settings, including the fully-qualified email address to send the email to, which is a required field.

Here's a list of some of the email output plugin settings:

The fully-qualified email address to send the email to can be customized, and you can also use dynamic fields from the event with the %{fieldname} syntax.

9 Kv

The KV plugin is a powerful tool for parsing messages into key-value pairs. By default, it uses the '=' delimiter to break down the message field.

This plugin can be configured to use any arbitrary strings to split your data into any event field, giving you flexibility in how you structure your data.

However, be aware that the production of an unlimited number of fields can hurt your efforts to index your data in Elasticsearch later, so use this feature with caution.

Redis

An artist's illustration of artificial intelligence (AI). This image represents storage of collected data in AI. It was created by Wes Cockx as part of the Visualising AI project launched ...
Credit: pexels.com, An artist's illustration of artificial intelligence (AI). This image represents storage of collected data in AI. It was created by Wes Cockx as part of the Visualising AI project launched ...

Redis is a key-value data store that can serve as a buffer layer in your data pipeline.

It's often used as a message queue for Logstash shipping instances that handle data ingestion and storage in the message queue.

The Redis plugin is used to output events to Redis using an RPUSH.

This allows you to store events in Redis and use it as a buffer layer in your data pipeline.

Redis is particularly useful for handling high volumes of data, allowing you to scale your data pipeline as needed.

It's also a great way to decouple your data ingestion and storage processes, making it easier to manage your data pipeline.

Audit Logs for Monitor Plugin

To monitor the output plugin's activity, you need to enable the Logstash log file. This log file is located in the directory specified by the Logstash Directory Layout document.

The log file will show you if the output plugin is receiving data, which is essential for Microsoft Sentinel to function properly. If you're not seeing any data in the log file, try generating some events locally using the input and filter plugins.

Microsoft Sentinel will only support issues related to the output plugin, so make sure to check the log file first before reaching out for help.

Network Security

Credit: youtube.com, Analyzing Output from Network Security Monitoring Tools

Network security is crucial for protecting your data and systems. Define network settings to ensure your output and logging processes are secure.

Enabling network isolation for the Microsoft Sentinel Logstash output plugin is a key step in securing your network. This helps prevent unauthorized access to your sensitive data.

In order to maintain network security, you need to take proactive measures. Defining network settings and enabling network isolation are just a couple of steps you can take.

Network isolation is a powerful tool that can help prevent data breaches. By isolating your network, you can better protect your data and systems from external threats.

Metadata Fields

Metadata Fields are a crucial part of the logging process, and they're used to map structured metadata to log lines.

An array of fields is used for this purpose, which is sent to Loki for each log line. This array is specifically called metadata_fields.

The fields in this array are then used to create structured metadata, which can be used to provide more context to log lines. This can be particularly helpful for debugging and troubleshooting purposes.

For example, metadata_fields can include specific information such as timestamps, user IDs, or request IDs. These fields can be customized to fit the specific needs of your application or system.

A fresh viewpoint: Docker Log to Logstash

3. Stdout

Credit: youtube.com, Linux Crash Course - Data Streams (stdin, stdout & stderr)

The Stdout output is a simple yet effective way to debug plugin configurations. It prints event data directly to the stdout of the shell running Logstash.

This output is convenient for quickly testing and verifying the flow of event data through the pipeline. It can be a lifesaver when troubleshooting issues.

As a Logstash user, I've found that the Stdout output is especially useful during the development and testing phases. It allows you to see exactly what's happening with your event data in real-time.

The Stdout output is a standard output plugin, which means it's easy to use and requires minimal configuration. Just add it to your Logstash pipeline and you're good to go.

With the Stdout output, you can print event data to the console, making it easy to inspect and debug your pipeline. This is a big time-saver, especially when working on complex event processing pipelines.

Gilbert Deckow

Senior Writer

Gilbert Deckow is a seasoned writer with a knack for breaking down complex technical topics into engaging and accessible content. With a focus on the ever-evolving world of cloud computing, Gilbert has established himself as a go-to expert on Azure Storage Options and related topics. Gilbert's writing style is characterized by clarity, precision, and a dash of humor, making even the most intricate concepts feel approachable and enjoyable to read.

Love What You Read? Stay Updated!

Join our community for insights, tips, and more.