
# 批量更新Prometheus监控告警规则 - BatchUpdateAlarmRule
#### 功能介绍
该接口用于批量启停Prometheus监控告警规则、批量修改Prometheus监控告警规则的告警行动规则。
#### 调用方法
请参见[如何调用API](https://support.huaweicloud.com/api-aom/aom_04_0057.html)。
#### 授权信息
账号具备所有API的调用权限，如果使用账号下的IAM用户调用当前API，该IAM用户需具备调用API所需的权限。
- 如果使用角色与策略授权，具体权限要求请参见[权限和授权项](https://support.huaweicloud.com/api-aom/aom_04_0031.html)。
- 如果使用身份策略授权，需具备如下身份策略权限。
  
  | 授权项                  | 访问级别  | 资源类型（\*为必须）  | 条件键                                                                                                                                                                                                                                                                                                                                                                   | 别名 | 依赖的授权项 |
  |:---|:---|:---|:---|:---|:---|
  | aom:alarmRule:create | Write | alarmRule \* | g:ResourceTag/\<tag-key\>                                                                                                                                                                                                                                                                                                                                             | -  | -      |
  | aom:alarmRule:create | Write | -            | - g:TagKeys   - g:RequestTag/\<tag-key\>    | -  | -      |
     
  
 
#### URI
PUT /v4/{project_id}/alarm-rules/batch-update
表1路径参数 
| 参数         | 是否必选 | 参数类型   | 描述                                                                                                     |
|:---|:---|:---|:---|
| project_id | 是    | String | 项目ID，可以从控制台获取，也可以从调用API处获取。获取方式请参见：[获取项目ID](https://support.huaweicloud.com/api-aom/aom_04_0024.html)。 |
   
表2Query参数 
| 参数     | 是否必选 | 参数类型   | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
|:---|:---|:---|:---|
| action | 是    | String | 批量操作action： - enable：批量启动Prometheus监控告警规则   - disable：批量停止Prometheus监控告警规则   - BATCH_UPDATE_ACTION_RULE：批量修改Prometheus监控告警规则的告警行动规则    |
   
#### 请求参数
表3请求Header参数 
| 参数                    | 是否必选 | 参数类型   | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
|:---|:---|:---|:---|
| X-Auth-Token          | 是    | String | 从IAM服务获取的用户Token。获取方式请参见：[获取Token](https://support.huaweicloud.com/api-aom/aom_04_0059.html)。                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| Content-Type          | 是    | String | 消息体的类型（格式）。指定类型为"application/json"。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| Enterprise-Project-Id | 否    | String | 企业项目id。获取方式请参见：[获取企业项目ID](https://support.huaweicloud.com/api-aom/aom_04_0024.html) 。 - 批量启停或批量修改单个企业项目下实例，填写企业项目id。   - 不填 则批量启停或批量修改默认企业项目下实例，默认企业项目id为0。    |
   
表4请求Body参数 
| 参数                  | 是否必选 | 参数类型                                                                                             | 描述                                               |
|:---|:---|:---|:---|
| alarm_rules         | 否    | Array of [BatchAlarmRulesBody] objects       | 批量启停的告警规则列表。批量启停告警规则时，该参数必填。                     |
| update_action_rules | 否    | Array of [BatchUpdateActionRules] objects | 批量修改告警行动规则的告警规则列表。批量修改告警行动规则时，该参数必填。             |
| update_type         | 否    | String                                                                                           | 更新类型：BATCH_UPDATE_ACTION_RULE。批量修改告警行动规则时，该参数必填。 |
   
 表5BatchAlarmRulesBody 
| 参数                    | 是否必选 | 参数类型    | 描述                                                                                                                                                                                                                                                                                                                                                                                                                 |
|:---|:---|:---|:---|
| alarm_rule_enable     | 是    | Boolean | 当前状态是否启用。                                                                                                                                                                                                                                                                                                                                                                                                          |
| alarm_rule_id         | 是    | Long    | 告警规则id。                                                                                                                                                                                                                                                                                                                                                                                                            |
| alarm_rule_name       | 是    | String  | 告警规则名称。                                                                                                                                                                                                                                                                                                                                                                                                            |
| alarm_rule_type       | 是    | String  | 告警规则类型。 - metric：Prometheus指标   - event： 事件    |
| enterprise_project_id | 是    | String  | 企业项目id。获取方式请参见：[获取企业项目ID](https://support.huaweicloud.com/api-aom/aom_04_0024.html) 。 批量启停或批量修改单个企业项目下实例，填写企业项目id。                                                                                                                                                                                                                                                         |
   
 表6BatchUpdateActionRules 
| 参数                        | 是否必选 | 参数类型    | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
|:---|:---|:---|:---|
| alarm_rule_id             | 是    | Long    | 告警规则id。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| alarm_rule_name           | 是    | String  | 告警规则名称。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| alarm_rule_type           | 是    | String  | 告警规则类型。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| bind_notification_rule_id | 否    | String  | 待绑定的告警行动规则名称。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| frequency                 | 是    | String  | 通知频率 - 当通知类型为"alarm_policy"时，填"-1"   - 当通知类型为"direct"时， - "0"：只告警一次   - "300"：每5分钟   - "600"：每10分钟   - "900"：每15分钟   - "1800"：每30分钟   - "3600"：每1小时   - "10800"：每3小时   - "21600"：每6小时   - "43200"：每12小时   - "86400"：每天      |
| notification_enable       | 否    | Boolean | 是否启用告警通知规则。 - 当通知类型为"direct"时，填true   - 当通知类型为"alarm_policy"时，填false    如果告警触发"notify_triggered"或告警恢复"notify_resolved"都设置为false（即都不进行告警通知），则notification_enable需设置为false。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| notification_type         | 否    | String  | 通知类型。 - "direct"：直接告警   - "alarm_policy"：告警降噪                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| notify_resolved           | 是    | Boolean | 告警解决是否通知。 - true：通知   - false：不通知                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| notify_triggered          | 是    | Boolean | 告警触发是否通知。 - true：通知   - false：不通知                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| route_group_enable        | 否    | Boolean | 启用告警分组规则。 - 当通知类型为"alarm_policy"时：true   - 当通知类型为"direct"时：false    如果告警触发"notify_triggered"或告警恢复"notify_resolved"都设置为false（即都不进行告警通知），则route_group_enable需设置为false。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| route_group_rule          | 否    | String  | 告警分组规则名称。 - 当route_group_enable 为true时，填告警分组规则名称   - 当route_group_enable 为false时，填""                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
   
#### 响应参数
**状态码：200**
表7响应Body参数 
| 参数            | 参数类型                                                                                            | 描述    |
|:---|:---|:---|
| error_code    | String                                                                                          | 错误码。  |
| error_message | String                                                                                          | 错误信息。 |
| resources     | Array of [BatchUpdateItemResult] objects | 资源列表。 |
   
 表8BatchUpdateItemResult 
| 参数             | 参数类型   | 描述      |
|:---|:---|:---|
| resource_alias | String | 资源名称别名。 |
| resource_name  | String | 资源名称。   |
| ret_status     | String | 资源更新状态。 |
   
**状态码：400**
表9响应Body参数 
| 参数         | 参数类型   | 描述                                                                                                                                                        |
|:---|:---|:---|
| error_code | String | **参数解释：** 非法请求错误码。 **取值范围：** 不涉及。 |
| error_msg  | String | **参数解释：** 错误信息。 **取值范围：** 不涉及。    |
| error_type | String | **参数解释：** 错误类型。 **取值范围：** 不涉及。    |
| trace_id   | String | **参数解释：** 请求id。 **取值范围：** 不涉及。    |
   
#### 请求示例
- 批量启动告警规则。
  ```
  https://{Endpoint}/v4/{project_id}/alarm-rules/batch-update?action=enable
  {
    "alarm_rules" : [ {
      "alarm_rule_enable" : false,
      "alarm_rule_id" : 1366,
      "alarm_rule_name" : "0002",
      "enterprise_project_id" : "0",
      "alarm_rule_type" : "metric"
    }, {
      "alarm_rule_enable" : false,
      "alarm_rule_id" : 1366,
      "alarm_rule_name" : "0003",
      "enterprise_project_id" : "0",
      "alarm_rule_type" : "metric"
    } ]
  }
  ```
  
- 批量停止告警规则。
  ```
  https://{Endpoint}/v4/{project_id}/alarm-rules/batch-update?action=disable
  {
    "alarm_rules" : [ {
      "alarm_rule_enable" : true,
      "alarm_rule_id" : 1366,
      "alarm_rule_name" : "0002",
      "enterprise_project_id" : "0",
      "alarm_rule_type" : "metric"
    }, {
      "alarm_rule_enable" : true,
      "alarm_rule_id" : 1366,
      "alarm_rule_name" : "0003",
      "enterprise_project_id" : "0",
      "alarm_rule_type" : "metric"
    } ]
  }
  ```
  
- 批量将告警规则的告警通知方式更改为直接告警。
  ```
  https://{Endpoint}/v4/{project_id}/alarm-rules/batch-update?action=BATCH_UPDATE_ACTION_RULE
  {
    "update_action_rules" : [ {
      "alarm_rule_id" : 1366,
      "alarm_rule_name" : "0002",
      "alarm_rule_type" : "metric",
      "bind_notification_rule_id" : "111111111111111111111111111111111111111111111111111111111111111111",
      "frequency" : "0",
      "notification_enable" : true,
      "notification_type" : "direct",
      "notify_resolved" : true,
      "notify_triggered" : true
    }, {
      "alarm_rule_id" : 1366,
      "alarm_rule_name" : "0003",
      "alarm_rule_type" : "metric",
      "bind_notification_rule_id" : "111111111111111111111111111111111111111111111111111111111111111111",
      "frequency" : "0",
      "notification_enable" : true,
      "notification_type" : "direct",
      "notify_resolved" : true,
      "notify_triggered" : true
    } ],
    "update_type" : "BATCH_UPDATE_ACTION_RULE"
  }
  ```
  
- 批量将告警规则的告警通知方式更改为告警降噪。
  ```
  https://{Endpoint}/v4/{project_id}/alarm-rules/batch-update?action=BATCH_UPDATE_ACTION_RULE
  {
    "update_action_rules" : [ {
      "alarm_rule_id" : 1366,
      "alarm_rule_name" : "0002",
      "alarm_rule_type" : "metric",
      "frequency" : "0",
      "notification_type" : "alarm_policy",
      "notify_resolved" : true,
      "notify_triggered" : true,
      "route_group_enable" : true,
      "route_group_rule" : "aom1"
    }, {
      "alarm_rule_id" : 1366,
      "alarm_rule_name" : "0003",
      "alarm_rule_type" : "metric",
      "frequency" : "0",
      "notification_type" : "alarm_policy",
      "notify_resolved" : true,
      "notify_triggered" : true,
      "route_group_enable" : true,
      "route_group_rule" : "aom1"
    } ],
    "update_type" : "BATCH_UPDATE_ACTION_RULE"
  }
  ```
  
 
#### 响应示例
**状态码：200**
OK 请求响应成功。当批量启停告警规则时，返回为null。当批量修改告警规则时，返回以下内容：
```
{
  "error_code" : "200",
  "error_message" : "success",
  "resources" : [ {
    "resource_alias" : "0002",
    "resource_name" : "0002",
    "ret_status" : "Success"
  }, {
    "resource_alias" : "0003",
    "resource_name" : "0003",
    "ret_status" : "Success"
  } ]
}
```
**状态码：400**
BadRequest 非法请求。建议直接修改该请求，不要重试该请求。
```
{
  "error_code" : "AOM.02025026",
  "error_msg" : "Input alarmParams  is invalid: rule name or type is empty",
  "error_type" : "BAD_REQUEST",
  "trace_id" : "ff96d66927d839a49fb93d7ccaab3dae"
}
```
#### SDK代码示例
SDK代码示例如下。
- [Java]
  - 批量启动告警规则。
    ```
    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.aom.v2.region.AomRegion;
    import com.huaweicloud.sdk.aom.v2.*;
    import com.huaweicloud.sdk.aom.v2.model.*;
    import java.util.List;
    import java.util.ArrayList;
    public class BatchUpdateAlarmRuleSolution {
        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);
            AomClient client = AomClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(AomRegion.valueOf("<YOUR REGION>"))
                    .build();
            BatchUpdateAlarmRuleRequest request = new BatchUpdateAlarmRuleRequest();
            BatchUpdateRequest body = new BatchUpdateRequest();
            List<BatchAlarmRulesBody> listbodyAlarmRules = new ArrayList<>();
            listbodyAlarmRules.add(
                new BatchAlarmRulesBody()
                    .withAlarmRuleEnable(false)
                    .withAlarmRuleId(1366L)
                    .withAlarmRuleName("0002")
                    .withAlarmRuleType("metric")
                    .withEnterpriseProjectId("0")
            );
            listbodyAlarmRules.add(
                new BatchAlarmRulesBody()
                    .withAlarmRuleEnable(false)
                    .withAlarmRuleId(1366L)
                    .withAlarmRuleName("0003")
                    .withAlarmRuleType("metric")
                    .withEnterpriseProjectId("0")
            );
            body.withAlarmRules(listbodyAlarmRules);
            request.withBody(body);
            try {
                BatchUpdateAlarmRuleResponse response = client.batchUpdateAlarmRule(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());
            }
        }
    }
    ```
    
  
  - 批量停止告警规则。
    ```
    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.aom.v2.region.AomRegion;
    import com.huaweicloud.sdk.aom.v2.*;
    import com.huaweicloud.sdk.aom.v2.model.*;
    import java.util.List;
    import java.util.ArrayList;
    public class BatchUpdateAlarmRuleSolution {
        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);
            AomClient client = AomClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(AomRegion.valueOf("<YOUR REGION>"))
                    .build();
            BatchUpdateAlarmRuleRequest request = new BatchUpdateAlarmRuleRequest();
            BatchUpdateRequest body = new BatchUpdateRequest();
            List<BatchAlarmRulesBody> listbodyAlarmRules = new ArrayList<>();
            listbodyAlarmRules.add(
                new BatchAlarmRulesBody()
                    .withAlarmRuleEnable(true)
                    .withAlarmRuleId(1366L)
                    .withAlarmRuleName("0002")
                    .withAlarmRuleType("metric")
                    .withEnterpriseProjectId("0")
            );
            listbodyAlarmRules.add(
                new BatchAlarmRulesBody()
                    .withAlarmRuleEnable(true)
                    .withAlarmRuleId(1366L)
                    .withAlarmRuleName("0003")
                    .withAlarmRuleType("metric")
                    .withEnterpriseProjectId("0")
            );
            body.withAlarmRules(listbodyAlarmRules);
            request.withBody(body);
            try {
                BatchUpdateAlarmRuleResponse response = client.batchUpdateAlarmRule(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());
            }
        }
    }
    ```
    
  
  - 批量将告警规则的告警通知方式更改为直接告警。
    ```
    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.aom.v2.region.AomRegion;
    import com.huaweicloud.sdk.aom.v2.*;
    import com.huaweicloud.sdk.aom.v2.model.*;
    import java.util.List;
    import java.util.ArrayList;
    public class BatchUpdateAlarmRuleSolution {
        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);
            AomClient client = AomClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(AomRegion.valueOf("<YOUR REGION>"))
                    .build();
            BatchUpdateAlarmRuleRequest request = new BatchUpdateAlarmRuleRequest();
            BatchUpdateRequest body = new BatchUpdateRequest();
            List<BatchUpdateActionRules> listbodyUpdateActionRules = new ArrayList<>();
            listbodyUpdateActionRules.add(
                new BatchUpdateActionRules()
                    .withAlarmRuleId(1366L)
                    .withAlarmRuleName("0002")
                    .withAlarmRuleType("metric")
                    .withBindNotificationRuleId("111111111111111111111111111111111111111111111111111111111111111111")
                    .withFrequency("0")
                    .withNotificationEnable(true)
                    .withNotificationType("direct")
                    .withNotifyResolved(true)
                    .withNotifyTriggered(true)
            );
            listbodyUpdateActionRules.add(
                new BatchUpdateActionRules()
                    .withAlarmRuleId(1366L)
                    .withAlarmRuleName("0003")
                    .withAlarmRuleType("metric")
                    .withBindNotificationRuleId("111111111111111111111111111111111111111111111111111111111111111111")
                    .withFrequency("0")
                    .withNotificationEnable(true)
                    .withNotificationType("direct")
                    .withNotifyResolved(true)
                    .withNotifyTriggered(true)
            );
            body.withUpdateType("BATCH_UPDATE_ACTION_RULE");
            body.withUpdateActionRules(listbodyUpdateActionRules);
            request.withBody(body);
            try {
                BatchUpdateAlarmRuleResponse response = client.batchUpdateAlarmRule(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());
            }
        }
    }
    ```
    
  
  - 批量将告警规则的告警通知方式更改为告警降噪。
    ```
    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.aom.v2.region.AomRegion;
    import com.huaweicloud.sdk.aom.v2.*;
    import com.huaweicloud.sdk.aom.v2.model.*;
    import java.util.List;
    import java.util.ArrayList;
    public class BatchUpdateAlarmRuleSolution {
        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);
            AomClient client = AomClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(AomRegion.valueOf("<YOUR REGION>"))
                    .build();
            BatchUpdateAlarmRuleRequest request = new BatchUpdateAlarmRuleRequest();
            BatchUpdateRequest body = new BatchUpdateRequest();
            List<BatchUpdateActionRules> listbodyUpdateActionRules = new ArrayList<>();
            listbodyUpdateActionRules.add(
                new BatchUpdateActionRules()
                    .withAlarmRuleId(1366L)
                    .withAlarmRuleName("0002")
                    .withAlarmRuleType("metric")
                    .withFrequency("0")
                    .withNotificationType("alarm_policy")
                    .withNotifyResolved(true)
                    .withNotifyTriggered(true)
                    .withRouteGroupEnable(true)
                    .withRouteGroupRule("aom1")
            );
            listbodyUpdateActionRules.add(
                new BatchUpdateActionRules()
                    .withAlarmRuleId(1366L)
                    .withAlarmRuleName("0003")
                    .withAlarmRuleType("metric")
                    .withFrequency("0")
                    .withNotificationType("alarm_policy")
                    .withNotifyResolved(true)
                    .withNotifyTriggered(true)
                    .withRouteGroupEnable(true)
                    .withRouteGroupRule("aom1")
            );
            body.withUpdateType("BATCH_UPDATE_ACTION_RULE");
            body.withUpdateActionRules(listbodyUpdateActionRules);
            request.withBody(body);
            try {
                BatchUpdateAlarmRuleResponse response = client.batchUpdateAlarmRule(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());
            }
        }
    }
    ```
    
   
- [Python]
  - 批量启动告警规则。
    ```
    # coding: utf-8
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkaom.v2.region.aom_region import AomRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkaom.v2 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 = AomClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(AomRegion.value_of("<YOUR REGION>")) \
            .build()
        try:
            request = BatchUpdateAlarmRuleRequest()
            listAlarmRulesbody = [
                BatchAlarmRulesBody(
                    alarm_rule_enable=False,
                    alarm_rule_id=1366,
                    alarm_rule_name="0002",
                    alarm_rule_type="metric",
                    enterprise_project_id="0"
                ),
                BatchAlarmRulesBody(
                    alarm_rule_enable=False,
                    alarm_rule_id=1366,
                    alarm_rule_name="0003",
                    alarm_rule_type="metric",
                    enterprise_project_id="0"
                )
            ]
            request.body = BatchUpdateRequest(
                alarm_rules=listAlarmRulesbody
            )
            response = client.batch_update_alarm_rule(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    ```
    
  
  - 批量停止告警规则。
    ```
    # coding: utf-8
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkaom.v2.region.aom_region import AomRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkaom.v2 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 = AomClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(AomRegion.value_of("<YOUR REGION>")) \
            .build()
        try:
            request = BatchUpdateAlarmRuleRequest()
            listAlarmRulesbody = [
                BatchAlarmRulesBody(
                    alarm_rule_enable=True,
                    alarm_rule_id=1366,
                    alarm_rule_name="0002",
                    alarm_rule_type="metric",
                    enterprise_project_id="0"
                ),
                BatchAlarmRulesBody(
                    alarm_rule_enable=True,
                    alarm_rule_id=1366,
                    alarm_rule_name="0003",
                    alarm_rule_type="metric",
                    enterprise_project_id="0"
                )
            ]
            request.body = BatchUpdateRequest(
                alarm_rules=listAlarmRulesbody
            )
            response = client.batch_update_alarm_rule(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    ```
    
  
  - 批量将告警规则的告警通知方式更改为直接告警。
    ```
    # coding: utf-8
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkaom.v2.region.aom_region import AomRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkaom.v2 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 = AomClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(AomRegion.value_of("<YOUR REGION>")) \
            .build()
        try:
            request = BatchUpdateAlarmRuleRequest()
            listUpdateActionRulesbody = [
                BatchUpdateActionRules(
                    alarm_rule_id=1366,
                    alarm_rule_name="0002",
                    alarm_rule_type="metric",
                    bind_notification_rule_id="111111111111111111111111111111111111111111111111111111111111111111",
                    frequency="0",
                    notification_enable=True,
                    notification_type="direct",
                    notify_resolved=True,
                    notify_triggered=True
                ),
                BatchUpdateActionRules(
                    alarm_rule_id=1366,
                    alarm_rule_name="0003",
                    alarm_rule_type="metric",
                    bind_notification_rule_id="111111111111111111111111111111111111111111111111111111111111111111",
                    frequency="0",
                    notification_enable=True,
                    notification_type="direct",
                    notify_resolved=True,
                    notify_triggered=True
                )
            ]
            request.body = BatchUpdateRequest(
                update_type="BATCH_UPDATE_ACTION_RULE",
                update_action_rules=listUpdateActionRulesbody
            )
            response = client.batch_update_alarm_rule(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    ```
    
  
  - 批量将告警规则的告警通知方式更改为告警降噪。
    ```
    # coding: utf-8
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkaom.v2.region.aom_region import AomRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkaom.v2 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 = AomClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(AomRegion.value_of("<YOUR REGION>")) \
            .build()
        try:
            request = BatchUpdateAlarmRuleRequest()
            listUpdateActionRulesbody = [
                BatchUpdateActionRules(
                    alarm_rule_id=1366,
                    alarm_rule_name="0002",
                    alarm_rule_type="metric",
                    frequency="0",
                    notification_type="alarm_policy",
                    notify_resolved=True,
                    notify_triggered=True,
                    route_group_enable=True,
                    route_group_rule="aom1"
                ),
                BatchUpdateActionRules(
                    alarm_rule_id=1366,
                    alarm_rule_name="0003",
                    alarm_rule_type="metric",
                    frequency="0",
                    notification_type="alarm_policy",
                    notify_resolved=True,
                    notify_triggered=True,
                    route_group_enable=True,
                    route_group_rule="aom1"
                )
            ]
            request.body = BatchUpdateRequest(
                update_type="BATCH_UPDATE_ACTION_RULE",
                update_action_rules=listUpdateActionRulesbody
            )
            response = client.batch_update_alarm_rule(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    ```
    
   
- [Go]
  - 批量启动告警规则。
    ```
    package main
    import (
    "fmt"
    "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        aom "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v2"
    "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v2/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v2/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 := aom.AomClientBuilder().
             WithRegion(region.ValueOf("<YOUR REGION>")).
             WithCredential(auth).
             SafeBuild()
        if err != nil {
            fmt.Println(err)
            return
        }
        client := aom.NewAomClient(hcClient)
        request := &model.BatchUpdateAlarmRuleRequest{}
    var listAlarmRulesbody = []model.BatchAlarmRulesBody{
            {
                AlarmRuleEnable: false,
                AlarmRuleId: int64(1366),
                AlarmRuleName: "0002",
                AlarmRuleType: "metric",
                EnterpriseProjectId: "0",
            },
            {
                AlarmRuleEnable: false,
                AlarmRuleId: int64(1366),
                AlarmRuleName: "0003",
                AlarmRuleType: "metric",
                EnterpriseProjectId: "0",
            },
        }
    request.Body = &model.BatchUpdateRequest{
    AlarmRules: &listAlarmRulesbody,
    }
    response, err := client.BatchUpdateAlarmRule(request)
    if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    ```
    
  
  - 批量停止告警规则。
    ```
    package main
    import (
    "fmt"
    "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        aom "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v2"
    "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v2/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v2/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 := aom.AomClientBuilder().
             WithRegion(region.ValueOf("<YOUR REGION>")).
             WithCredential(auth).
             SafeBuild()
        if err != nil {
            fmt.Println(err)
            return
        }
        client := aom.NewAomClient(hcClient)
        request := &model.BatchUpdateAlarmRuleRequest{}
    var listAlarmRulesbody = []model.BatchAlarmRulesBody{
            {
                AlarmRuleEnable: true,
                AlarmRuleId: int64(1366),
                AlarmRuleName: "0002",
                AlarmRuleType: "metric",
                EnterpriseProjectId: "0",
            },
            {
                AlarmRuleEnable: true,
                AlarmRuleId: int64(1366),
                AlarmRuleName: "0003",
                AlarmRuleType: "metric",
                EnterpriseProjectId: "0",
            },
        }
    request.Body = &model.BatchUpdateRequest{
    AlarmRules: &listAlarmRulesbody,
    }
    response, err := client.BatchUpdateAlarmRule(request)
    if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    ```
    
  
  - 批量将告警规则的告警通知方式更改为直接告警。
    ```
    package main
    import (
    "fmt"
    "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        aom "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v2"
    "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v2/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v2/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 := aom.AomClientBuilder().
             WithRegion(region.ValueOf("<YOUR REGION>")).
             WithCredential(auth).
             SafeBuild()
        if err != nil {
            fmt.Println(err)
            return
        }
        client := aom.NewAomClient(hcClient)
        request := &model.BatchUpdateAlarmRuleRequest{}
    bindNotificationRuleIdUpdateActionRules:= "111111111111111111111111111111111111111111111111111111111111111111"
    notificationEnableUpdateActionRules:= true
    notificationTypeUpdateActionRules:= "direct"
    bindNotificationRuleIdUpdateActionRules1:= "111111111111111111111111111111111111111111111111111111111111111111"
    notificationEnableUpdateActionRules1:= true
    notificationTypeUpdateActionRules1:= "direct"
    var listUpdateActionRulesbody = []model.BatchUpdateActionRules{
            {
                AlarmRuleId: int64(1366),
                AlarmRuleName: "0002",
                AlarmRuleType: "metric",
                BindNotificationRuleId: &bindNotificationRuleIdUpdateActionRules,
                Frequency: "0",
                NotificationEnable: &notificationEnableUpdateActionRules,
                NotificationType: &notificationTypeUpdateActionRules,
                NotifyResolved: true,
                NotifyTriggered: true,
            },
            {
                AlarmRuleId: int64(1366),
                AlarmRuleName: "0003",
                AlarmRuleType: "metric",
                BindNotificationRuleId: &bindNotificationRuleIdUpdateActionRules1,
                Frequency: "0",
                NotificationEnable: &notificationEnableUpdateActionRules1,
                NotificationType: &notificationTypeUpdateActionRules1,
                NotifyResolved: true,
                NotifyTriggered: true,
            },
        }
    updateTypeBatchUpdateRequest:= "BATCH_UPDATE_ACTION_RULE"
    request.Body = &model.BatchUpdateRequest{
    UpdateType: &updateTypeBatchUpdateRequest,
    UpdateActionRules: &listUpdateActionRulesbody,
    }
    response, err := client.BatchUpdateAlarmRule(request)
    if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    ```
    
  
  - 批量将告警规则的告警通知方式更改为告警降噪。
    ```
    package main
    import (
    "fmt"
    "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        aom "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v2"
    "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v2/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v2/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 := aom.AomClientBuilder().
             WithRegion(region.ValueOf("<YOUR REGION>")).
             WithCredential(auth).
             SafeBuild()
        if err != nil {
            fmt.Println(err)
            return
        }
        client := aom.NewAomClient(hcClient)
        request := &model.BatchUpdateAlarmRuleRequest{}
    notificationTypeUpdateActionRules:= "alarm_policy"
    routeGroupEnableUpdateActionRules:= true
    routeGroupRuleUpdateActionRules:= "aom1"
    notificationTypeUpdateActionRules1:= "alarm_policy"
    routeGroupEnableUpdateActionRules1:= true
    routeGroupRuleUpdateActionRules1:= "aom1"
    var listUpdateActionRulesbody = []model.BatchUpdateActionRules{
            {
                AlarmRuleId: int64(1366),
                AlarmRuleName: "0002",
                AlarmRuleType: "metric",
                Frequency: "0",
                NotificationType: &notificationTypeUpdateActionRules,
                NotifyResolved: true,
                NotifyTriggered: true,
                RouteGroupEnable: &routeGroupEnableUpdateActionRules,
                RouteGroupRule: &routeGroupRuleUpdateActionRules,
            },
            {
                AlarmRuleId: int64(1366),
                AlarmRuleName: "0003",
                AlarmRuleType: "metric",
                Frequency: "0",
                NotificationType: &notificationTypeUpdateActionRules1,
                NotifyResolved: true,
                NotifyTriggered: true,
                RouteGroupEnable: &routeGroupEnableUpdateActionRules1,
                RouteGroupRule: &routeGroupRuleUpdateActionRules1,
            },
        }
    updateTypeBatchUpdateRequest:= "BATCH_UPDATE_ACTION_RULE"
    request.Body = &model.BatchUpdateRequest{
    UpdateType: &updateTypeBatchUpdateRequest,
    UpdateActionRules: &listUpdateActionRulesbody,
    }
    response, err := client.BatchUpdateAlarmRule(request)
    if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    ```
    
   
- [更多]
  更多编程语言的SDK代码示例，请参见[API Explorer](https://console.huaweicloud.com/apiexplorer/#/openapi/AOM/sdk?api=BatchUpdateAlarmRule)的代码示例页签，可生成自动对应的SDK代码示例。
#### 状态码
| 状态码 | 描述                                              |
|:---|:---|
| 200 | OK 请求响应成功。当批量启停告警规则时，返回为null。当批量修改告警规则时，返回以下内容： |
| 400 | BadRequest 非法请求。建议直接修改该请求，不要重试该请求。              |
   
#### 错误码
请参见[错误码](https://support.huaweicloud.com/api-aom/ErrorCode.html)。
