current_alerts
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
current_alerts [2019/01/09 10:38] – created akuzmuk | current_alerts [2022/07/04 12:35] (current) – [GetCurrentAlerts()] emozolyak | ||
---|---|---|---|
Line 9: | Line 9: | ||
^Key ^Description | ^Key ^Description | ||
- | |startTime |Alert | + | |alertId|Alert |
- | |regId |The number of the register | + | |title |Alert name |String | |
- | |regAlias |Variable name for programs |String| | + | |startTime |Alert trigger time |Number, UnixTime |
- | |bit |Number of the bit with the alarm flag |Number| | + | |alertLevel |The flag indicates |
- | |title |Alert name |String| | + | |acknowledgedBy| User name, who confirmed the alert. If the alert is not confirmed - empty string.|String | |
- | |connectionTitle |Connection name |String| | + | |acknowledgedTime |Time, |
- | |connectionId |Connection ID |Number| | + | |canBeAcknowledged |The flag indicates the alert can be confirmed. |Boolean |
- | |connectionAlias |The name of the connection variable for programs|String| | + | |groupId|The id key of the group the alert belongs to|Number |
- | |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. | Using this structure, it is possible to implement, for example, various notification scenarios about unconfirmed accidents. | ||
Line 25: | Line 22: | ||
An example of such program: | An example of such program: | ||
<code lua> | <code lua> | ||
- | local notificationsSent = {}; | ||
function main (userId) | function main (userId) | ||
- | | + | |
- | if (# | + | local ACK_DELAY_TOLERANCE = 30 |
- | for num,alert in pairs(alerts) do | + | local now = os.time() |
- | local now = os.time(); | + | |
- | local canBeAcknowledged = alert['canBeAcknowledged']; | + | |
- | local acknowledgedTime | + | |
- | | + | for a_num, a in ipairs(alerts) do |
- | | + | INFO(" |
- | | + | |
- | | + | INFO(tostring(a.canBeAcknowledged) .. ' ' .. a.startTime) |
- | if (canBeAcknowledged | + | local time_diff = (now - a.startTime) |
- | | + | |
- | if (notificationsSent[regId] == nil or notificationsSent[regId][bit] ~= startTime) then | + | ERROR(" |
- | | + | |
- | | + | end |
- | if (notificationsSent[regId] == nil) then | + | |
- | | + | end |
- | | + | |
- | | + | function tprint(t, indent) |
- | end | + | if not indent then indent = 0 end |
- | end | + | |
- | end | + | local formatting |
- | end | + | if type(v) |
- | end | + | |
+ | | ||
+ | else | ||
+ | | ||
+ | v = v and " | ||
+ | | ||
+ | ERROR(formatting .. v) | ||
+ | end | ||
+ | end -- for | ||
+ | end -- tprint | ||
+ | </ | ||
+ | |||
+ | === Example of sending Telegram messages upon new alerts === | ||
+ | |||
+ | Below is the example of how to send Telegram messages when the alert count has increased: | ||
+ | <code lua> | ||
+ | --[[ | ||
+ | | ||
+ | Telegram | ||
+ | --]] | ||
+ | TELEGRAM_BOT_ID | ||
+ | active_alerts | ||
+ | |||
+ | function main (userId) | ||
+ | |||
+ | local alerts = GetCurrentAlerts() | ||
+ | |||
+ | | ||
+ | local a_names = {} DEBUG(" | ||
+ | |||
+ | for a_num, a in ipairs(alerts) do | ||
+ | INFO(" | ||
+ | table.insert(a_names, | ||
+ | end | ||
+ | SendTelegramMessage(TELEGRAM_BOT_ID, | ||
+ | | ||
+ | end | ||
+ | |||
+ | active_alerts | ||
+ | |||
end | end | ||
</ | </ | ||
current_alerts.1547030292.txt.gz · Last modified: 2019/01/09 10:38 by akuzmuk