文档首页/ 数据安全中心 DSC/ API参考/ API/ 扫描任务/ 添加扫描Job - AddScanJob
更新时间:2026-10-20 GMT+08:00
分享

添加扫描Job - AddScanJob

功能介绍

功能介绍:创建扫描作业。 关键参数说明:name、asset_ids、cycle必填;rule_group_ids与scan_template_ids二选一;template_type为TRADITIONAL/LLM;scan_mode为FULL/INCREMENTAL(默认FULL)。 返回值说明:返回操作状态。

调用方法

请参见如何调用API。

授权信息

账号具备所有API的调用权限,如果使用账号下的IAM用户调用当前API,该IAM用户需具备调用API所需的权限。

  • 如果使用角色与策略授权,具体权限要求请参见权限和授权项。
  • 如果使用身份策略授权,当前API调用无需身份策略权限。

URI

POST /v1/{project_id}/sdg/scan/job

表1 路径参数

参数

是否必选

参数类型

描述

project_id

是

String

参数解释:

项目ID,标识用户在数据安全中心控制台中创建的项目

约束限制:

不涉及

取值范围:

长度为32个字符的字符串

默认取值:

不涉及

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

是

String

参数解释:

用户Token,用于接口请求鉴权,可通过调用IAM服务查询用户Token接口获取

约束限制:

不涉及

取值范围:

不涉及

默认取值:

不涉及

表3 请求Body参数

参数

是否必选

参数类型

描述

name

是

String

参数解释:

扫描任务名称

约束限制:

最大长度1024字符

取值范围:

不涉及

默认取值:

不涉及

asset_scope

否

Array of AssetScope objects

参数解释:

作业范围

约束限制:

数组最大500个元素

取值范围:

不涉及

默认取值:

不涉及

asset_ids

是

Array of strings

参数解释:

资产ID列表,指定扫描作业覆盖的资产,列表元素为字符串类型的资产ID,可通过调用查询资产列表接口获取

约束限制:

数组最大500个元素

取值范围:

数组类型

默认取值:

不涉及

rule_group_ids

否

Array of strings

参数解释:

规则分组ID列表,指定作业使用的规则分组,列表元素为字符串类型的规则分组ID,可通过调用查询规则分组列表接口获取

约束限制:

数组最大500个元素

取值范围:

数组类型

默认取值:

不涉及

scan_template_ids

否

Array of strings

参数解释:

扫描模板ID列表,指定作业使用的识别扫描模板,列表元素为字符串类型的扫描模板ID,可通过调用查询模板列表接口获取

约束限制:

数组最大500个元素

取值范围:

数组类型

默认取值:

不涉及

template_type

否

String

参数解释:

作业类型

约束限制:

不涉及

取值范围:

  • TRADITIONAL-传统识别模板

  • LLM-智能识别模板

默认取值:

不涉及

sampling_proportion

否

Integer

参数解释:

采样比例,用于指定扫描时对数据的采样比例,以百分比表示

约束限制:

不涉及

取值范围:

0~100之间的整数,单位为百分比(%)

默认取值:

不涉及

cycle

是

String

参数解释:

扫描周期

约束限制:

不涉及

取值范围:

  • ONCE-单次执行

  • DAY-每天

  • WEEK-每周

  • MONTH-每月

默认取值:

不涉及

time_zone

否

String

参数解释:

时间可用区

约束限制:

最大长度1024字符

取值范围:

不涉及

默认取值:

不涉及

start_time

否

Long

参数解释:

开始时间,为Unix时间戳,单位为毫秒,表示任务计划开始扫描的时间点

约束限制:

不涉及

取值范围:

毫秒级Unix时间戳

默认取值:

不涉及

use_nlp

否

Boolean

参数解释:

是否使用自然语言处理,用于指定识别扫描时是否启用NLP技术辅助数据识别

约束限制:

不涉及

取值范围:

true-使用,false-不使用

默认取值:

不涉及

open

否

Boolean

参数解释:

是否开启扫描

约束限制:

不涉及

取值范围:

不涉及

默认取值:

不涉及

topic_urn

否

String

参数解释:

主题URN,用于指定扫描任务完成后发送通知的消息主题,可通过消息通知服务SMN查询主题列表获取主题URN

约束限制:

不涉及

取值范围:

字符串类型

默认取值:

不涉及

credential_types

否

Array of strings

参数解释:

凭证类型

约束限制:

不涉及

取值范围:

不涉及

默认取值:

不涉及

incremental_only

否

Boolean

参数解释:

是否仅扫描增量数据,用于指定扫描作业是否只扫描新增或变更的增量数据

约束限制:

不涉及

取值范围:

true-是,false-否

默认取值:

不涉及

scan_time_scope

否

Integer

参数解释:

扫描时间范围,表示按指定时间窗口内的数据变更进行扫描的时间范围

约束限制:

不涉及

取值范围:

0~2147483647之间的整数,单位为天

默认取值:

0

scan_sensitivity

否

String

参数解释:

扫描敏感度,用于指定扫描作业的敏感度级别,不同敏感度对应不同的检测强度

约束限制:

不涉及

取值范围:

  • NULL:未设置扫描敏感度

  • LOW:低敏感度

  • MIDDLE:中等敏感度

  • HIGH:高敏感度

默认取值:

不涉及

scan_mode

否

String

参数解释:

作业模式

约束限制:

不涉及

取值范围:

  • FULL-全量扫描

  • INCREMENTAL-增量扫描

默认取值:

FULL

表4 AssetScope

参数

是否必选

参数类型

描述

asset_id

否

Array of strings

参数解释:

资产ID列表,作业覆盖的扫描资产标识,列表元素为字符串类型的资产ID,可通过调用查询资产列表接口获取

约束限制:

不涉及

取值范围:

数组类型

默认取值:

不涉及

scope

否

String

参数解释:

资产范围,用于描述扫描范围配置

约束限制:

不涉及

取值范围:

字符串类型

默认取值:

不涉及

pattern

否

String

参数解释:

匹配模式

约束限制:

最大长度1024字符

取值范围:

不涉及

默认取值:

不涉及

include

否

Boolean

参数解释:

是否包含

约束限制:

不涉及

取值范围:

true-是,false-否

默认取值:

不涉及

depth

否

Integer

参数解释:

扫描深度,表示数据扫描的层级深度,用于控制多层级数据对象的扫描深度

约束限制:

不涉及

取值范围:

0~2147483647之间的整数,单位为层

默认取值:

不涉及

index

否

Integer

参数解释:

资产索引

约束限制:

不涉及

取值范围:

不涉及

默认取值:

不涉及

type

否

Integer

参数解释:

资产类型

约束限制:

不涉及

取值范围:

不涉及

默认取值:

不涉及

响应参数

状态码:200

表5 响应Body参数

参数

参数类型

描述

status

String

参数解释:

操作结果状态

取值范围:

不涉及

msg

String

参数解释:

操作结果描述信息

取值范围:

不涉及

id

String

参数解释:

资源ID,唯一标识

取值范围:

不涉及

请求示例

添加扫描Job

{
  "name" : "scan-job-01",
  "asset_scope" : [ {
    "asset_id" : [ "5c9d0e1f-2a3b-4c4d-9e0f-8a7b6c5d4e3f", "8f2a3b4c-5d6e-4f7a-2b3c-1d0e9f8a7b6c" ],
    "scope" : "PRE",
    "pattern" : "\\d{11}",
    "include" : true,
    "depth" : 1,
    "index" : 100,
    "type" : 100
  }, {
    "asset_id" : [ "5c9d0e1f-2a3b-4c4d-9e0f-8a7b6c5d4e3f", "8f2a3b4c-5d6e-4f7a-2b3c-1d0e9f8a7b6c" ],
    "scope" : "PRE",
    "pattern" : "\\d{11}",
    "include" : true,
    "depth" : 1,
    "index" : 100,
    "type" : 100
  } ],
  "asset_ids" : [ "5c9d0e1f-2a3b-4c4d-9e0f-8a7b6c5d4e3f", "8f2a3b4c-5d6e-4f7a-2b3c-1d0e9f8a7b6c" ],
  "rule_group_ids" : [ "4b8c9d0e-1f2a-4b3c-8d9e-7f6a5b4c3d2e", "7e1f2a3b-4c5d-4e6f-1a2b-0c9d8e7f6a5b" ],
  "scan_template_ids" : [ "7e1f2a3b-4c5d-4e6f-1a2b-0c9d8e7f6a5b", "0b4c5d6e-7f8a-4b9c-4d5e-3f2a1b0c9d8e" ],
  "template_type" : "BUILT_IN",
  "sampling_proportion" : 100,
  "cycle" : "DAY",
  "time_zone" : "Asia/Shanghai",
  "start_time" : 1700000000000,
  "use_nlp" : true,
  "open" : true,
  "topic_urn" : "urn:smn:cn-north-4:826314dd1b5b4037b9765f9b7a17df46:classification-notice",
  "credential_types" : [ "OBS" ],
  "incremental_only" : true,
  "scan_time_scope" : 1700000000000,
  "scan_sensitivity" : "HIGH",
  "scan_mode" : "AUTO"
}

响应示例

状态码:200

{
  "status" : "success",
  "msg" : "创建扫描任务成功",
  "id" : "8f2a3b4c-5d6e-4f7a-2b3c-1d0e9f8a7b6c"
}

SDK代码示例

SDK代码示例如下。

Java

添加扫描Job

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package com.huaweicloud.sdk.test;

import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.exception.ConnectionException;
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
import com.huaweicloud.sdk.core.exception.ServiceResponseException;
import com.huaweicloud.sdk.dsc.v1.region.DscRegion;
import com.huaweicloud.sdk.dsc.v1.*;
import com.huaweicloud.sdk.dsc.v1.model.*;

import java.util.List;
import java.util.ArrayList;

public class AddScanJobSolution {

    public static void main(String[] args) {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        String ak = System.getenv("CLOUD_SDK_AK");
        String sk = System.getenv("CLOUD_SDK_SK");
        String projectId = "{project_id}";

        ICredential auth = new BasicCredentials()
                .withProjectId(projectId)
                .withAk(ak)
                .withSk(sk);

        DscClient client = DscClient.newBuilder()
                .withCredential(auth)
                .withRegion(DscRegion.valueOf("<YOUR REGION>"))
                .build();
        AddScanJobRequest request = new AddScanJobRequest();
        ScanJobRequest body = new ScanJobRequest();
        List<String> listbodyRuleGroupIds = new ArrayList<>();
        listbodyRuleGroupIds.add("4b8c9d0e-1f2a-4b3c-8d9e-7f6a5b4c3d2e");
        listbodyRuleGroupIds.add("7e1f2a3b-4c5d-4e6f-1a2b-0c9d8e7f6a5b");
        List<String> listbodyAssetIds = new ArrayList<>();
        listbodyAssetIds.add("5c9d0e1f-2a3b-4c4d-9e0f-8a7b6c5d4e3f");
        listbodyAssetIds.add("8f2a3b4c-5d6e-4f7a-2b3c-1d0e9f8a7b6c");
        body.withUseNlp(true);
        body.withTopicUrn("urn:smn:cn-north-4:826314dd1b5b4037b9765f9b7a17df46:classification-notice");
        body.withTimeZone("Asia/Shanghai");
        body.withStartTime(1700000000000L);
        body.withRuleGroupIds(listbodyRuleGroupIds);
        body.withOpen(true);
        body.withName("scan-job-01");
        body.withCycle(ScanJobRequest.ScanJobRequest.fromValue("DAY"));
        body.withAssetIds(listbodyAssetIds);
        request.withBody(body);
        try {
            AddScanJobResponse response = client.addScanJob(request);
            System.out.println(response.toString());
        } catch (ConnectionException e) {
            e.printStackTrace();
        } catch (RequestTimeoutException e) {
            e.printStackTrace();
        } catch (ServiceResponseException e) {
            e.printStackTrace();
            System.out.println(e.getHttpStatusCode());
            System.out.println(e.getRequestId());
            System.out.println(e.getErrorCode());
            System.out.println(e.getErrorMsg());
        }
    }
}

Python

添加扫描Job

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkdsc.v1.region.dsc_region import DscRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkdsc.v1 import *

if __name__ == "__main__":
    # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak = os.environ["CLOUD_SDK_AK"]
    sk = os.environ["CLOUD_SDK_SK"]
    projectId = "{project_id}"

    credentials = BasicCredentials(ak, sk, projectId)

    client = DscClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(DscRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = AddScanJobRequest()
        listRuleGroupIdsbody = [
            "4b8c9d0e-1f2a-4b3c-8d9e-7f6a5b4c3d2e",
            "7e1f2a3b-4c5d-4e6f-1a2b-0c9d8e7f6a5b"
        ]
        listAssetIdsbody = [
            "5c9d0e1f-2a3b-4c4d-9e0f-8a7b6c5d4e3f",
            "8f2a3b4c-5d6e-4f7a-2b3c-1d0e9f8a7b6c"
        ]
        request.body = ScanJobRequest(
            use_nlp=True,
            topic_urn="urn:smn:cn-north-4:826314dd1b5b4037b9765f9b7a17df46:classification-notice",
            time_zone="Asia/Shanghai",
            start_time=1700000000000,
            rule_group_ids=listRuleGroupIdsbody,
            open=True,
            name="scan-job-01",
            cycle="DAY",
            asset_ids=listAssetIdsbody
        )
        response = client.add_scan_job(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

Go

添加扫描Job

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    dsc "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dsc/v1"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dsc/v1/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dsc/v1/region"
)

func main() {
    // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak := os.Getenv("CLOUD_SDK_AK")
    sk := os.Getenv("CLOUD_SDK_SK")
    projectId := "{project_id}"

    auth, err := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        WithProjectId(projectId).
        SafeBuild()

    if err != nil {
        fmt.Println(err)
        return
    }

    hcClient, err := dsc.DscClientBuilder().
         WithRegion(region.ValueOf("<YOUR REGION>")).
         WithCredential(auth).
         SafeBuild()


    if err != nil {
        fmt.Println(err)
        return
    }

    client := dsc.NewDscClient(hcClient)

    request := &model.AddScanJobRequest{}
	var listRuleGroupIdsbody = []string{
        "4b8c9d0e-1f2a-4b3c-8d9e-7f6a5b4c3d2e",
	    "7e1f2a3b-4c5d-4e6f-1a2b-0c9d8e7f6a5b",
    }
	var listAssetIdsbody = []string{
        "5c9d0e1f-2a3b-4c4d-9e0f-8a7b6c5d4e3f",
	    "8f2a3b4c-5d6e-4f7a-2b3c-1d0e9f8a7b6c",
    }
	useNlpScanJobRequest:= true
	topicUrnScanJobRequest:= "urn:smn:cn-north-4:826314dd1b5b4037b9765f9b7a17df46:classification-notice"
	timeZoneScanJobRequest:= "Asia/Shanghai"
	startTimeScanJobRequest:= int64(1700000000000)
	openScanJobRequest:= true
	request.Body = &model.ScanJobRequest{
		UseNlp: &useNlpScanJobRequest,
		TopicUrn: &topicUrnScanJobRequest,
		TimeZone: &timeZoneScanJobRequest,
		StartTime: &startTimeScanJobRequest,
		RuleGroupIds: listRuleGroupIdsbody,
		Open: &openScanJobRequest,
		Name: "scan-job-01",
		Cycle: model.GetScanJobRequestCycleEnum().DAY,
		AssetIds: listAssetIdsbody,
	}
	response, err := client.AddScanJob(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

更多

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

200

请求已成功

错误码

请参见错误码。

相关文档