current_alerts
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
Previous revisionNext revision | |||
— | current_alerts [2021/11/03 10:41] – emozolyak | ||
---|---|---|---|
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 | ||
+ | |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, | ||
+ | |canBeAcknowledged |The flag indicates the alert can be confirmed. |Boolean| | ||
+ | |groupId|The id key of the group the alert resides in|Number | | ||
+ | |||
+ | 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