DDOS防护 AAD-更新告警配置信息:Java

时间:2024-04-09 10:10:12

Java

设置 消息通知 的主题为“urn:smn:cn-north-7:2d2d90a56a3243bdb909f6a24a27be8d:cnad-test-intl”,并配置需要告警通知的攻击类型为DDoS攻击

 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
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.antiddos.v1.region.AntiDDoSRegion;
import com.huaweicloud.sdk.antiddos.v1.*;
import com.huaweicloud.sdk.antiddos.v1.model.*;


public class UpdateAlertConfigSolution {

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

        AntiDDoSClient client = AntiDDoSClient.newBuilder()
                .withCredential(auth)
                .withRegion(AntiDDoSRegion.valueOf("cn-north-4"))
                .build();
        UpdateAlertConfigRequest request = new UpdateAlertConfigRequest();
        UpdateAlertConfigRequestBody body = new UpdateAlertConfigRequestBody();
        UpdateAlertConfigRequestBodyWarnConfig warnConfigbody = new UpdateAlertConfigRequestBodyWarnConfig();
        warnConfigbody.withAntiDDoS(true)
            .withBackDoors(false)
            .withBruceForce(false)
            .withHighPrivilege(false)
            .withRemoteLogin(false)
            .withSendFrequency(1)
            .withWaf(false)
            .withWeakPassword(false);
        body.withWarnConfig(warnConfigbody);
        body.withTopicUrn("urn:smn:cn-north-7:2d2d90a56a3243bdb909f6a24a27be8d:cnad-test-intl");
        body.withDisplayName("");
        request.withBody(body);
        try {
            UpdateAlertConfigResponse response = client.updateAlertConfig(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-aad/UpdateAlertConfig.html