User Tools

Site Tools


current_alerts

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
current_alerts [2021/11/03 11:22] – [GetCurrentAlerts()] emozolyakcurrent_alerts [2022/07/04 12:35] (current) – [GetCurrentAlerts()] emozolyak
Line 9: Line 9:
  
 ^Key ^Description                                                       ^Data type^                                           ^Key ^Description                                                       ^Data type^                                          
-|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,2,3] Info, Warn, Alert | 
-|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, when the alert was confiremed. If the alert is not confirmed - 0.|Number, UnixTime| +|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|+|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 35: Line 35:
       local time_diff = (now - a.startTime)       local time_diff = (now - a.startTime)
         if (a.canBeAcknowledged and (time_diff > ACK_DELAY_TOLERANCE)) then          if (a.canBeAcknowledged and (time_diff > ACK_DELAY_TOLERANCE)) then 
-            ERROR("The " .. a.title .. " exceeded ack time!")+            ERROR("The alert " .. a.title .. " exceeded ack time!")
         end          end 
    end     end 
Line 56: Line 56:
     end -- for      end -- for 
 end -- tprint  end -- tprint 
 +</code>
 +
 +=== 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>
 +--[[
 +    Checks if number of alerts has increased and then sends message via 
 +    Telegram 
 +--]] 
 +TELEGRAM_BOT_ID = "229345xxxxx"                -- your telegram chat bot id 
 +active_alerts = 0                              -- global counter for current alerts
 +
 +function main (userId)
 +  
 +  local alerts = GetCurrentAlerts()
 +  
 +  if (#alerts > active_alerts) then            -- number has increased, # - means count table elements
 +      local a_names = {}                       DEBUG("Alert count has increased!")
 +
 +      for a_num, a in ipairs(alerts) do 
 +          INFO("Processing alert #" .. a_num)
 +          table.insert(a_names, a.title)
 +      end 
 +      SendTelegramMessage(TELEGRAM_BOT_ID, 
 +                          "Current alerts are: " .. table.concat(a_names, ', '))
 +  end 
 +  
 +  active_alerts = #alerts
 +  
 +end
 </code> </code>
  
  
current_alerts.txt · Last modified: 2022/07/04 12:35 by emozolyak

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki