Queries the audit logs of a MongoDB instance.
Operation description
The audit log feature must be enabled for the instance before you call this operation. Otherwise, the returned audit log content is empty.
This operation applies to instances of the General-purpose local disk and Dedicated local disk specification types.
This operation can be called up to 30 times per minute. Calls that exceed this limit are throttled. Do not call this operation at a high frequency. If high-frequency calls are required, 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 specify a sharded cluster instance ID for this parameter, you must also specify the NodeId parameter. |
dds-bp12c5b040dc**** |
| NodeId |
string |
No |
Instance ID of a mongos node or shard node in the sharded cluster instance. Note
This parameter is available only when DBInstanceId is set to instance ID of a sharded cluster instance. |
d-bp128a003436**** |
| StartTime |
string |
Yes |
The start time of the 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 time of the 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 end time and the start time cannot exceed 24 hours. If the time range exceeds 24 hours, the call fails. |
2019-03-13T13:11:14Z |
| Database |
string |
No |
The name of the database. The default value is all databases. |
database**** |
| User |
string |
No |
The database account. The default value is all accounts. |
test |
| Form |
string |
No |
The display format of the returned audit records. Valid values:
Note
The File value is deprecated. Valid values:
|
Stream |
| QueryKeywords |
string |
No |
The keywords to query. Separate multiple keywords with spaces. You can specify a maximum of 10 keywords. |
slow |
| LogicalOperator |
string |
No |
The logical operator for keyword search. The default value is and. Valid values:
|
and |
| PageSize |
integer |
No |
The number of records per page. Valid values: 30 (default), 50, and 100. |
30 |
| PageNumber |
integer |
No |
The page number. The value must be greater than 0 and cannot exceed the maximum value of the Integer type. Default value: 1. |
1 |
| OrderType |
string |
No |
The order in which the queried slow logs are sorted by time. Valid values:
Valid values:
|
asc |
Response elements
|
Element |
Type |
Description |
Example |
|
object |
The total number of records. |
||
| TotalRecordCount |
integer |
The total number of records. |
40 |
| PageRecordCount |
integer |
The maximum number of records 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 instance information. |
||
| HostAddress |
string |
The client IP address. |
11.xxx.xxx.xxx |
| TableName |
string |
The name of the MongoDB collection. |
C1 |
| ReturnRowCounts |
integer |
The number of returned records. |
2 |
| DBName |
string |
The name of the database. |
test123 |
| ExecuteTime |
string |
The time when the statement was executed. The time is in the yyyy-MM-ddTHH:mm:ssZ format. The time is in UTC. |
2019-03-11T03:30:27Z |
| ThreadID |
string |
The thread ID. |
140682188297984 |
| TotalExecutionTimes |
integer |
The execution duration, 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. | The specified EndTime parameter is invalid. Specify a valid end time point in the yyyy-MM-ddTHH:mmZ format. The time must be in UTC. The end time must be later than the start time. |
| 400 | InvalidEndTime.Invalid | Specified end time is before this service active time. | |
| 400 | InvalidParameterCombination | The end time must be greater than the start time. | The end time must be later 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. | StartTime or EndTime parameter is null or illegal. |
| 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.