Create Alert Type


创建一条告警类型。

请求格式

POST https://{apigw-address}/event-service/v2.1/alert-types?action=create

请求参数(URI)

名称 位置(Path/Query) 必需/可选 数据类型 描述
orgId Query 必需 String 资产所属的组织ID。如何获取orgId信息>>

请求参数(Body)

名称 必需/可选 数据类型 描述
type 必需 GenerateType结构体 告警类型。见 generateType结构体

generateType结构体

名称 必需/可选 数据类型 描述
typeId 必需 String 告警类型编号
typeDesc 必需 StringI18n 国际化告警类型描述,其中default必填。结构请见 国际化名称结构体>>
tags 可选 Map 告警类型的标签。详见 标签的作用与表示方法>>
parentTypeId 可选 String 父告警类型编号。如果为 null ,则该告警类型本身就是父告警类型。

响应参数

名称 数据类型 描述
data String 告警类型ID。

示例

请求示例

url: https://{apigw-address}/event-service/v2.1/alert-types?action=create&orgId=yourOrgId
method: POST
requestBody:
{
 "type": {
  "typeId": "yourTypeId",
  "parentTypeId" : "parent",
  "typeDesc": {
   "defaultValue": "OverLimit",
   "i18nValue": {
    "en_US": "OverLimit",
    "zh_CN": "超限"
   }
  },
  "tags": {
   "year": "2000",
   "author": "cshan"
  }
 }
}

返回示例

{
  "code": 0,
  "msg": "OK",
  "requestId": "4873095e-621d-4cfd-bc2c-edb520f574ea",
  "data": "planetTemperature"
}

Java SDK调用示例

public void testCreateAlertType() {
    private static String accessKey = "yourAppAccessKey";
    private static String secretKey = "yourAppSecretKey";
    private static String orgId = "yourOrgId";
    private static String url = "https://{apigw-address}";
    CreateAlertTypeRequest request = new CreateAlertTypeRequest();
    request.setOrgId(orgId);
    GenerateType type = new GenerateType();
    type.setTypeId("yourAlertTypeId");
    type.setParentTypeId("yourParentTypeId");
    StringI18n desc = new StringI18n();
    desc.setDefaultValue("default");
    Map < String, String > map = new HashMap < > ();
    map.put("zh_CN", "中文");
    map.put("en_US", "english");
    desc.setI18nValue(map);
    type.setTypeDesc(desc);
    Map < String, String > tags = new HashMap < > ();
    tags.put("yourTagKey", "yourTagValue");
    type.setTags(tags);
    request.setType(type);
    try {
        CreateAlertTypeResponse response = Poseidon.config(PConfig.init().appKey(accessKey).appSecret(secretKey).debug())
            .url(url)
            .getResponse(request, CreateAlertTypeResponse.class);
        Gson gson = new Gson();
        System.out.println(gson.toJson(response));
    } catch (Exception e) {
        e.printStackTrace();
    }
}