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

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

Go

设置 消息通知 的主题为“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
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    antiddos "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/antiddos/v1"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/antiddos/v1/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/antiddos/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")

    auth := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        Build()

    client := antiddos.NewAntiDDoSClient(
        antiddos.AntiDDoSClientBuilder().
            WithRegion(region.ValueOf("cn-north-4")).
            WithCredential(auth).
            Build())

    request := &model.UpdateAlertConfigRequest{}
	backDoorsWarnConfig:= false
	bruceForceWarnConfig:= false
	highPrivilegeWarnConfig:= false
	remoteLoginWarnConfig:= false
	sendFrequencyWarnConfig:= int32(1)
	wafWarnConfig:= false
	weakPasswordWarnConfig:= false
	warnConfigbody := &model.UpdateAlertConfigRequestBodyWarnConfig{
		AntiDDoS: true,
		BackDoors: &backDoorsWarnConfig,
		BruceForce: &bruceForceWarnConfig,
		HighPrivilege: &highPrivilegeWarnConfig,
		RemoteLogin: &remoteLoginWarnConfig,
		SendFrequency: &sendFrequencyWarnConfig,
		Waf: &wafWarnConfig,
		WeakPassword: &weakPasswordWarnConfig,
	}
	request.Body = &model.UpdateAlertConfigRequestBody{
		WarnConfig: warnConfigbody,
		TopicUrn: "urn:smn:cn-north-7:2d2d90a56a3243bdb909f6a24a27be8d:cnad-test-intl",
		DisplayName: "",
	}
	response, err := client.UpdateAlertConfig(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}
support.huaweicloud.com/api-aad/UpdateAlertConfig.html