Querying Job Audit Logs

Sample Code

You can use the API to query job audit logs. Sample code is as follows:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
import com.huaweicloud.cs.java.v1.client.ApiException;
import com.huaweicloud.cs.java.v1.LogApi;


LogApi apiInstance = new LogApi(apiClient);//apiClient is created when initializing a CS API client.
String xProjectId = "xProjectId_example"; // String | Project ID used for obtaining the token for the project.
String resourceType = "resourceType_example"; // String | Resource type, including job, template, and cluster.
String cursor = "cursor_example"; // String | Job ID, template ID, or cluster ID.
String resourceId = "resourceId_example"; // String | Resource ID.
Integer pageNumber = 0; // Integer | Queried page.
Integer limit = 10; // Integer | Maximum number of records to be displayed.
try {
    AuditLogResponse result = apiInstance.getAuditLogs(xProjectId, resourceType, cursor, resourceId, pageNumber, limit);
    System.out.println(result);
} catch (ApiException e) {
    System.err.println("Exception when calling LogApi#getAuditLogs");
    System.err.println(e.getResponseBody());
    e.printStackTrace();
}

Parameter Description

Table 1 Parameters

Parameter

Mandatory

Type

Description

xProjectId

Yes

String

Project ID. This parameter is used to obtain the token for the project.

resourceType

Yes

String

Resource type. The parameter value can be job, template, and cluster.

cursor

No

String

Event ID. If cursor is specified, the request parameter page_number is invalid.

resourceId

No

String

Resource ID.

pageNumber

No

Integer

Page number that is queried. The default value is 0.

limit

No

Integer

Maximum number of records that can be queried. The default value is 10.

Table 2 Parameters involved in AuditLogResponse

Parameter

Mandatory

Type

Description

messageId

No

String

Message type ID.

message

No

String

Message content.

currentTime

No

Integer

Current time, expressed by milliseconds.

payload

No

-

For details about parameter types, see Table 3.

Table 3 Parameters involved in AuditLogResponsePayload

Parameter

Mandatory

Type

Description

total

No

Integer

Number audit log records in the query result.

traces

No

List<AuditLog>

For details about parameter types, see Table 4.

Table 4 Parameters involved in AuditLog

Parameter

Mandatory

Type

Description

resourceId

No

String

Resource ID.

resourceName

No

String

Resource name.

eventName

No

String

Event name.

eventType

No

String

Source type of an event.

  • ConsoleAction
  • ApiCall
  • SystemAction

eventRating

No

String

Event level. Values include the following:

  • normal
  • warning
  • incident

opUser

No

String

Information about the tenant that initiates the request.

opTime

No

Integer

Timestamp of the sent event.

opIp

No

String

IP address of the tenant that initiates the request.

opResult

No

String

Event response content.