2022-05-04 17:37:01 +00:00
|
|
|
local util = require("scada-common.util")
|
|
|
|
|
2022-05-10 21:06:27 +00:00
|
|
|
---@class alarm
|
2022-05-04 17:37:01 +00:00
|
|
|
local alarm = {}
|
2022-04-25 14:36:47 +00:00
|
|
|
|
2022-05-10 21:06:27 +00:00
|
|
|
---@alias SEVERITY integer
|
2022-01-25 18:51:43 +00:00
|
|
|
SEVERITY = {
|
|
|
|
INFO = 0, -- basic info message
|
|
|
|
WARNING = 1, -- warning about some abnormal state
|
|
|
|
ALERT = 2, -- important device state changes
|
|
|
|
FACILITY = 3, -- facility-wide alert
|
|
|
|
SAFETY = 4, -- safety alerts
|
|
|
|
EMERGENCY = 5 -- critical safety alarm
|
|
|
|
}
|
|
|
|
|
2022-05-04 17:37:01 +00:00
|
|
|
alarm.SEVERITY = SEVERITY
|
|
|
|
|
2022-05-10 21:06:27 +00:00
|
|
|
-- severity integer to string
|
|
|
|
---@param severity SEVERITY
|
2022-05-31 20:09:06 +00:00
|
|
|
function alarm.severity_to_string(severity)
|
2022-05-04 17:37:01 +00:00
|
|
|
if severity == SEVERITY.INFO then
|
|
|
|
return "INFO"
|
|
|
|
elseif severity == SEVERITY.WARNING then
|
|
|
|
return "WARNING"
|
|
|
|
elseif severity == SEVERITY.ALERT then
|
|
|
|
return "ALERT"
|
|
|
|
elseif severity == SEVERITY.FACILITY then
|
|
|
|
return "FACILITY"
|
|
|
|
elseif severity == SEVERITY.SAFETY then
|
|
|
|
return "SAFETY"
|
|
|
|
elseif severity == SEVERITY.EMERGENCY then
|
|
|
|
return "EMERGENCY"
|
|
|
|
else
|
|
|
|
return "UNKNOWN"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-05-10 21:06:27 +00:00
|
|
|
-- create a new scada alarm entry
|
|
|
|
---@param severity SEVERITY
|
|
|
|
---@param device string
|
|
|
|
---@param message string
|
2022-05-31 20:09:06 +00:00
|
|
|
function alarm.scada_alarm(severity, device, message)
|
2022-01-25 18:51:43 +00:00
|
|
|
local self = {
|
2022-04-25 14:36:47 +00:00
|
|
|
time = util.time(),
|
2022-01-25 18:51:43 +00:00
|
|
|
ts_string = os.date("[%H:%M:%S]"),
|
|
|
|
severity = severity,
|
|
|
|
device = device,
|
|
|
|
message = message
|
|
|
|
}
|
|
|
|
|
2022-05-10 21:06:27 +00:00
|
|
|
---@class scada_alarm
|
|
|
|
local public = {}
|
|
|
|
|
|
|
|
-- format the alarm as a string
|
|
|
|
---@return string message
|
2022-05-31 20:09:06 +00:00
|
|
|
function public.format()
|
|
|
|
return self.ts_string .. " [" .. alarm.severity_to_string(self.severity) .. "] (" .. self.device .. ") >> " .. self.message
|
2022-01-25 18:51:43 +00:00
|
|
|
end
|
|
|
|
|
2022-05-10 21:06:27 +00:00
|
|
|
-- get alarm properties
|
2022-05-31 20:09:06 +00:00
|
|
|
function public.properties()
|
2022-01-25 18:51:43 +00:00
|
|
|
return {
|
|
|
|
time = self.time,
|
|
|
|
severity = self.severity,
|
|
|
|
device = self.device,
|
|
|
|
message = self.message
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2022-05-10 21:06:27 +00:00
|
|
|
return public
|
2022-01-25 18:51:43 +00:00
|
|
|
end
|
|
|
|
|
2022-05-04 17:37:01 +00:00
|
|
|
return alarm
|