Queries audit log entries for a MongoDB instance.
Operation description
-
When you call this operation, ensure that the audit log feature of the instance is enabled. Otherwise, the operation returns an empty audit log.
-
This operation is applicable only to general-purpose local-disk and dedicated local-disk instances.
-
You can call this operation up to 30 times per minute. To call this operation at a higher frequency, use a Logstore. For more information, see Manage a Logstore.
Try it now
Test
RAM authorization
|
Action |
Access level |
Resource type |
Condition key |
Dependent action |
|
dds:DescribeAuditRecords |
get |
*dbinstance
|
None | None |
Request parameters
|
Parameter |
Type |
Required |
Description |
Example |
| DBInstanceId |
string |
Yes |
The instance ID. Note
If you set this parameter to the ID of a sharded cluster instance, you must also specify the NodeId parameter. |
dds-bp12c5b040dc**** |
| NodeId |
string |
No |
The ID of a Mongos node or a shard node in the sharded cluster instance. Note
This parameter is available only when DBInstanceId is set to the ID of a sharded cluster instance. |
d-bp128a003436**** |
| StartTime |
string |
Yes |
The beginning of the time range to query. Specify the time in the yyyy-MM-ddTHH:mm:ssZ format. The time must be in UTC. |
2019-03-13T12:11:14Z |
| EndTime |
string |
Yes |
The end of the time range to query. The end time must be later than the start time. Specify the time in the yyyy-MM-ddTHH:mm:ssZ format. The time must be in UTC. Note
The time range between the start time and the end time cannot exceed 24 hours. Otherwise, the operation fails. |
2019-03-13T13:11:14Z |
| Database |
string |
No |
The name of the database. By default, all databases are queried. |
database**** |
| User |
string |
No |
The database account. By default, all accounts are queried. |
test |
| Form |
string |
No |
The format of the returned audit records. Valid values:
Note
The File parameter is deprecated. |
Stream |
| QueryKeywords |
string |
No |
The keywords for the query. You can specify up to 10 keywords. Separate multiple keywords with spaces. |
slow |
| LogicalOperator |
string |
No |
The logical operator for the keyword search. The default value is and. |
and |
| PageSize |
integer |
No |
The number of entries to return on each page. Valid values: 30 (default), 50, and 100. |
30 |
| PageNumber |
integer |
No |
The page number to return. The value must be greater than 0 and must not exceed the maximum value of the integer data type. Default value: 1. |
1 |
| OrderType |
string |
No |
The order in which to sort the returned audit log entries by time. Valid values:
|
asc |
Response elements
|
Element |
Type |
Description |
Example |
|
object |
|||
| TotalRecordCount |
integer |
The total number of entries. |
40 |
| PageRecordCount |
integer |
The number of entries on the current page. |
30 |
| RequestId |
string |
The request ID. |
3278BEB8-503B-4E46-8F7E-D26E040C9769 |
| PageNumber |
integer |
The page number. |
1 |
| Items |
object |
||
| SQLRecord |
array<object> |
The list of audit log details. |
|
|
object |
The details of an audit log entry. |
||
| HostAddress |
string |
The IP address of the client. |
11.xxx.xxx.xxx |
| TableName |
string |
The name of the MongoDB collection. |
C1 |
| ReturnRowCounts |
integer |
The number of returned rows. |
2 |
| DBName |
string |
The database name. |
test123 |
| ExecuteTime |
string |
The time when the statement was executed. The time is in the yyyy-MM-ddTHH:mm:ssZ format and is displayed in UTC. |
2019-03-11T03:30:27Z |
| ThreadID |
string |
The thread ID. |
140682188297984 |
| TotalExecutionTimes |
integer |
The execution time, in microseconds. |
700 |
| Syntax |
string |
The executed statement. |
{ \"atype\" : \"createCollection\", \"param\" : { \"ns\" : \"123.test1\" }, \"result\": \"OK\" } |
| AccountName |
string |
The name of the database account. |
test |
Examples
Success response
JSON format
{
"TotalRecordCount": 40,
"PageRecordCount": 30,
"RequestId": "3278BEB8-503B-4E46-8F7E-D26E040C9769",
"PageNumber": 1,
"Items": {
"SQLRecord": [
{
"HostAddress": "11.xxx.xxx.xxx",
"TableName": "C1",
"ReturnRowCounts": 2,
"DBName": "test123",
"ExecuteTime": "2019-03-11T03:30:27Z",
"ThreadID": "140682188297984",
"TotalExecutionTimes": 700,
"Syntax": "{ \\\"atype\\\" : \\\"createCollection\\\", \\\"param\\\" : { \\\"ns\\\" : \\\"123.test1\\\" }, \\\"result\\\": \\\"OK\\\" }",
"AccountName": "test"
}
]
}
}
Error codes
|
HTTP status code |
Error code |
Error message |
Description |
|---|---|---|---|
| 400 | InvalidStartTime.Format | Specified start time is not valid. | The specified start time is invalid. |
| 400 | InvalidEndTime.Format | Specified end time is not valid. | |
| 400 | InvalidEndTime.Invalid | Specified end time is before this service active time. | |
| 400 | InvalidParameterCombination | The end time must be greater than the start time. | |
| 400 | InvalidQueryKeyword.Format | Specified Query Keyword is not valid. | |
| 400 | InvalidDatabase.Format | Specified Database is not valid. | |
| 400 | InvalidQueryTime.Format | Specified query time is not valid. | |
| 403 | IncorrectSQLLogActiveStatus | Current DB instance SQL log active status does not support this operation. | |
| 403 | LogApiFrequencyExceeded | Exceeding the allowed frequency of log api. | |
| 403 | ConcurrentTaskExceeded | Concurrent task exceeding the allowed amount. |
See Error Codes for a complete list.
Release notes
See Release Notes for a complete list.