Create History Alert¶
创建历史告警。除了必填性校验,不需要对参数的合法性进行校验。用户使用的如contentId不会在EnOS平台的系统上维护。相同assetId、measurepointId和occurTime的插入告警只作更新操作。
请求格式¶
POST https://{apigw-address}/event-service/v2.1/history-alerts?action=create
请求参数(URI)¶
名称  | 
位置(Path/Query)  | 
必需/可选  | 
数据类型  | 
描述  | 
|---|---|---|---|---|
orgId  | 
Query  | 
必需  | 
String  | 
资产所属的组织ID。如何获取orgId信息>>  | 
请求参数(Body)¶
名称  | 
必需/可选  | 
数据类型  | 
描述  | 
|---|---|---|---|
historyAlert  | 
必需  | 
HistoryAlert结构体  | 
历史告警。见 HistoryAlert结构体>>  | 
HistoryAlert结构体  ¶
备注
以下非必须字段中,必须提供 measurepointId 或 deviceStatus 作为告警触发条件。
名称  | 
必需/可选  | 
数据类型  | 
描述  | 
|---|---|---|---|
assetId  | 
必需  | 
String  | 
资产ID。如何获取Asset ID信息>>  | 
modelId  | 
必需  | 
String  | 
告警适用的模型的ID。如何获取modelId信息>>  | 
modelIdPath  | 
可选  | 
String  | 
模型路径  | 
measurepointId  | 
可选  | 
String  | 
资产测点。如何获取测点(pointId)信息>>  | 
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  | 
标签,只支持全量更新。详见 标签的作用与表示方法>>  | 
响应参数¶
名称  | 
数据类型  | 
描述  | 
|---|---|---|
data  | 
String  | 
告警ID。  | 
示例¶
请求示例¶
url: https://{apigw-address}/event-service/v2.1/history-alerts?action=create&orgId=yourOrgId
method: POST
requestBody:
{
    "historyAlert":{
        "assetId":"qu5TmJRj",
        "modelId":"Inverter_Model",
        "modelIdPath":"/Inverter_Model",
        "measurepointId":"power",
        "value":"3.5559796405967736",
        "occurTime":1559304899404,
        "localOccurTime":"2019-06-01 02:14:59",
        "recoverTime":1559304900404,
        "localRecoverTime":"2019-06-01 12:14:59",
        "severityId":"alert_001",
        "severityDesc":{
            "defaultValue":"Warn",
            "i18nValue":{
                "en_US":"警告",
                "zh_CN":"警告"
            }
        },
        "typeId":"errorType",
        "typeDesc":{
            "defaultValue":"Warn",
            "i18nValue":{
                "en_US":"login failed",
                "zh_CN":"登录失败"
            }
        },
        "contentId":"planetTemperature",
        "contentDesc":{
            "defaultValue":"the temperature is too high",
            "i18nValue":{
                "en_US":"the temperature is too high",
                "zh_CN":"温度过高"
            }
        },
        "tags":{
            "Tag666":"63253w532",
            "Tag888":"63253w532888",
            "Tag":"1111"
        }
    },
  "action": "create"
}
返回示例¶
{
    "code": 0,
    "msg": "OK",
    "requestId": "4873095e-621d-4cfd-bc2c-edb520f574ea",
    "data": "20191101479fb7810c81a0cfe08f3552db40e546"
}
Java SDK调用示例¶
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 testCreateHistoryAlert() {
    String accessKey = "yourAppAccessKey";
    String secretKey = "yourAppSecretKey";
    String orgId = "yourOrgId";
    String url = "https://{apigw-address}";
    CreateHistoryAlertRequest request = new CreateHistoryAlertRequest();
    GenerateHistoryAlert historyAlert = new GenerateHistoryAlert();
    historyAlert.setAssetId("yourAssetId");
    historyAlert.setModelId("yourModelId");
    historyAlert.setModelIdPath("yourModelIdPath");
    historyAlert.setMeasurepointId("yourMeasurementPointId");
    historyAlert.setValue(1);
    historyAlert.setOccurTime(System.currentTimeMillis());
    historyAlert.setLocalOccurTime("2019-08-08 00:00:00");
    historyAlert.setSeverityId("yourSeverityId");
    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);
    historyAlert.setSeverityDesc(desc);
    historyAlert.setTypeId("yourTypeId");
    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);
    historyAlert.setTypeDesc(desc1);
    historyAlert.setContentId("yourContentId");
    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);
    historyAlert.setContentDesc(desc2);
    Map < String, String > tags = new HashMap < > ();
    tags.put("yourTagKey", "yourTagValue");
    historyAlert.setTag(tags);
    historyAlert.setRecoverTime(System.currentTimeMillis());
    historyAlert.setRecoverReason("reason");
    historyAlert.setLocalRecoverTime("2019-07-18 00:00:00");
    request.setHistoryAlert(historyAlert);
    request.setOrgId(orgId);
    try {
        CreateHistoryAlertResponse response = Poseidon.config(PConfig.init().appKey(accessKey).appSecret(secretKey).debug())
            .url(url)
            .getResponse(request, CreateHistoryAlertResponse.class);
        System.out.println(response);
    } catch (Exception e) {
        System.out.print(e);
    }
}