UpsertCollectionPolicy

Updated at: 2025-03-28 03:59

Creates a log collection policy for a cloud service. This way, logs can be automatically collected from the service.

Debugging

You can run this interface directly in OpenAPI Explorer, saving you the trouble of calculating signatures. After running successfully, OpenAPI Explorer can automatically generate SDK code samples.

Authorization information

There is currently no authorization information disclosed in the API.

Request syntax

POST /collectionpolicy HTTP/1.1

Request parameters

ParameterTypeRequiredDescriptionExample
ParameterTypeRequiredDescriptionExample
bodyobjectNo

The body of the request.

policyNamestringYes

The name must meet the following requirements:

  • The name can contain only lowercase letters, digits, hyphens (-), and underscores (_).
  • The name must start with a letter.
  • The name must be 3 to 63 characters in length.
your_log_policy
productCodestringYes

The code of the service.

oss
dataCodestringYes

The code of the log type.

access_log
enabledbooleanYes

Specifies whether to enable the policy.

true
policyConfigobjectYes

The configurations of the policy.

resourceModestringYes

The resource collection mode. Valid values: all, attributeMode, and instanceMode. The value all specifies that logs of all instances within your account are collected to the default logstore. The value attributeMode specifies that logs are collected based on the regions of instances and resource tags. The value instanceMode specifies that logs are collected based on instance IDs.

all
resourceTagsobjectNo

The resource tags. This parameter takes effect only when resourceMode is set to attributeMode. If you leave this parameter empty, resource tag-based filtering is not performed. The system considers that all instances are matched. If you specify a value for this parameter, logs of instances that use the specified resource tags are collected. Logs are collected from an instance only if the resource tags and region of the instance match the specified conditions.

{"tag1":"value1",“tag2":"value2"}
regionsarrayNo

The regions of the instances. This parameter takes effect only when resourceMode is set to attributeMode. Wildcard characters are supported. If you leave this parameter empty, region-based filtering is not performed. The system considers that all instances are matched. If you specify a value for this parameter, logs of instances that reside in the specified regions are collected. Logs are collected from an instance only if the resource tags and region of the instance match the specified conditions.

stringNo

The ID of the region.

cn-hangzhou
instanceIdsarrayNo

The IDs of the instances. This parameter takes effect only when resourceMode is set to instanceMode. Logs are collected only from instances that use the specified IDs.

stringNo

The ID of the instance.

your-test-bucket1
centralizeEnabledbooleanNo

Specifies whether to enable centralized storage. Default value: false.

false
centralizeConfigobjectNo

The configurations of centralized storage.

destRegionstringNo

The destination region for centralized storage.

cn-beijing
destProjectstringNo

The destination project for centralized storage. Make sure that the region of the destination project is consistent with the region specified by destRegion.

your-sls-project-in-beijing
destLogstorestringNo

The destination logstore for centralized storage. Make sure that the region of the destination logstore is consistent with the region specified by destRegion and the destination logstore belongs to the destination project specified by destProject.

your-sls-logstore-in-beijing
destTTLintegerNo

The data retention period for centralized storage. Unit: days. This parameter takes effect only when you use an existing logstore for centralized storage.

your-sls-logstore-ttl
dataConfigobjectNo

The data configurations. The configuration is returned only for global logs. For example, if productCode is set to sls, the configuration is returned.

dataRegionstringNo

The region for storing the global logs that are collected for the first time.

cn-beijing
resourceDirectoryobjectNo

The configurations of the resource directory. The account must have activated the resource directory and be a management account or a delegated administrator of the resource directory.

accountGroupTypestringNo

The mode of the resource directory. Valid values: all and custom.

all,custom
membersarrayNo

The members. If accountGroupType is set to custom, the members are returned.

stringNo

The ID of the Alibaba Cloud account.

165***********50

Response parameters

ParameterTypeDescriptionExample
ParameterTypeDescriptionExample
headersobject
Content-Typestring
Content-Lengthstring
Datestring
Connectionstring
x-log-requestidstring
Serverstring

For more information about error codes, see Manage collection rules in the new version of Log Audit Service.

Examples

Sample success responses

JSONformat

{}

Error codes

For a list of error codes, visit the Service error codes.

Change history

Change timeSummary of changesOperation
Change timeSummary of changesOperation
2023-10-19The internal configuration of the API is changed, but the call is not affectedView Change Details
  • On this page (1)
  • Debugging
  • Authorization information
  • Request syntax
  • Request parameters
  • Response parameters
  • Examples
  • Error codes
  • Change history
Feedback