current_alerts
This is an old revision of the document!
Functions to work with alerts
GetCurrentAlerts()
The GetCurrentAlerts function returns a list of current alerts. Type of returned value is table. Its key is the alarm number, the value is the another table with the alert properties.
Alert properties are:
Key | Description | Data type |
---|---|---|
alertId | Alert id key in the project | Number |
title | Alert name | String |
startTime | Alert trigger time | Number, UnixTime |
alertLevel | The flag indicates the alert can be confirmed. | [1,2,3] Info, Warn, Alert |
acknowledgedBy | User name, who confirmed the alert. If the alert is not confirmed - empty string. | String |
acknowledgedTime | Time, when the alert was confiremed. If the alert is not confirmed - 0. | Number, UnixTime |
canBeAcknowledged | The flag indicates the alert can be confirmed. | Boolean |
groupId | The id key of the group the alert belongs to | Number |
Using this structure, it is possible to implement, for example, various notification scenarios about unconfirmed accidents.
An example of such program:
local notificationsSent = {}; function main (userId) local alerts = GetCurrentAlerts(); if (#alerts > 0) then for num,alert in pairs(alerts) do local now = os.time(); local canBeAcknowledged = alert['canBeAcknowledged']; local acknowledgedTime = alert['acknowledgedTime']; local startTime = alert['startTime']; local waitSecondsBeforeEscalate = 300; -- notify about alerts that are not confirmed for more than 5 minutes local regId = alert['regId']; local bit = alert['bit']; if (canBeAcknowledged and acknowledgedTime == 0) then if (now - startTime > waitSecondsBeforeEscalate) then if (notificationsSent[regId] == nil or notificationsSent[regId][bit] ~= startTime) then --ERROR("Alert" .. alert['title'] .. " was not acknowledged!"); SendSMS("380501234567", "The alert is not confirmed: " .. alert['title']); if (notificationsSent[regId] == nil) then notificationsSent[regId] = {}; end notificationsSent[regId][bit] = startTime; end end end end end end
current_alerts.1635936165.txt.gz ยท Last modified: 2021/11/03 10:42 by emozolyak