安全云脑 SECMASTER-更新指标:Java

时间:2023-12-06 18:52:41

Java

更新一条指标,指标触发标志为否,值为ip。

 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
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.secmaster.v2.region.SecMasterRegion;
import com.huaweicloud.sdk.secmaster.v2.*;
import com.huaweicloud.sdk.secmaster.v2.model.*;


public class UpdateIndicatorSolution {

    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");

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

        SecMasterClient client = SecMasterClient.newBuilder()
                .withCredential(auth)
                .withRegion(SecMasterRegion.valueOf("cn-north-4"))
                .build();
        UpdateIndicatorRequest request = new UpdateIndicatorRequest();
        UpdateIndicatorRequestBody body = new UpdateIndicatorRequestBody();
        IndicatorDataObjectDetailDataSource dataSourceDataObject = new IndicatorDataObjectDetailDataSource();
        dataSourceDataObject.withSourceType(1)
            .withDomainId("ac7438b990ef4a37b741004eb45e8bf4")
            .withProjectId("5b8bb3c888db498f9eeaf1023f7ba597")
            .withRegionId("cn-xxx-7");
        IndicatorDataObjectDetailIndicatorType indicatorTypeDataObject = new IndicatorDataObjectDetailIndicatorType();
        indicatorTypeDataObject.withIndicatorType("ipv6")
            .withId("ac794b2dfab9fe8c0676587301a636d3")
            .withCategory("ipv6")
            .withLayoutId("4e2d7f64-a66d-3236-a8c1-704636ced9a7");
        IndicatorDataObjectDetail dataObjectbody = new IndicatorDataObjectDetail();
        dataObjectbody.withIndicatorType(indicatorTypeDataObject)
            .withValue("ip")
            .withDataSource(dataSourceDataObject)
            .withFirstReportTime("2023-07-04T16:47:01Z+0800")
            .withGranularMarking(1)
            .withProjectId("909494e3-558e-46b6-a9eb-07a8e18ca62f")
            .withStatus("Open")
            .withWorkspaceId("909494e3-558e-46b6-a9eb-07a8e18ca620");
        body.withDataObject(dataObjectbody);
        request.withBody(body);
        try {
            UpdateIndicatorResponse response = client.updateIndicator(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());
        }
    }
}
support.huaweicloud.com/api-secmaster/UpdateIndicator.html