批量更新Prometheus监控告警规则 - BatchUpdateAlarmRule
功能介绍
该接口用于批量启停Prometheus监控告警规则、批量修改Prometheus监控告警规则的告警行动规则。
调用方法
请参见如何调用API。
授权信息
账号具备所有API的调用权限,如果使用账号下的IAM用户调用当前API,该IAM用户需具备调用API所需的权限。
- 如果使用角色与策略授权,具体权限要求请参见权限和授权项。
- 如果使用身份策略授权,需具备如下身份策略权限。
授权项
访问级别
资源类型(*为必须)
条件键
别名
依赖的授权项
aom:alarmRule:create
Write
alarmRule *
g:ResourceTag/<tag-key>
-
-
-
-
g:TagKeys
-
g:RequestTag/<tag-key>
-
URI
PUT /v4/{project_id}/alarm-rules/batch-update
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
project_id |
是 |
String |
项目ID,可以从控制台获取,也可以从调用API处获取。获取方式请参见:获取项目ID。 |
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
action |
是 |
String |
批量操作action:
|
请求参数
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
X-Auth-Token |
是 |
String |
从IAM服务获取的用户Token。获取方式请参见:获取Token。 |
|
Content-Type |
是 |
String |
消息体的类型(格式)。指定类型为“application/json”。 |
|
Enterprise-Project-Id |
否 |
String |
企业项目id。获取方式请参见:获取企业项目ID 。
|
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
alarm_rules |
否 |
Array of BatchAlarmRulesBody objects |
批量启停的告警规则列表。批量启停告警规则时,该参数必填。 |
|
update_action_rules |
否 |
Array of BatchUpdateActionRules objects |
批量修改告警行动规则的告警规则列表。批量修改告警行动规则时,该参数必填。 |
|
update_type |
否 |
String |
更新类型:BATCH_UPDATE_ACTION_RULE。批量修改告警行动规则时,该参数必填。 |
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
alarm_rule_enable |
是 |
Boolean |
当前状态是否启用。 |
|
alarm_rule_id |
是 |
Long |
告警规则id。 |
|
alarm_rule_name |
是 |
String |
告警规则名称。 |
|
alarm_rule_type |
是 |
String |
告警规则类型。
|
|
enterprise_project_id |
是 |
String |
企业项目id。获取方式请参见:获取企业项目ID 。 批量启停或批量修改单个企业项目下实例,填写企业项目id。 |
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
alarm_rule_id |
是 |
Long |
告警规则id。 |
|
alarm_rule_name |
是 |
String |
告警规则名称。 |
|
alarm_rule_type |
是 |
String |
告警规则类型。 |
|
bind_notification_rule_id |
否 |
String |
待绑定的告警行动规则名称。 |
|
frequency |
是 |
String |
通知频率
|
|
notification_enable |
否 |
Boolean |
是否启用告警通知规则。
如果告警触发“notify_triggered”或告警恢复“notify_resolved”都设置为false(即都不进行告警通知),则notification_enable需设置为false。 |
|
notification_type |
否 |
String |
通知类型。
|
|
notify_resolved |
是 |
Boolean |
告警解决是否通知。
|
|
notify_triggered |
是 |
Boolean |
告警触发是否通知。
|
|
route_group_enable |
否 |
Boolean |
启用告警分组规则。
如果告警触发“notify_triggered”或告警恢复“notify_resolved”都设置为false(即都不进行告警通知),则route_group_enable需设置为false。 |
|
route_group_rule |
否 |
String |
告警分组规则名称。
|
响应参数
状态码:200
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
error_code |
String |
错误码。 |
|
error_message |
String |
错误信息。 |
|
resources |
Array of BatchUpdateItemResult objects |
资源列表。 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
resource_alias |
String |
资源名称别名。 |
|
resource_name |
String |
资源名称。 |
|
ret_status |
String |
资源更新状态。 |
状态码:400
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
error_code |
String |
错误码。 最小长度:12 最大长度:12 |
|
error_msg |
String |
错误信息。 最小长度:0 最大长度:1024 |
|
error_type |
String |
错误类型。 最小长度:0 最大长度:128 |
|
trace_id |
String |
请求id。 最小长度:32 最大长度:32 |
请求示例
-
批量启动告警规则。
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代码示例如下。
-
批量启动告警规则。
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 68 69
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()); } } }
-
批量停止告警规则。
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 68 69
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()); } } }
-
批量将告警规则的告警通知方式更改为直接告警。
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 68 69 70 71 72 73 74 75 76 77 78
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()); } } }
-
批量将告警规则的告警通知方式更改为告警降噪。
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 68 69 70 71 72 73 74 75 76 77 78
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()); } } }
-
批量启动告警规则。
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
# 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)
-
批量停止告警规则。
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
# 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)
-
批量将告警规则的告警通知方式更改为直接告警。
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
# 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)
-
批量将告警规则的告警通知方式更改为告警降噪。
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
# 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)
-
批量启动告警规则。
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
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 := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := aom.NewAomClient( aom.AomClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) 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) } }
-
批量停止告警规则。
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
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 := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := aom.NewAomClient( aom.AomClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) 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) } }
-
批量将告警规则的告警通知方式更改为直接告警。
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 68 69 70 71 72
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 := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := aom.NewAomClient( aom.AomClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) 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: ¬ificationEnableUpdateActionRules, NotificationType: ¬ificationTypeUpdateActionRules, NotifyResolved: true, NotifyTriggered: true, }, { AlarmRuleId: int64(1366), AlarmRuleName: "0003", AlarmRuleType: "metric", BindNotificationRuleId: &bindNotificationRuleIdUpdateActionRules1, Frequency: "0", NotificationEnable: ¬ificationEnableUpdateActionRules1, NotificationType: ¬ificationTypeUpdateActionRules1, 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) } }
-
批量将告警规则的告警通知方式更改为告警降噪。
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 68 69 70 71 72
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 := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := aom.NewAomClient( aom.AomClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) 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: ¬ificationTypeUpdateActionRules, NotifyResolved: true, NotifyTriggered: true, RouteGroupEnable: &routeGroupEnableUpdateActionRules, RouteGroupRule: &routeGroupRuleUpdateActionRules, }, { AlarmRuleId: int64(1366), AlarmRuleName: "0003", AlarmRuleType: "metric", Frequency: "0", NotificationType: ¬ificationTypeUpdateActionRules1, 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的代码示例页签,可生成自动对应的SDK代码示例。
状态码
|
状态码 |
描述 |
|---|---|
|
200 |
OK 请求响应成功。当批量启停告警规则时,返回为null。当批量修改告警规则时,返回以下内容: |
|
400 |
BadRequest 非法请求。建议直接修改该请求,不要重试该请求。 |
错误码
请参见错误码。