To ship logs to a Security Information and Event Management (SIEM) system, you can deploy an application that connects SLS to your SIEM. This application uses an SLS consumer group to pull logs and then forwards them to your SIEM using Splunk HEC or Syslog. This integrates your cloud logs with your on-premises security analytics platform.
Background
Enterprises often deploy Security Information and Event Management (SIEM) platforms, such as Splunk or QRadar, in on-premises data centers. To maintain security, these platforms typically do not expose public endpoints for receiving data. When you migrate your business to the cloud, you need to consolidate logs from cloud resources into your on-premises SIEM for unified monitoring, auditing, and threat analysis. You must establish a secure log shipping pipeline from SLS to your on-premises SIEM without compromising the security of your existing systems.
How it works
For real-time data shipping, use an SLS consumer group. A dedicated application pulls logs from SLS and forwards them to your SIEM using the Splunk HTTP Event Collector (HEC) or Syslog over TCP/TLS.
Core logic
-
Log pulling: An application based on a consumer group pulls data from SLS. This mechanism supports concurrent consumption and failover.
-
Concurrency and throughput
-
To achieve higher throughput, run multiple instances of the consumer application. Each consumer instance must belong to the same consumer group and have a unique name, for example, by using a process ID as a suffix.
-
Only one consumer can process a shard at a time. Therefore, the maximum number of concurrent consumers is limited by the number of shards in the logstore. For example, if a logstore has 10 shards, you can run up to 10 consumers in parallel.
-
Under ideal network conditions:
-
A single consumer (using about 20% of a single CPU core) can consume raw logs at a rate of 10 MB/s.
-
Ten consumers can process up to 100 MB/s of raw logs.
-
-
-
High availability
-
The consumer group stores each consumer's progress as a checkpoint on the server.
-
If a consumer instance fails, another available instance automatically takes over its assigned shards and resumes processing from the last saved checkpoint. To ensure robust failover, you can run consumer instances on different machines.
-
You can run more consumer instances than the number of shards. The extra instances act as standbys for immediate failover.
-
-
-
Data forwarding: After pulling the logs, the application formats and forwards them to your on-premises SIEM based on your configuration.
Prerequisites
-
Create a RAM user and grant permissions: The RAM user must have the
AliyunLogFullAccesspolicy. -
Network requirements: The machine running the application must be able to access the SLS endpoint and be on the same network as the SIEM.
-
To obtain the endpoint:
-
Log on to the SLS console. In the project list, click the target project.
-
Click the
icon to the right of the project name to go to the project overview page. -
In the Endpoint section, copy the public endpoint. The endpoint is
https://+ the public endpoint.
-
-
-
Environment requirements: Prepare a Python 3 runtime environment and install the SLS Python SDK.
-
Install the SLS Python SDK:
pip install -U aliyun-log-python-sdk. -
Verify the installation:
pip show aliyun-log-python-sdk. A successful installation returns information similar to the following.Name: aliyun-log-python-sdk Version: 0.9.12 Summary: Aliyun log service Python client SDK Home-page: https://github.com/aliyun/aliyun-log-python-sdk Author: Aliyun
-
Procedure
Step 1: Prepare the application
SLS provides sample scripts for two shipping methods: Splunk HEC and Syslog. Select the method that matches your SIEM and configure the corresponding script.
-
Splunk HEC: The HTTP Event Collector (HEC) is a token-based mechanism that lets you send data in various formats securely and efficiently to Splunk over HTTP.
-
Syslog: A common logging protocol that is compatible with most SIEM systems and supports plain text format.
Splunk HEC
To ship log data to Splunk, configure the provided sync_data.py script. The script consists of three main parts:
-
main() method: The main program control logic.
-
get_option() method: Defines consumption configuration options.
-
Basic configuration: Includes connection settings for SLS and the consumer group.
-
Advanced consumer group options: Includes performance-tuning parameters. Do not modify these unless necessary.
-
SIEM (Splunk) parameters and options.
-
Add an SPL query to filter or transform data during shipping for tasks like row filtering, column trimming, or data normalization. Example:
# SPL query query = "* | where instance_id in ('instance-1', 'instance-2')" # Create a consumer with the filter rule. The 'query' parameter is added to the configuration. option = LogHubConfig(endpoint, accessKeyId, accessKey, project, logstore, consumer_group, consumer_name, cursor_position=CursorPosition.SPECIAL_TIMER_CURSOR, cursor_start_time=cursor_start_time, heartbeat_interval=heartbeat_interval, data_fetch_interval=data_fetch_interval, query=query)
-
-
SyncData(ConsumerProcessorBase) class: Contains the logic for fetching data from SLS and shipping it to Splunk. Review the comments in the code and adjust the logic as needed.
The complete script is provided below:
Syslog
Syslog defines log format specifications based on protocols such as RFC 5424 and RFC 3164. We recommend using RFC 5424. While Syslog can be transported over both UDP and TCP, TCP provides more reliable data transmission. RFC 5424 also defines a secure transport layer using TLS. If your SIEM supports Syslog over a TCP or TLS channel, use it.
To ship log data to a SIEM by using Syslog, you can configure the provided sync_data.py script. The script consists of three main parts:
-
main() method: The main program control logic.
-
get_monitor_option() method: Defines consumption configuration options.
-
Basic configuration: Includes connection settings for SLS and the consumer group.
-
Advanced consumer group options: Includes performance-tuning parameters. Do not modify these unless necessary.
-
SIEM Syslog server parameters and options.
-
Syslog facility: The program component that generated the log. This example uses
syslogclient.FAC_USERas the default. -
Syslog severity: The log level of the message. You can customize this based on the log content. This example uses
syslogclient.SEV_INFO. -
If your SIEM supports Syslog over TCP or TLS, set the proto parameter to TLS and provide the path to a valid SSL certificate.
-
-
-
SyncData(ConsumerProcessorBase) class: Contains the logic for fetching data from SLS and delivering it to a Syslog server. Review the comments in the code and adjust the logic as needed.
The complete script is provided below:
Step 2: Configure environment variables
After configuring the program, perform the system environment variable configuration in the table.
|
Parameter |
Value |
Example |
|
SLS_ENDPOINT |
If the endpoint is prefixed with |
|
|
SLS_PROJECT |
The name of your target project in the SLS console. |
my-sls-project-one |
|
SLS_LOGSTORE |
The name of your target logstore in the SLS console. |
my-sls-logstore-a1 |
|
SLS_AK_ID |
The AccessKey ID of your RAM user. Important
|
L***ky |
|
SLS_AK_KEY |
The AccessKey Secret of your RAM user. |
x***Xl |
|
SLS_CG |
The name of the consumer group. You can use a simple name like "sync_data". If the specified group does not exist, the application creates it automatically. |
sync_data |
Step 3: Start and verify
-
Start multiple consumer processes to enable concurrent processing. The maximum number of concurrent processes equals the number of shards in your logstore.
# Start the first consumer process nohup python3 sync_data.py & # Start the second consumer process nohup python3 sync_data.py & -
View the status of the consumer group in the SLS console.
-
In the project list, click your target project. Go to the tab. Click the
icon next to your target logstore, and then click the
icon next to Data Consumption. -
In the consumer group list, click your target consumer group. On the Consumer Group Status tab, view the consumer client and progress for each shard.
-
FAQ
ConsumerGroupQuotaExceed error
This error indicates that you have exceeded the quota for consumer groups. A single logstore can have a maximum of 30 consumer groups. To resolve this issue, delete any unused consumer groups in the SLS console.