current_alerts
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
Next revision | |||
— | current_alerts [2019/01/09 10:38] – created akuzmuk | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | |||
+ | ===== 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 | ||
+ | |startTime |Alert trigger time | Number, UnixTime| | ||
+ | |regId |The number of the register in which the flag of the alert led to this alert | ||
+ | |regAlias |Variable name for programs |String| | ||
+ | |bit |Number of the bit with the alarm flag |Number| | ||
+ | |title |Alert name |String| | ||
+ | |connectionTitle |Connection name |String| | ||
+ | |connectionId |Connection ID |Number| | ||
+ | |connectionAlias |The name of the connection variable for programs|String| | ||
+ | |acknowledgedBy| User name, who confirmed the alert. If the alert is not confirmed - empty string.|String| | ||
+ | |acknowledgedTime |Time, | ||
+ | |canBeAcknowledged |The flag indicates the alert can be confirmed. |Boolean| | ||
+ | |||
+ | Using this structure, it is possible to implement, for example, various notification scenarios about unconfirmed accidents. | ||
+ | |||
+ | An example of such program: | ||
+ | <code lua> | ||
+ | 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[' | ||
+ | local acknowledgedTime = alert[' | ||
+ | local startTime = alert[' | ||
+ | local waitSecondsBeforeEscalate = 300; -- notify about alerts that are not confirmed for more than 5 minutes | ||
+ | local regId = alert[' | ||
+ | local bit = alert[' | ||
+ | if (canBeAcknowledged and acknowledgedTime == 0) then | ||
+ | if (now - startTime > waitSecondsBeforeEscalate) then | ||
+ | if (notificationsSent[regId] == nil or notificationsSent[regId][bit] ~= startTime) then | ||
+ | --ERROR(" | ||
+ | SendSMS(" | ||
+ | if (notificationsSent[regId] == nil) then | ||
+ | notificationsSent[regId] = {}; | ||
+ | end | ||
+ | notificationsSent[regId][bit] = startTime; | ||
+ | end | ||
+ | end | ||
+ | end | ||
+ | end | ||
+ | end | ||
+ | end | ||
+ | </ | ||
+ | |||
current_alerts.txt · Last modified: 2022/07/04 12:35 by emozolyak