
# 新增告警抑制规则 - AddInhibitRule
#### 功能介绍
该接口用于新增告警抑制规则。
#### 调用方法
请参见[如何调用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:inhibitRule:create | Write | -           | -   | -  | -      |
     
  
 
#### URI
POST /v2/{project_id}/alert/inhibit-rules
表1路径参数 
| 参数         | 是否必选 | 参数类型   | 描述                                                                                                     |
|:---|:---|:---|:---|
| project_id | 是    | String | 项目ID，可以从控制台获取，也可以从调用API处获取。获取方式请参见：[获取项目ID](https://support.huaweicloud.com/api-aom/aom_04_0024.html)。 |
   
#### 请求参数
表2请求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。   - 不填，新增默认企业项目下告警抑制规则。    |
   
表3请求Body参数 
| 参数                 | 是否必选 | 参数类型                                                                          | 描述                                                                                                                  |
|:---|:---|:---|:---|
| name               | 是    | String                                                                        | 告警抑制规则的名称。 只能由大小写字母、数字、下划线组成，且不能以下划线开头和结尾，最多不能超过100个字符。                           |
| desc               | 否    | String                                                                        | 告警抑制规则描述。规则描述长度最大 1024。                                                                                             |
| match_v3           | 否    | [InhibitMatchV3Tag] object        | 告警抑制规则编排详情。（如果创建新版告警抑制规则（支持编排能力），该参数必填。否则，该参数为空。）                                                                   |
| binding_group_rule | 否    | String                                                                        | 告警抑制规则绑定的告警分组规则名称。（如果创建新版告警抑制规则（支持编排能力），该参数可填可不填。否则，该参数为空。）                                                         |
| source_match       | 否    | Array\<Array\<[InhibitMatchTag]\>\> | 根源告警。（如果创建新版告警抑制规则（支持编排能力），该参数必填。否则，该参数为空。） 根源告警最多可设置10个并行条件，每个并行条件下最多可设置10个串行条件。 |
| target_match       | 否    | Array\<Array\<[InhibitMatchTag]\>\> | 抑制告警。（如果创建新版告警抑制规则（支持编排能力），该参数必填。否则，该参数为空。） 抑制告警最多可设置10个并行条件，每个并行条件下最多可设置10个串行条件。 |
   
 表4InhibitMatchV3Tag 
| 参数    | 是否必选 | 参数类型                                                                         | 描述      |
|:---|:---|:---|:---|
| nodes | 是    | Array of [InhibitRuleNode] objects | 节点详情列表。 |
| edges | 是    | Array of [Edge] objects                       | 边详情列表。  |
   
 表5InhibitRuleNode 
| 参数           | 是否必选 | 参数类型                                                                               | 描述                                                                                                                                                                                                                                                                                                                                                                                                                  |
|:---|:---|:---|:---|
| id           | 是    | String                                                                             | 节点id。命名规范为：flow-"8位随机字符串"。 随机字符串只能由字母、数字、下划线和中划线组成。 例如：flow-M3pfK020                                                                                                                                                                                                                                                                            |
| type         | 是    | String                                                                             | 节点类型。 Start：开始节点。 End：结束节点。 Card：卡片节点。                                                                                                                                                                                                                                                                        |
| businessType | 否    | String                                                                             | 卡片类型。（当type为Card时，该参数必填） - InhibitSourceCondition：根源告警卡片。   - InhibitTargetCondition：抑制告警卡片。    |
| value        | 否    | [InhibitConditionSubNode] object | 告警抑制规则节点详情。（当type为Card时，该参数必填）                                                                                                                                                                                                                                                                                                                                                                                      |
   
 表6InhibitConditionSubNode 
| 参数    | 是否必选 | 参数类型                                                                                         | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
|:---|:---|:---|:---|
| nodes | 否    | Array of [InhibitConditionSubNode] objects | 子节点列表。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| id    | 是    | String                                                                                       | 节点id。命名规范为：{businessType}-"8位随机字符串"。 随机字符串只能由字母、数字、下划线和中划线组成 例如：InhibitSourceCondition-M3pfK020                                                                                                                                                                                                                                                                                                                            |
| type  | 是    | String                                                                                       | 节点类型： - bool：布尔。   - text：文本。   - numerical：数字。    |
| value | 否    | String                                                                                       | 节点之间关系： - and：且。   - or：或。                                                                                                                                                 |
| match | 否    | [InhibitMatchTag] object                           | 匹配条件列表。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
   
 表7InhibitMatchTag 
| 参数      | 是否必选 | 参数类型             | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
|:---|:---|:---|:---|
| key     | 是    | String           | 告警抑制规则下根源告警或抑制告警key取值范围： - 具体标签名称：标签只能包含中文、字母、数字和下划线   - event_severity：告警级别   - resource_provider：告警源   - resource_type：资源类型                                                                                                                                                                                       |
| value   | 是    | Array of strings | 告警抑制规则下根源告警或抑制告警value取值范围。当表达式为正则时，value的长度不能超过256 - 当key为告警级别且表达式为等于时，value取值范围为：Critical，Major，Minor，Info。   - 当key为资源类型，value取值范围为：创建告警规则或自定义上报告警时选定的资源类型。可以设置为：host、container、process等类型。   - 当key为告警源，value取值范围为：触发告警或事件的服务名称。可以设置为AOM 、LTS、CCE等服务名称。   - 当key为标签，value取值范围为：标签名对应的标签值，标签值只能包含中文、字母、数字和下划线。    |
| operate | 是    | String           | 操作符： - EQUALS ：等于   - REGEX ：正则   - EXIST ：存在                                                                                                                                                                                                                                                                                                                                                                                               |
   
 表8Edge 
| 参数     | 是否必选 | 参数类型   | 描述                                                                                                                                      |
|:---|:---|:---|:---|
| id     | 是    | String | 边id。命名规范为：edge-"8位随机字符串"。 随机字符串只能由字母、数字、下划线和中划线组成。 例如：edge-M3pfK202 |
| source | 是    | String | 边起始节点id。取值于nodes列表里的id。                                                                                                                 |
| target | 是    | String | 边终止节点id。取值于nodes列表里的id。                                                                                                                 |
| value  | 否    | String | 边value。节点之间的关系true或false。                                                                                                               |
   
#### 响应参数
**状态码：204**
No Content 表示请求成功，但没有内容返回。
**状态码：400**
表9响应Body参数 
| 参数         | 参数类型   | 描述                                                                                                                                      |
|:---|:---|:---|
| error_code | String | **参数解释：** 非法请求错误码。 **取值范围：** 不涉及。 |
| error_msg  | String | **参数解释：** 错误信息。 **取值范围：** 不涉及。    |
| error_type | String | **参数解释：** 错误类型。 **取值范围：** 不涉及。    |
| trace_id   | String | **参数解释：** 请求id。 **取值范围：** 不涉及。    |
   
**状态码：403**
表10响应Body参数 
| 参数         | 参数类型   | 描述                                                                                                                                      |
|:---|:---|:---|
| error_code | String | **参数解释：** 非法请求错误码。 **取值范围：** 不涉及。 |
| error_msg  | String | **参数解释：** 错误信息。 **取值范围：** 不涉及。    |
| error_type | String | **参数解释：** 错误类型。 **取值范围：** 不涉及。    |
| trace_id   | String | **参数解释：** 请求id。 **取值范围：** 不涉及。    |
   
#### 请求示例
- 新增新版告警抑制规则
  ```
  https://{Endpoint}/v2/{project_id}/alert/inhibit-rules
  {
    "desc" : "·123",
    "match_v3" : {
      "edges" : [ {
        "id" : "edge-M3pfK202",
        "source" : "flow-VHSvKyYY",
        "target" : "flow-ufs5Zsn3"
      }, {
        "id" : "edge-OrwQoSVg",
        "source" : "flow-ufs5Zsn3",
        "target" : "flow-eAheOiH5",
        "value" : "true"
      }, {
        "id" : "edge-ukREdGnr",
        "source" : "flow-ufs5Zsn3",
        "target" : "flow-f6P36v4a",
        "value" : "false"
      } ],
      "nodes" : [ {
        "id" : "flow-VHSvKyYY",
        "type" : "Start"
      }, {
        "businessType" : "InhibitSourceCondition",
        "id" : "flow-ufs5Zsn3",
        "type" : "Card",
        "value" : {
          "id" : "InhibitSourceCondition-wtJBNJD7",
          "nodes" : [ {
            "id" : "InhibitSourceCondition-awPpHgHv",
            "match" : {
              "key" : "resource_type",
              "operate" : "EQUALS",
              "value" : [ "service" ]
            },
            "type" : "text"
          }, {
            "id" : "InhibitSourceCondition-DmfXe2vN",
            "match" : {
              "key" : "resource_type",
              "operate" : "EQUALS",
              "value" : [ "service" ]
            },
            "type" : "text"
          }, {
            "id" : "InhibitSourceCondition-0fnYAVWg",
            "nodes" : [ {
              "id" : "InhibitSourceCondition-Xn7CUof5",
              "match" : {
                "key" : "event_severity",
                "operate" : "EQUALS",
                "value" : [ "Critical" ]
              },
              "type" : "text"
            } ],
            "type" : "bool",
            "value" : "and"
          }, {
            "id" : "InhibitSourceCondition-juUOsA2L",
            "match" : {
              "key" : "resource_provider",
              "operate" : "EQUALS",
              "value" : [ "AOM" ]
            },
            "type" : "text"
          }, {
            "id" : "InhibitSourceCondition-JvtIwdL6",
            "match" : {
              "key" : "1",
              "operate" : "EQUALS",
              "value" : [ "1" ]
            },
            "type" : "text"
          } ],
          "type" : "bool",
          "value" : "and"
        }
      }, {
        "businessType" : "InhibitTargetCondition",
        "id" : "flow-eAheOiH5",
        "type" : "Card",
        "value" : {
          "id" : "InhibitSourceCondition--foPmJou",
          "nodes" : [ {
            "id" : "InhibitSourceCondition--m9jJEAN",
            "match" : {
              "key" : "resource_type",
              "operate" : "EQUALS",
              "value" : [ "service" ]
            },
            "type" : "text"
          }, {
            "id" : "InhibitSourceCondition-MmTv1BZ5",
            "match" : {
              "key" : "resource_provider",
              "operate" : "EQUALS",
              "value" : [ "AOM" ]
            },
            "type" : "text"
          }, {
            "id" : "InhibitSourceCondition-7oz9ddLB",
            "nodes" : [ {
              "id" : "InhibitSourceCondition-oM73YTRG",
              "match" : {
                "key" : "2",
                "operate" : "EQUALS",
                "value" : [ "2" ]
              },
              "type" : "text"
            } ],
            "type" : "bool",
            "value" : "and"
          } ],
          "type" : "bool",
          "value" : "and"
        }
      }, {
        "id" : "flow-f6P36v4a",
        "type" : "End"
      } ]
    },
    "name" : "123"
  }
  ```
  
- 新增告警抑制规则
  ```
  https://{Endpoint}/v2/{project_id}/alert/inhibit-rules
  {
    "desc" : "",
    "name" : "test",
    "source_match" : [ [ {
      "key" : "event_severity",
      "operate" : "EQUALS",
      "value" : [ "Critical" ]
    } ] ],
    "target_match" : [ [ {
      "key" : "event_severity",
      "operate" : "EQUALS",
      "value" : [ "Info" ]
    } ] ]
  }
  ```
  
 
#### 响应示例
**状态码：400**
BadRequest 非法请求。建议直接修改该请求，不要重试该请求。
```
{
  "error_code" : "AOM.08006001",
  "error_msg" : "the inhibitName is exist",
  "error_type" : "PARAM_INVALID",
  "trace_id" : ""
}
```
**状态码：403**
Forbidden 请求被拒绝访问。返回该状态码，表明请求能够到达服务端，且服务端能够理解用户请求，但是拒绝做更多的事情，因为该请求被设置为拒绝访问，建议直接修改该请求，不要重试该请求。
```
{
  "error_code" : "AOM.0403",
  "error_msg" : "auth failed.",
  "error_type" : "AUTH_FAILED",
  "trace_id" : ""
}
```
#### 状态码
| 状态码 | 描述                                                                                            |
|:---|:---|
| 204 | No Content 表示请求成功，但没有内容返回。                                                                    |
| 400 | BadRequest 非法请求。建议直接修改该请求，不要重试该请求。                                                            |
| 403 | Forbidden 请求被拒绝访问。返回该状态码，表明请求能够到达服务端，且服务端能够理解用户请求，但是拒绝做更多的事情，因为该请求被设置为拒绝访问，建议直接修改该请求，不要重试该请求。 |
   
#### 错误码
请参见[错误码](https://support.huaweicloud.com/api-aom/ErrorCode.html)。
