Setting a State-based Triggered Alert¶
Situations may arise where EnOS needs to send an alert when the device is in a certain state.
For example, when the EnOS alert service is used to monitor the A/C devices of a smart building, an alert rule can be set to trigger the “A/C Offline” alert when an A/C device becomes offline. This alert would be cleared when the A/C device is online again.
EnOS currently can only trigger device alerts based on the offline state.
Alert Masking and Delay for State-based Triggered Alerts¶
Alert Masking:
When a particular state of a device triggers an alert, the alerts of the devices of its child nodes in the asset tree will be blocked.
The state-based alert of a device will be masked if alert masking is set for the device of its upper node in the asset tree.
Alert Delay:
You can set alert delays for state-based alerts, for example, where a “Device Offline” alert is triggered only when a device is offline for at least 5 minutes.
About This Task¶
This task uses a smart building scenario to describe how to set a state-based triggered alert. An ammeter that measures the real-time current of the refrigerator, as simulated in the Tutorial: How to Set the Alerts of Different Threshold for the Devices of the Same Model, is used to set the state-based triggered alerts.
Prerequisites¶
Ensure that you have the permissions for Alert Engine. If not, contact your OU administrator. For more information, see Policies, Roles, and Permissions.
Go through the Tutorial: Setting Different Alert Thresholds for Devices of the Same Model.
Procedure¶
Select Alert Rule and create an alert rule based on the below. See Creating Alert Rules for how to create the alert rule.
At this time, the alert is set to trigger immediately when the ammeter gets offline.
Copy the sample code
fridgeMQTT
from the Tutorial: Setting Different Alert Thresholds for Devices of the Same Model to your IDE.Run
fridgeMQTT
. You will be able to see from Asset Management > Device Asset that therefrigerator meter
is now online.At this point, you can stop running the
fridgeMQTT
code block.
Results¶
Go to Alert Engine > Alert Records and you can see the triggered state-based alerts with the State as Real-time.
If you run the fridgeMQTT
code block again at this time, the State of the alert record will change to Historical.
Impact on API¶
An optional parameter deviceStatus
with an offline
value has been added to the request parameters (Body) of the following APIs:
Create Alert Rule
Update Alert Rule
Search Active Alerts
Search History Alerts
Search Alert Rule
The addition serves the following purposes:
Create or update alert rules so that the alert can be triggered based on the device state.
Return the active or history alert records that were triggered based on the device state.
Java SDK Sample¶
You can use the Search Active Alerts
API to search an active alert based on the device state.
import com.envision.apim.poseidon.config.PConfig;
import com.envision.apim.poseidon.core.Poseidon;
public class searchActiveAlert {
public static void main(String[] args) {
String accessKey = "yourAccessKey";
String secretKey = "yourSecretKey";
String data = "{\n" +
"\t\"deviceStatus\":\"offline\",\n" +
"}";
String response = Poseidon.config(PConfig.init().appKey(accessKey).appSecret(secretKey))
.url("https://beta-apim-cn4.eniot.io/event-service/v2.1/active-alerts?action=search&orgId=o15434988531231")
.method("POST")
.requestBody(data)
.sync();
System.out.println(response);
}
}
Return Sample:
{
"code":0,
"msg":"OK",
"requestId":"9d99634e-b2b5-4f45-9071-d691dd71073d",
"data":[
{
"eventId":"201912020a1487e26e2d84601d24f1c5783634d8",
"orgId":"yourOrgId",
"assetId":"I7Vp9nRm",
"modelId":"current_meter",
"modelIdPath":"/current_meter",
"measurepointId":null,
"deviceStatus":"offline",
"hitRuleId":"CurrentMeterAlertState",
"value":"1",
"occurTime":1575277201254,
"localOccurTime":"2019-12-02 17:00:01",
"createTime":1575277201388,
"updateTime":1575277201388,
"severityId":"MeterAlert001",
"severityDesc":{
"defaultValue":"Warning: Current Over Threshold",
"i18nValue":{
"en_US":"",
"zh_CN":""
}
},
"typeId":"alertType003",
"typeDesc":{
"defaultValue":"This is a serious warning",
"i18nValue":{
}
},
"subTypeId":null,
"subTypeDesc":null,
"contentId":"MeterAlert003",
"contentDesc":{
"defaultValue":"设备已离线",
"i18nValue":{
"en_US":"Device offline",
"zh_CN":"设备已离线"
}
},
"eventType":1,
"tag":{
},
"ruleDesc":null,
"assetPath":null,
"maskedBy":null
}
]
}