获取任务列表 - ShowScanJobs
功能介绍
功能介绍:获取扫描任务列表,支持分页和时间范围过滤。 关键参数说明:支持limit/offset分页(limit默认100)、start_time/end_time时间范围过滤、content内容过滤。 返回值说明:返回任务总数及任务列表(含状态、进度、安全等级等)。
调用方法
请参见如何调用API。
授权信息
账号具备所有API的调用权限,如果使用账号下的IAM用户调用当前API,该IAM用户需具备调用API所需的权限。
- 如果使用角色与策略授权,具体权限要求请参见权限和授权项。
- 如果使用身份策略授权,当前API调用无需身份策略权限。
URI
GET /v1/{project_id}/sdg/scan/jobs
| 参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
| project_id | 是 | String | 参数解释: 项目ID,标识用户在数据安全中心控制台中创建的项目 约束限制: 不涉及 取值范围: 长度为32个字符的字符串 默认取值: 不涉及 |
| 参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
| limit | 否 | Integer | 参数解释: 每页返回的数量限制,用于指定分页查询时每页返回的任务条数,单位为条 约束限制: 不涉及 取值范围: 0-200 默认取值: 100 |
| offset | 否 | Integer | 参数解释: 分页偏移量,用于指定分页查询时跳过的记录条数,单位为条 约束限制: 不涉及 取值范围: 不涉及 默认取值: 0 |
| start_time | 否 | String | 参数解释: 开始时间,用于按时间范围过滤任务列表的范围起始点 约束限制: 不涉及 取值范围: 不涉及 默认取值: 不涉及 |
| end_time | 否 | String | 参数解释: 结束时间 约束限制: 不涉及 取值范围: 不涉及 默认取值: 不涉及 |
| content | 否 | String | 参数解释: 扫描内容 约束限制: 不涉及 取值范围: 不涉及 默认取值: 不涉及 |
请求参数
| 参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
| X-Auth-Token | 是 | String | 参数解释: 用户Token,用于接口请求鉴权,可通过调用IAM服务查询用户Token接口获取 约束限制: 不涉及 取值范围: 不涉及 默认取值: 不涉及 |
响应参数
状态码:200
| 参数 | 参数类型 | 描述 |
|---|---|---|
| total | Long | 参数解释: 总记录数,标识符合查询条件的任务记录总量 取值范围: 整数 |
| tasks | Array of ScanJob objects | 参数解释: 扫描任务列表,列表元素为ScanJob对象,包含扫描作业的详细信息 取值范围: 数组类型 |
| 参数 | 参数类型 | 描述 |
|---|---|---|
| id | String | 参数解释: 资源ID,唯一标识 取值范围: 不涉及 |
| name | String | 参数解释: 扫描任务名称 取值范围: 不涉及 |
| rule_groups | Array of strings | 参数解释: 规则分组列表,列表元素为字符串类型 取值范围: 数组类型 |
| scan_templates | Map<String,String> | 参数解释: 扫描模板,为Map<String,String>类型,Key为模板标识,Value为模板名称 取值范围: Map类型 |
| cycle | String | 参数解释: 扫描周期 取值范围: 不涉及 |
| status | String | 参数解释: 操作结果状态 取值范围: |
| last_run_time | Long | 参数解释: 上次运行时间,为Unix时间戳,单位为毫秒,表示任务上次运行的时间 取值范围: Unix时间戳,单位为毫秒 |
| create_time | Long | 参数解释: 创建时间,为Unix时间戳,单位为秒,表示任务的创建时间 取值范围: Unix时间戳,单位为秒 |
| last_scan_risk | String | 参数解释: 上次扫描风险 取值范围: 不涉及 |
| use_nlp | Boolean | 参数解释: 是否使用自然语言处理,标识任务扫描时是否启用NLP技术 取值范围: true-使用,false-不使用 |
| open | Boolean | 参数解释: 是否开启扫描 取值范围: true-是,false-否 |
| topic_urn | String | 参数解释: 主题URN 取值范围: 不涉及 |
| start_time | Long | 参数解释: 开始时间,为Unix时间戳,单位为秒,表示任务开始扫描的时间 取值范围: Unix时间戳,单位为秒 |
| task_source | String | 参数解释: 任务来源,标识任务的来源方式或渠道 取值范围: 字符串类型 |
| workspace_id | String | 参数解释: 工作空间ID,标识任务所属的工作空间 取值范围: 字符串类型 |
| security_level_name | String | 参数解释: 安全等级名称 取值范围: 不涉及 |
| security_level_color | Integer | 参数解释: 安全级别颜色,为颜色编码值,标识任务对应安全级别的显示颜色 取值范围: 整数值 |
| asset_infos | Array of AssetInfo objects | 参数解释: 资产信息列表,列表元素为AssetInfo对象 取值范围: 数组类型 |
| scan_time_scope | Integer | 参数解释: 扫描时间范围,表示任务扫描覆盖的时间范围 取值范围: 整数,单位为天 |
| scan_sensitivity | String | 参数解释: 扫描敏感度 取值范围: |
| template_type | String | 参数解释: 扫描作业类型 取值范围: |
| scan_mode | String | 参数解释: 扫描作业模式 取值范围: |
| progress | Integer | 参数解释: 扫描进度,表示任务当前扫描完成的比例 取值范围: 0~100之间的整数,单位为百分比(%) |
请求示例
获取任务列表
/v1/2b31ed520aabbccddeedb6e571234567/sdg/scan/jobs
响应示例
状态码:200
{
"total" : 1,
"tasks" : [ {
"id" : "8f2a3b4c-5d6e-4f7a-2b3c-1d0e9f8a7b6c",
"name" : "scan-job-01",
"rule_groups" : [ "scan-job-01" ],
"scan_templates" : {
"scan-template-01" : "scan-job-01"
},
"cycle" : "DAY",
"status" : "FINISHED",
"last_run_time" : 1700000000000,
"create_time" : 1700000000000,
"last_scan_risk" : "scan-job-01",
"use_nlp" : true,
"open" : true,
"topic_urn" : "urn:smn:cn-north-4:826314dd1b5b4037b9765f9b7a17df46:classification-notice",
"start_time" : 1700000000000,
"task_source" : "scan-job-01",
"workspace_id" : "8f2a3b4c-5d6e-4f7a-2b3c-1d0e9f8a7b6c",
"security_level_name" : "scan-job-01",
"security_level_color" : 3,
"asset_infos" : [ {
"asset_id" : "8f2a3b4c-5d6e-4f7a-2b3c-1d0e9f8a7b6c",
"asset_type" : "OBS"
} ],
"scan_time_scope" : 30,
"scan_sensitivity" : "HIGH",
"template_type" : "TRADITIONAL",
"scan_mode" : "FULL",
"progress" : 100
} ]
} SDK代码示例
SDK代码示例如下。
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 | 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.*; public class ShowScanJobsSolution { 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(); ShowScanJobsRequest request = new ShowScanJobsRequest(); try { ShowScanJobsResponse response = client.showScanJobs(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()); } } } |
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 | # 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 = ShowScanJobsRequest() response = client.show_scan_jobs(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) |
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 | 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.ShowScanJobsRequest{} response, err := client.ShowScanJobs(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } |
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
| 状态码 | 描述 |
|---|---|
| 200 | 请求已成功 |
错误码
请参见错误码。