User Tools

Site Tools


current_alerts

This is an old revision of the document!


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 Data type
startTime Alert trigger time Number, UnixTime
regId The number of the register in which the flag of the alert led to this alert Number
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 programsString
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
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:

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['canBeAcknowledged'];
            local acknowledgedTime = alert['acknowledgedTime'];
            local startTime = alert['startTime'];
            local waitSecondsBeforeEscalate = 300; -- notify about alerts that are not confirmed for more than 5 minutes
            local regId = alert['regId'];
            local bit = alert['bit'];
            if (canBeAcknowledged and acknowledgedTime == 0) then
                if (now - startTime > waitSecondsBeforeEscalate) then
                    if (notificationsSent[regId] == nil or notificationsSent[regId][bit] ~= startTime) then
                        --ERROR("Alert" .. alert['title'] .. " was not acknowledged!");
                        SendSMS("380501234567", "The alert is not confirmed: " .. alert['title']);
                        if (notificationsSent[regId] == nil) then
                            notificationsSent[regId] = {};
                        end
                        notificationsSent[regId][bit] = startTime;
                    end
                end
            end
        end
    end
end
current_alerts.1547030292.txt.gz ยท Last modified: 2019/01/09 10:38 by akuzmuk

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki