All Products
Search
Document Center

ApsaraDB for MongoDB:DescribeAuditRecords

Last Updated:Jan 17, 2023

Queries entries in audit logs of an ApsaraDB for 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.

Authorization information

The following table is the authorization information corresponding to the API, which can be found in the RAM permission policy statement.Action Used in the element to grant the RAM user or RAM role permission to call this API. The specific instructions are as follows:

  • Operation: the value that you can use in the Action element to specify the operation on a resource.
  • Access level: the access level of each operation. The levels are read, write, and list.
  • Resource type: the type of the resource on which you can authorize the RAM user or the RAM role to perform the operation. Take note of the following items:
    • The required resource types are displayed in bold characters.
    • If the permissions cannot be granted at the resource level, All resources is used in the Resource type column of the operation.
  • Condition keyword: refers to the condition keyword defined by the cloud product itself.
  • Associated operation: other operations that the RAM user or the RAM role must have permissions to perform to complete the operation. To complete the operation, the RAM user or the RAM role must have the permissions to perform the associated operations.
Operate access level Resource type conditional keyword Association operation
dds:DescribeAuditRecords READ
  • MongoDB
    acs:dds:{#regionId}:{#accountId}:dbinstance/{#dbinstanceId}
    without
without

Request parameters

Parameter Type Required Description Example
DBInstanceId string Yes

The ID of the instance.

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 the mongos node or shard node whose audit logs you want to query in the instance. If the instance is a sharded cluster instance, you must specify this parameter.

Note This parameter is valid 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 that is specified to query the audit log. 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 end time must be within 24 hours from the start time. Otherwise, the query fails.
2019-03-13T13:11:14Z
Database string No

The name of the database to be queried. By default, all databases are queried.

database****
User string No

The user of the database. If you do not specify this parameter, this operation returns records of all users.

root
Form string No

The form of the audit log that the operation returns. Valid values:

  • File: triggers the generation of audit logs. If this parameter is set to File, only common parameters are returned.
  • Stream: returns data streams.

Default value: Stream.

Stream
QueryKeywords string No

The keywords that are used for queries. Separate multiple keywords with spaces. The maximum number of keywords is 10.

slow
PageSize integer No

The number of entries to return on each page. Valid values: 30, 50, and 100. Default value: 30.

30
PageNumber integer No

The number of the page to return. The value must be an integer that is greater than 0. Default value: 1.

1
OrderType string No

The order of time in which the log entries to return are sorted. Valid values:

  • asc: The log entries are sorted by time in ascending order.
  • desc: The log entries are sorted by time in descending order.
asc

Response parameters

Parameter Type Description Example
object
TotalRecordCount integer

The total number of entries.

40
PageRecordCount integer

The maximum number of entries on the current page.

30
RequestId string

The ID of the request.

3278BEB8-503B-4E46-8F7E-D26E040C9769
PageNumber integer

The number of the page to return.

1
Items array

An array that consists of the information of audit log entries.

object
HostAddress string

The IP address of the client.

11.xxx.xxx.xxx
TableName string

The name of the collection.

C1
ReturnRowCounts long

The number of SQL audit log entries that are returned.

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 displayed in UTC.

2019-03-11T03:30:27Z
ThreadID string

The ID of the thread that is recorded in the SQL audit log entry.

140682188297984
TotalExecutionTimes long

The duration of the statement execution. Unit: microseconds.

700
Syntax string

The statement that was executed.

{ \"atype\" : \"createCollection\", \"param\" : { \"ns\" : \"123.test1\" }, \"result\": \"OK\" }
AccountName string

The account of the database.

root

Example

Normal return example

JSONFormat

{
  "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": "root"
      }
    ]
  }
}

Error codes

Http code Error code Error message
400 InvalidStartTime.Format Specified start time is not valid.
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.

For a list of error codes, visit the API error center.