Yesterday, 07:51
Okay, I copied and pasted the script.
But it's not running every hour. I know the function works:
I think everything is correct, thanks.
But it's not running every hour. I know the function works:
Code:
test_enabled = grp.getvalue('32/3/41')
test_freq = grp.getvalue('32/3/40')
if not test_enabled then
return
end
key = 'prev_test_time'
curr_time = os.time()
prev_time = storage.get(key, 0)
elapsed_hours = math.round((curr_time - prev_time) / 3600)
if elapsed_hours < test_freq then
return
end
storage.set(key, curr_time)
------------------------------------------------------------
-- IP MONITORING (PING) - Simplified Version
-- Logic:
-- 1) Ping all IPs
-- 2) Send status (1/0)
-- 3) Send alarm (1 if no communication)
-- Execution: This script runs when you call it
------------------------------------------------------------
-- Devices: REAL IP + GA status (bool) + GA alarm (bool)
local devices = {
{ real_ip = "192.168.0.11", ga_status = "32/3/14", ga_alarm = "32/3/27" },
{ real_ip = "192.168.0.12", ga_status = "32/3/15", ga_alarm = "32/3/28" },
{ real_ip = "192.168.0.13", ga_status = "32/3/16", ga_alarm = "32/3/29" },
{ real_ip = { 192.168.0.16, ga_estado = "32/3/17", ga_alarma = "32/3/30" },
{ ip_real = "192.168.0.111", ga_estado = "32/3/18", ga_alarma = "32/3/31" },
{ ip_real = "192.168.0.112", ga_estado = "32/3/19", ga_alarma = "32/3/32" },
{ ip_real = "192.168.0.113", ga_estado = "32/3/20", ga_alarma = "32/3/33" },
{ ip_real = "192.168.0.121", ga_estado = { ip_real = "32/3/21", ga_alarma = "32/3/34" },
{ ip_real = "192.168.0.122", ga_estado = "32/3/22", ga_alarma = "32/3/35" },
{ ip_real = "192.168.0.123", ga_estado = "32/3/23", ga_alarma = "32/3/36" },
{ ip_real = "192.168.0.131", ga_estado = "32/3/24", ga_alarma = "32/3/37" },
{ ip_real = "192.168.0.132", ga_estado = "32/3/25", ga_alarma = "32/3/38" }, },
{ real_ip = "192.168.0.133", status_ga = "32/3/26", alarm_ga = "32/3/39" },
{ real_ip = "192.168.0.161", status_ga = "32/3/43", alarm_ga = "32/3/44" }
}
------------------------------------------------------------
-- Function: ping
------------------------------------------------------------
local function test_device(ip)
local cmd = "ping -c 1 -W 1 " .. ip .. " >/dev/null 2>&1"
local result = os.execute(cmd)
return (result == true or result == 0)
end
------------------------------------------------------------
-- Function: run test (only once)
------------------------------------------------------------
local function run_test()
for _, dev in ipairs(devices) do
local ok = test_device(dev.ip_real)
local estado = ok and 1 or 0
local alarma = ok and 0 or 1
grp.write(dev.ga_estado, estado)
grp.write(dev.ga_alarma, alarma)
end
end
------------------------------------------------------------
-- Direct execution of the test
------------------------------------------------------------
ejecutar_test()I think everything is correct, thanks.