Create History Alerts in Batch¶
批量创建历史告警进。
备注
一旦有一条告警的格式校验不通过,所有告警均无法创建成功。
请求格式¶
POST https://{apigw-address}/event-service/v2.1/history-alerts?action=batchCreate
请求参数(URI)¶
名称 |
位置(Path/Query) |
必需/可选 |
数据类型 |
描述 |
---|---|---|---|---|
orgId |
Query |
必需 |
String |
资产所属的组织ID。如何获取orgId信息>> |
请求参数(Body)¶
名称 |
必需/可选 |
数据类型 |
描述 |
---|---|---|---|
historyAlertList |
必需 |
HistoryAlert结构体数组 |
有关historyAlert结构体的定义。见 HistoryAlert结构体>> |
HistoryAlert结构体 ¶
名称 |
必需/可选 |
数据类型 |
描述 |
---|---|---|---|
assetId |
必需 |
String |
资产ID。如何获取Asset ID信息>> |
modelId |
必需 |
String |
告警适用的模型的ID。如何获取modelId信息>> |
modelIdPath |
可选 |
String |
模型路径 |
measurepointId |
可选 |
String |
资产测点。必须使用 |
deviceStatus |
可选 |
String |
设备状态,如“offline”。必须使用 |
value |
必需 |
Object |
测点值。 |
occurTime |
必需 |
Long |
告警发生的时间,以UTC时间表示,格式见 UTC采用的ISO8601标准时间格式>> |
localOccurTime |
可选 |
String |
告警发生的时间,以本地时间表示,格式见 localtime采用的日期时间格式>> |
recoverTime |
必需 |
Long |
触发告警的异常状况恢复正常的时间,以UTC时间表示,格式见 UTC采用的ISO8601标准时间格式>> |
localRecoverTime |
可选 |
String |
触发告警的异常状况恢复正常的时间,以本地时间表示,格式见 localtime采用的日期时间格式>> |
recoverReason |
可选 |
String |
异常状况恢复的原因。 |
severityId |
可选 |
String |
告警级别编号。 |
severityDesc |
可选 |
StringI18n |
告警级别描述。结构请见 国际化名称结构体>> |
typeId |
可选 |
String |
告警类型编号。 |
typeDesc |
可选 |
StringI18n |
告警类型描述。结构请见 国际化名称结构体>> |
subTypeId |
可选 |
String |
告警子类型编号。 |
subTypeDesc |
可选 |
StringI18n |
告警子类型描述。结构请见 国际化名称结构体>> |
contentId |
可选 |
String |
告警内容编号。 |
contentDesc |
可选 |
StringI18n |
告警内容描述。结构请见 国际化名称结构体>> |
tags |
可选 |
Map |
标签,只支持全量更新。参见`标签的作用与表示方法>> </docs/api/zh_CN/2.1.0/api_faqs.html#id6>`_ |
响应参数¶
名称 |
数据类型 |
描述 |
---|---|---|
data |
EnosBatchEachData结构体数组 |
有关EnosBatchEachData结构体的定义,参见下表。 |
EnosBatchEachData结构体¶
名称 |
数据类型 |
描述 |
---|---|---|
code |
Integer |
单条记录创建成功或失败,0:成功,-1:失败 |
msg |
String |
提示格式正确还是错误 |
data |
String |
若创建成功,则为 |
示例¶
请求示例¶
url: POST
https://{apigw-address}/event-service/v2.1/history-alerts?action=batchCreate&orgId=yourOrgId
method: POST
requestBody:
{
"historyAlertList":[
{
"assetId":"asset",
"contentDesc":{
"defaultValue":"default2",
"i18nValue":{
"en_US":"english",
"zh_CN":"中文"
}
},
"contentId":"content",
"localOccurTime":"2019-11-07 15:36:32",
"localRecoverTime":"2019-11-18 00:00:00",
"measurepointId":"point111",
"modelId":"model",
"modelIdPath":"/path-path-path",
"occurTime":1573025793008,
"recoverTime":1573112193008,
"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.0
},
{
"assetId":"asset",
"contentDesc":{
"defaultValue":"default2",
"i18nValue":{
"en_US":"english",
"zh_CN":"中文"
}
},
"contentId":"content",
"localOccurTime":"2019-11-07 15:36:33",
"localRecoverTime":"2019-11-18 00:00:00",
"measurepointId":"point111",
"modelId":"model",
"modelIdPath":"/path-path-path",
"occurTime":1573112193008,
"orgId":"yourOrgId",
"severityDesc":{
"defaultValue":"default",
"i18nValue":{
"en_US":"english",
"zh_CN":"中文"
}
},
"severityId":"severity",
"tag":{
"key2":" v2 "
},
"typeDesc":{
"defaultValue":"default1",
"i18nValue":{
"en_US":"english",
"zh_CN":"中文"
}
},
"typeId":"type",
"value":1.0
},
{
"assetId":"asset",
"contentDesc":{
"defaultValue":"default2",
"i18nValue":{
"en_US":"english",
"zh_CN":"中文"
}
},
"contentId":"content",
"localOccurTime":"2019-11-07 15:36:33",
"localRecoverTime":"2019-11-18 00:00:00",
"measurepointId":"point111",
"modelId":"model",
"modelIdPath":"/path-path-path",
"occurTime":1573112193012,
"orgId":"yourOrgId",
"recoverTime":1573112193016,
"severityDesc":{
"defaultValue":"default",
"i18nValue":{
"en_US":"english",
"zh_CN":"中文"
}
},
"severityId":"severity",
"tag":{
"key3":" v3 "
},
"typeDesc":{
"defaultValue":"default1",
"i18nValue":{
"en_US":"english",
"zh_CN":"中文"
}
},
"typeId":"type",
"value":1.0
}
],
"action": "batchCreate"
}
返回示例¶
{
"code":99206,
"msg":"Partial Content Success",
"requestId":"de9281bf-3ebf-4783-97c8-4b94be384351",
"data":[
{
"code":0,
"msg":"format right",
"data":"2019110630b8cc38735e8ba9d1b3a6b5e4381e36"
},
{
"code":-1,
"msg":"format wrong",
"data":"recoverTime :parameter empty"
},
{
"code":0,
"msg":"format right",
"data":"20191107bd6ab07f9be6ab769b1e7c898b40cc83"
}
],
"successSize":2,
"totalSize":3
}
Java SDK调用示例¶
package com.envisioniot.enos.event_service;
import com.envision.apim.poseidon.config.PConfig;
import com.envision.apim.poseidon.core.Poseidon;
import com.envisioniot.enos.api.common.constant.request.Pagination;
import com.envisioniot.enos.event_service.v2_1.*;
import com.envisioniot.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;
}
private GenerateHistoryAlert buildHistoryAlert() {
GenerateActiveAlert activeAlert = buildActiveAlert();
Gson gson = new Gson();
GenerateHistoryAlert historyAlert = gson.fromJson(gson.toJson(activeAlert), GenerateHistoryAlert.class);
historyAlert.setRecoverTime(System.currentTimeMillis());
historyAlert.setLocalRecoverTime("2019-11-18 00:00:00");
return historyAlert;
}
public void testBatchCreateHistoryAlert() {
String accessKey = "yourAppAccessKey";
String secretKey = "yourAppSecretKey";
String orgId = "yourOrgId";
String url = "https://{apigw-address}";
BatchCreateHistoryAlertsRequest request = new BatchCreateHistoryAlertsRequest();
request.setOrgId(orgId);
List < GenerateHistoryAlert > list = Lists.newArrayList();
GenerateHistoryAlert historyAlert1 = buildHistoryAlert();
historyAlert1.setOccurTime(System.currentTimeMillis() - 24L * 3600 * 1000);
Map < String, String > tags = new HashMap < > ();
tags.put("key1", "v1");
historyAlert1.setTag(tags);
list.add(historyAlert1);
GenerateHistoryAlert historyAlert2 = buildHistoryAlert();
tags = new HashMap < > ();
tags.put("key2", "v2");
historyAlert2.setTag(tags);
list.add(historyAlert2);
GenerateHistoryAlert historyAlert3 = buildHistoryAlert();
tags = new HashMap < > ();
tags.put("key3", "v3");
historyAlert3.setTag(tags);
list.add(historyAlert3);
request.setHistoryAlertList(list);
try {
BatchCreateHistoryAlertsResponse response = Poseidon.config(PConfig.init().appKey(accessKey).appSecret(secretKey).debug())
.url(url)
.getResponse(request, BatchCreateHistoryAlertsResponse.class);
System.out.println(response);
} catch (Exception e) {
System.out.print(e);
}
}