Create Active Alerts in Batch¶
批量创建当前告警。
备注
一旦有一条告警的格式校验不通过,所有告警均无法创建成功。
请求格式¶
POST https://{apigw-address}/event-service/v2.1/active-alerts?action=batchCreate
请求参数(URI)¶
名称 |
位置(Path/Query) |
必需/可选 |
数据类型 |
描述 |
---|---|---|---|---|
orgId |
Query |
必需 |
String |
资产所属的组织 ID。如何获取 orgId 信息>> |
请求参数(Body)¶
名称 |
必需/可选 |
数据类型 |
描述 |
---|---|---|---|
activeAlert |
必需 |
ActiveAlert 结构体数组 |
有关 activeAlert 结构体的定义。见 ActiveAlert 结构体>> |
响应参数¶
名称 |
数据类型 |
描述 |
---|---|---|
data |
EnosBatchEachData结构体数组 |
创建成功或失败信息。EnosBatchEachData结构体的详细信息,见下表。 |
successSize |
Integer |
成功创建的当前告警数。 |
totalSize |
Integer |
需要创建的当前告警总数。 |
EnosBatchEachData结构体¶
名称 |
数据类型 |
描述 |
---|---|---|
code |
Integer |
单条记录创建成功或失败,0:成功,-1:失败。 |
msg |
String |
提示格式正确还是错误。 |
data |
String |
若创建成功,则为 |
示例¶
请求示例¶
url: https://{apigw-address}/event-service/v2.1/active-alerts?action=batchCreate&orgId=yourOrgId
method: POST
requestBody:
{
"activeAlertList":[
{
"assetId":"asset",
"assetPaths": ["treeId1:/assetId1/assetId2/assetIdx", "treeId2:/assetId3/assetIdx"],
"contentDesc":{
"defaultValue":"default2",
"i18nValue":{
"en_US":"english",
"zh_CN":"中文"
}
},
"contentId":"content",
"localOccurTime":"2019-11-07 15:15:58",
"measurepointId":"point111",
"modelId":"model",
"modelIdPath":"/path-path-path",
"occurTime":1573110958644,
"severityDesc":{
"defaultValue":"default",
"i18nValue":{
"en_US":"english",
"zh_CN":"中文"
}
},
"severityId":"severity",
"tag":{
"key1":" v1 "
},
"typeDesc":{
"defaultValue":"default1",
"i18nValue":{
"en_US":"english",
"zh_CN":"中文"
}
},
"typeId":"type",
"value":1
}
],
"action": "batchCreate"
}
返回示例¶
{
"code": 0,
"msg": "OK",
"requestId": "08f7c947-8c4e-4512-9764-58258173186e",
"data": [{
"code": 0,
"msg": "format right",
"data": "201911072a7658def1801fa23dc0ba494e2f38c8"
}],
"successSize": 1,
"totalSize": 1
}
Java SDK调用示例¶
package com.enos-iot.enos.event_service;
import com.envision.apim.poseidon.config.PConfig;
import com.envision.apim.poseidon.core.Poseidon;
import com.enos-iot.enos.api.common.constant.request.Pagination;
import com.enos-iot.enos.event_service.v2_1.*;
import com.enos-iot.enos.event_service.vo.*;
import com.google.common.collect.Lists;
import com.google.gson.Gson;
import org.junit.Test;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
private GenerateActiveAlert buildActiveAlert() {
GenerateActiveAlert activeAlert = new GenerateActiveAlert();
activeAlert.setAssetId("asset");
activeAlert.setModelId("model");
activeAlert.setModelIdPath("/path-path-path");
activeAlert.setMeasurepointId("point111");
activeAlert.setValue(1);
long now = System.currentTimeMillis();
activeAlert.setOccurTime(now);
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String localTime = df.format(now);
activeAlert.setLocalOccurTime(localTime);
activeAlert.setSeverityId("severity");
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);
activeAlert.setSeverityDesc(desc);
activeAlert.setTypeId("type");
StringI18n desc1 = new StringI18n();
desc1.setDefaultValue("default1");
Map < String, String > map1 = new HashMap < > ();
map1.put("zh_CN", "中文");
map1.put("en_US", "english");
desc1.setI18nValue(map1);
activeAlert.setTypeDesc(desc1);
activeAlert.setContentId("content");
StringI18n desc2 = new StringI18n();
desc2.setDefaultValue("default2");
Map < String, String > map2 = new HashMap < > ();
map2.put("zh_CN", "中文");
map2.put("en_US", "english");
desc2.setI18nValue(map2);
activeAlert.setContentDesc(desc2);
return activeAlert;
}
public void testBatchCreateActiveAlert() {
String accessKey = "yourAppAccessKey";
String secretKey = "yourAppSecretKey";
String orgId = "yourOrgId";
String url = "https://{apigw-address}";
BatchCreateActiveAlertsRequest request = new BatchCreateActiveAlertsRequest();
request.setOrgId(orgId);
List < GenerateActiveAlert > list = Lists.newArrayList();
GenerateActiveAlert activeAlert1 = buildActiveAlert();
Map < String, String > tags = new HashMap < > ();
tags.put("yourTagKey1", "yourTagValue1");
activeAlert1.setTag(tags);
list.add(activeAlert1);
GenerateActiveAlert activeAlert2 = buildActiveAlert();
tags = new HashMap < > ();
tags.put("yourTagKey2", "yourTagValue2");
activeAlert2.setTag(tags);
list.add(activeAlert2);
GenerateActiveAlert activeAlert3 = buildActiveAlert();
tags = new HashMap < > ();
tags.put("yourTagKey3", "yourTagValue3");
activeAlert3.setTag(tags);
list.add(activeAlert3);
request.setActiveAlertList(list);
try {
BatchCreateActiveAlertsResponse response = Poseidon.config(PConfig.init().appKey(accessKey).appSecret(secretKey).debug())
.url(url)
.getResponse(request, BatchCreateActiveAlertsResponse.class);
System.out.println(response);
} catch (Exception e) {
System.out.print(e);
}
}