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

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

Python

设置 消息通知 的主题为“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
# coding: utf-8

from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkantiddos.v1.region.antiddos_region import AntiDDoSRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkantiddos.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.getenv("CLOUD_SDK_AK")
    sk = os.getenv("CLOUD_SDK_SK")

    credentials = BasicCredentials(ak, sk) \

    client = AntiDDoSClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(AntiDDoSRegion.value_of("cn-north-4")) \
        .build()

    try:
        request = UpdateAlertConfigRequest()
        warnConfigbody = UpdateAlertConfigRequestBodyWarnConfig(
            anti_d_do_s=True,
            back_doors=False,
            bruce_force=False,
            high_privilege=False,
            remote_login=False,
            send_frequency=1,
            waf=False,
            weak_password=False
        )
        request.body = UpdateAlertConfigRequestBody(
            warn_config=warnConfigbody,
            topic_urn="urn:smn:cn-north-7:2d2d90a56a3243bdb909f6a24a27be8d:cnad-test-intl",
            display_name=""
        )
        response = client.update_alert_config(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)
support.huaweicloud.com/api-aad/UpdateAlertConfig.html