You can use SQL statements in advanced event queries to query or analyze events that are delivered to Simple Log Service by using a trail.
If you want to use strings in analytic statements, you must enclose the strings in single quotation marks (''). Strings that are not enclosed or strings that are enclosed in double quotation marks ("") indicate field names or column names. For example, 'status' indicates the status string, and status or "status" indicates the status log field.
Examples
-
Full-text query
Specify a keyword such as a field name or a field value.
Example: Query events that contain the keyword
DescribeInstances.DescribeInstances -
Property-based exact match
Specify an event property in the
[Event property name]:[Event property value]format. You must specify an exact name and value. For more information about event properties, see Event properties in this topic.Example: Query events in which the value of
event.eventSourceisactiontrail.cn-hangzhou.aliyuncs.com.event.eventSource: actiontrail.cn-hangzhou.aliyuncs.com -
Attribute-based fuzzy match
Specify an event property in the
[Event property name]:[Event property value]format. You must specify an exact name. For the value, you can add an asterisk (*) to match multiple characters or a question mark (?) to match a single character.-
Example 1: Query all AccessKey pair-based access events.
event.userIdentity.accessKeyId: * -
Example 2: Query events in which the value of
event.eventSourcestarts withactiontrail.event.eventSource: actiontrail*
-
-
Multi-condition query
Use parentheses
()and logical operatorsANDorORto perform a multi-condition query.-
Example 1: Query all events on failures of AccessKey pair-based access.
event.errorCode: * AND event.userIdentity.accessKeyId: * -
Example 2: Query events in which the value of
event.eventNameisCreate,CreateInstance, orRunInstances.event.eventName: Create OR event.eventName: CreateInstance OR event.eventName: RunInstances -
Example 3: Query events in which the value of
event.serviceNameiskafkaand the value of eventName isCreate,CreateInstance, orRunInstances.(event.serviceName: AliKafka AND ( event.eventName: Create OR event.eventName: CreateInstance OR event.eventName: RunInstances )
-
-
Aggregate query
You can use the aggregate query syntax of Simple Log Service to generate aggregate statistics on events. For example, you can use the
GROUP BYclause to generate aggregate statistics on specific fields.-
Example 1: Query the numbers of events that are aggregated by cloud service.
* | SELECT "event.serviceName" AS service, COUNT(*) AS count FROM log GROUP BY "event.serviceName" -
Example 2: Query the numbers of events that are aggregated by user and cloud service.
* | SELECT "event.userIdentity.principalId" AS principalId, "event.serviceName" AS service, COUNT(*) AS count FROM log GROUP BY principalId,service
-
Event properties
The following table describes the event attributes supported by ActionTrail.
|
Category |
Event property name |
Description |
|
Operator |
|
The Alibaba Cloud account ID. |
|
|
The key ID. |
|
|
|
The requester ID. |
|
|
|
The account type. |
|
|
|
The username. |
|
|
Action |
|
The service name. |
|
|
The read/write type. |
|
|
|
The event name. |
|
|
|
The version information. |
|
|
|
The error message. |
|
|
|
The error code. |
|
|
Associated resource |
|
The resource type. |
|
|
The resource name. |
|
|
Location |
|
The region. |
|
|
The event source. |
|
|
|
The source IP address. |
|
|
Others |
|
The request ID. |
|
|
The event ID. |
Aggregate functions
The following table describes the aggregate functions supported by ActionTrail.
Parameter | Syntax | Description | SQL support | SPL support |
arbitrary(x) | Returns an arbitrary non-NULL value from x. | √ | × | |
avg(x) | Calculates the arithmetic mean of x. | √ | × | |
bitwise_and_agg(x) | Returns the bitwise AND of all values in x. | √ | × | |
bitwise_or_agg(x) | Returns the bitwise OR of all values in x. | √ | × | |
bool_and(boolean expression) | Returns true if all logs meet the condition. The | √ | × | |
bool_or(boolean expression) | Returns true if at least one log meets the condition. | √ | × | |
checksum(x) | Calculates the checksum of x. | √ | × | |
count(*) | Returns the total number of logs. | √ | × | |
count(1) | Returns the total number of logs, which is equivalent to | √ | × | |
count(x) | Returns the number of logs where the value of x is not NULL. | √ | × | |
count_if(boolean expression) | Returns the number of logs that meet the specified condition. | √ | × | |
every(boolean expression) | Returns true if all logs meet the condition. The | √ | × | |
geometric_mean(x) | Calculates the geometric mean of x. | √ | × | |
kurtosis(x) | Calculates the kurtosis of x. | √ | × | |
map_union(x) | Returns the union of maps in a column. If a key exists in multiple maps, an arbitrary value for that key is chosen. | √ | × | |
max(x) | Returns the maximum value in x. | √ | × | |
max(x, n) | Returns the n largest values in x as an array. | √ | × | |
max_by(x, y) | Returns the value of x associated with the maximum value of y. | √ | × | |
max_by(x, y, n) | Returns an array of the x values corresponding to the n largest values of y. | √ | × | |
min(x) | Returns the minimum value in x. | √ | × | |
min(x, n) | Returns the n smallest values in x as an array. | √ | × | |
min_by(x, y) | Returns the value of x associated with the minimum value of y. | √ | × | |
min_by(x, y, n) | Returns an array of the x values corresponding to the n smallest values of y. | √ | × | |
skewness(x) | Calculates the skewness of x. | √ | × | |
sum(x) | Calculates the sum of x. | √ | × |
Reserved words
The following code block shows all reserved words in SQL statements:
AND
AS
BETWEEN
BY
CASE
CAST
CROSS
CUBE
CURRENT_DATE
CURRENT_TIME
CURRENT_TIMESTAMP
DISTINCT
ELSE
END
ESCAPE
EXCEPT
EXISTS
FROM
GROUP
GROUPING
HAVING
IN
INNER
INSERT
INTERSECT
INTO
IS
JOIN
LEFT
LIKE
LIMIT
LOCALTIME
LOCALTIMESTAMP
NATURAL
NOT
NULL
ON
OR
ORDER
OUTER
RIGHT
ROLLUP
SELECT
THEN
TRUE
UNION
UNNEST
VALUES
WHEN
WHERE
WITH