SLS'den günlükleri çekmek ve bunları Splunk HEC veya Syslog üzerinden şirket içi SIEM sisteminize iletmek için bir tüketici grubu uygulaması dağıtın.
Arka Plan
Splunk ve QRadar gibi SIEM platformları genellikle genel ağa açık uç noktaları olmayan şirket içi veri merkezlerinde çalışır. Cloud'a geçiş yaptıktan sonra, izleme, denetim ve tehdit analizi amacıyla cloud kaynak günlüklerini şirket içi SIEM sisteminize güvenli bir şekilde aktaracak bir işlem hattına ihtiyacınız olur.
Nasıl Çalışır
Bir tüketici grubu uygulaması, günlükleri SLS'den gerçek zamanlı olarak çeker ve TCP/TLS üzerinden Splunk HEC veya Syslog kullanarak SIEM sisteminize iletir.
Temel Mantık
-
Günlük Çekme: Yerleşik eşzamanlılık ve yük devretme özelliklerine sahip bir tüketici grubu uygulaması, SLS'den verileri çeker.
-
Eşzamanlılık ve Aktarım Hızı
Daha yüksek aktarım hızı için aynı grupta birden fazla tüketici örneği çalıştırın. Her örneğin benzersiz bir adı olmalıdır (örneğin, işlem kimliği son eki).
Her parça aynı anda yalnızca bir tüketici tarafından işlenir. Maksimum eşzamanlılık, parça sayısına eşittir; örneğin, 10 parça en fazla 10 paralel tüketiciyi destekler.
-
İdeal ağ koşullarında:
Tek bir tüketici (~1 CPU çekirdeğinin %20'si), ham günlükleri 10 MB/s hızında tüketebilir.
On tüketici, saniyede 100 MB'a kadar işleyebilir.
-
Yüksek Kullanılabilirlik
Tüketici grubu, her tüketicinin ilerlemesini sunucu tarafı kontrol noktası olarak saklar.
Bir tüketici başarısız olursa, başka bir örnek onun parçalarını devralır ve son kontrol noktasından devam eder. Yük devretme için örnekleri ayrı makinelerde dağıtın.
Parça sayısının üzerindeki ek örnekler, anında yük devretme için yedek olarak görev yapar.
-
Veri İletimi: Uygulama, çekilen günlükleri biçimlendirir ve şirket içi SIEM sisteminize iletir.
Ön Koşullar
RAM kullanıcısı oluşturun ve izinler verin. RAM kullanıcısının
AliyunLogFullAccessilkesine sahip olması gerekir.-
Ağ: Uygulamayı çalıştıran makine hem SLS uç noktasına hem de SIEM sistemine erişebilmelidir.
-
Uç noktayı elde etmek için:
Log on to the SLS konsolu. 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.
-
-
Python 3 runtime with the SLS Python SDK installed.
Install the SLS Python SDK:
pip install -U aliyun-log-python-sdk.-
Verify:
pip show aliyun-log-python-sdk. Expected output: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. Select the one that matches your SIEM:
Splunk HEC: A token-based HTTP collector for sending data to Splunk.
Syslog: A standard logging protocol compatible with most SIEM systems.
Splunk HEC
Configure the sync_data.py script. It has three main parts:
main() method: The main program control logic.
-
get_option() method: Defines consumption configuration options.
Basic configuration: Connection settings for SLS and the consumer group.
Advanced consumer group options: Performance-tuning parameters. Do not modify 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: Fetches data from SLS and ships it to Splunk. Review the code comments and adjust as needed.
Complete script:
Syslog
Syslog supports RFC 5424 and RFC 3164 formats. Use RFC 5424 with TCP or TLS transport for reliable, secure delivery.
Configure the sync_data.py script. It has three main parts:
main() method: The main program control logic.
-
get_monitor_option() method: Defines consumption configuration options.
Basic configuration: Connection settings for SLS and the consumer group.
Advanced consumer group options: Performance-tuning parameters. Do not modify 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. Customize based on 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: Fetches data from SLS and delivers it to a Syslog server. Review the code comments and adjust as needed.
Complete script:
Step 2: Configure environment variables
Set the following environment variables:
|
Parameter |
Value |
Example |
|
SLS_ENDPOINT |
An |
|
|
SLS_PROJECT |
The name of your project in the SLS console. |
my-sls-project-one |
|
SLS_LOGSTORE |
The name of your Logstore in the SLS console. |
my-sls-logstore-a1 |
|
SLS_AK_ID |
AccessKey ID of your RAM user. Önemli
|
L***ky |
|
SLS_AK_KEY |
AccessKey Secret of your RAM user. |
x***Xl |
|
SLS_CG |
Consumer group name. Auto-created if it does not exist. |
sync_data |
Step 3: Start and verify
-
Start multiple consumer processes for concurrent processing. Maximum concurrency equals the shard count of 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.Click your consumer group. On the Consumer Group Status tab, view the consumer client and progress for each shard.
FAQ
ConsumerGroupQuotaExceed error
Each Logstore supports up to 30 consumer groups. Delete unused groups in the SLS console to free quota.