current_alerts
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
current_alerts [2021/11/03 10:42] – [GetCurrentAlerts()] emozolyak | current_alerts [2022/07/04 12:35] (current) – [GetCurrentAlerts()] emozolyak | ||
---|---|---|---|
Line 9: | Line 9: | ||
^Key ^Description | ^Key ^Description | ||
- | |alertId|Alert id key in the project | Number| | + | |alertId|Alert id key in the project |Number | |
- | |title |Alert name |String| | + | |title |Alert name |String | |
- | |startTime |Alert trigger time | Number, UnixTime| | + | |startTime |Alert trigger time |Number, UnixTime | |
- | |alertLevel |The flag indicates the alert can be confirmed. | [1,2,3] Info, Warn, Alert| | + | |alertLevel |The flag indicates the alert can be confirmed. |[1, |
- | |acknowledgedBy| User name, who confirmed the alert. If the alert is not confirmed - empty string.|String| | + | |acknowledgedBy| User name, who confirmed the alert. If the alert is not confirmed - empty string.|String | |
- | |acknowledgedTime |Time, | + | |acknowledgedTime |Time, |
- | |canBeAcknowledged |The flag indicates the alert can be confirmed. |Boolean| | + | |canBeAcknowledged |The flag indicates the alert can be confirmed. |Boolean | |
|groupId|The id key of the group the alert belongs to|Number | | |groupId|The id key of the group the alert belongs to|Number | | ||
Line 22: | 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.1635936165.txt.gz · Last modified: 2021/11/03 10:42 by emozolyak