DingTalk Application Management can automatically enable Simple Log Service (SLS) audit logs for your application. You can then use SLS audit analysis and alerting to detect abnormal operations such as unauthorized data access or data leaks.
Procedure
Step 1. Enable and view SLS audit logs
1. Enable SLS audit logs
On the application group Overview page in DingTalk Application, click Enable Now to initialize SLS audit logs. This creates a project, a Logstore, and a Logtail configuration named after the DingTalk application ID. This topic uses 031001 as the example ID.
2. View the initialized SLS audit logs
After SLS audit logs are enabled, click View Now to open the SLS project page.
Log access path:
The path contains the project and Logstore names.
- Project: dingtalk-application-cn-{regionId}. {regionId} is the region where the application group is deployed.
- Logstore: {dingTalkAppId}. {dingTalkAppId} is the ID of the DingTalk application.
Format:
https://sls.console.alibabacloud.com/lognext/project/dingtalk-application-{regionId}/logsearch/{dingTalkAppId}
Example:
https://sls.console.alibabacloud.com/lognext/project/dingtalk-application-cn-chengdu/logsearch/031001
Step 2. View the default SLS audit log configuration
The Logstore includes a Logtail Configuration automatically created for the application. A Logtail configuration defines the log collection policies. For more information, see Logtail configurations (Legacy).
The following table lists the initial collection configuration.
|
Field Name |
Initial Value |
Description |
|
|
Configuration Name |
031001 |
The DingTalk application ID used as the configuration name. |
|
|
Log Path |
/home/logs/**/031001.log |
Log collection path. Files matching the specified name (full name or wildcard) are monitored. |
|
|
Mode |
Full regex mode |
Log collection mode. |
|
|
Log Sample |
2022-03-09 18:36:13.236 INFO LogHelper.printProviderLog(85): ANTL_41A46571-0B69-1BD0-851C-35A893395774 userId=130920852836****,sourceIpAddress=106.11.**.***,userName=root,eventName=AddUserToGroup,request=requestBody,response=responseBody |
A preset sample log entry. Compute Nest predefines the sample text and field parsing rules. |
|
|
Regular Expression for First Line |
\d+-\d+-\d+\s\d+:\d+:\d+\.\d+\s.* |
Regex pattern for the first log line. Each extracted key-value pair uses a user-defined key name. If you do not use system time, specify a key-value pair with the key set to time. |
|
|
Extract Fields |
Enabled |
Whether to extract fields. |
|
|
Regular Expression |
(\d+-\d+-\d+\s\S+)\s+([a-zA-Z]+)\s+([^:]+):\s([a-zA-Z0-9_-]+)\suserId=(null|\d+),sourceIpAddress=(null|\d+\.\d+\.\d+\.\d+),userName=([a-zA-Z0-9_-]+),eventName=([a-zA-Z0-9_-]+),request=(.*),response=(.*) |
Regex used to parse and extract fields from log text. |
|
|
Extracted Log Content |
Extracted Field Name |
Extracted Field Value |
Regex-extracted field |
|
*eventTime |
2022-03-09 18:36:13.236 |
Event timestamp. |
|
|
*eventLevel |
INFO |
Event level. |
|
|
*eventFunction |
LogHelper.printProviderLog(85) |
Function that processed the event. |
|
|
*eventId |
ANTL_41A46571-0B69-1BD0-851C-35A893395774 |
Event ID. |
|
|
userId |
130920852836**** |
User ID. |
|
|
sourceIpAddress |
106.11.41.*** |
Source IP address. |
|
|
*userName |
root |
Username. |
|
|
*eventName |
AddUserToGroup |
Event name. |
|
|
requestParameters |
requestBody |
Request parameters. |
|
|
responseParameters |
responseBody |
Response parameters. |
|
Step 3. Create a machine group
In the left-side navigation pane, choose Resources > Machine Groups and create a machine group.
Name the machine group and specify IP addresses. This example uses a group named app-test. Requirements: only ECS instances in the same region as the project are supported, IP addresses must be internal, and you cannot mix Windows and Linux instances in the same group.
Step 4. Associate the machine group with the Logtail configuration
On the Logtail Configuration page, click Modify. Move the app-test machine group from Source Machine Groups to Applied Machine Groups.
Step 5. Configure an index for the SLS audit logs
You can enable indexes based on your log content. Click Enable Index and then click Auto Generate Index to simplify index creation. For more information, see Create an index.
Step 6. Collect a sample log
On the ECS instance in the configured machine group, create the specified log file and write test data to it.
mkdir -p /home/logs
touch /home/logs/031001.log
echo "2022-03-09 18:36:13.236 INFO LogHelper.printProviderLog(85): ANTL_41A46571-0B69-1BD0-851C-35A893395774 userId=1309208528360047,sourceIpAddress=106.11.XX.XXX,userName=root,eventName=AddUserToGroup,request=requestBody,response=responseBody" >> /home/logs/031001.log
After 3 to 5 seconds, the new log entry appears on the monitoring dashboard, confirming successful collection.
Query and analyze logs
On the monitoring dashboard, enter a query statement, select a time range, and click Query/Analysis.
In this example, to search for the requestBody keyword, enter requestBody in the search box and click Query/Analysis. All matching log entries are displayed. You can also use logical operators to query multiple keywords, such as requestBody or content, or query by a specific field value, such as userId: 130920852836****.
This topic describes only the most basic query methods. The SLS query and analysis feature provides many other methods, including a variety of convenience functions. For more information, see Query syntax and functions.