Here are some snippets that might be useful...
Just to give you some context, this is from a probe written in Lua that simply attempts to contact each robot to make sure it is reachable. It counts the number of failures per robot and only sends an alarm when the failures exceed a specific threshold (the 'failures' variable below, which I believe I have set to 3).
Creating a table to track alarms:
local alarms = {}
Doing the check (which occurs inside a loop):
local suppkey = probename.."/"..robot
if rc == NIME_OK then
if alarms[suppkey] == nil or alarms[suppkey] >= failures then
probe.log(1, "Request to robot %s successful, sending clear", nimaddr)
nimbus.alarm(NIML_CLEAR, "Robot "..nimaddr.." is reachable", suppkey, nil, robot)
alarms[suppkey] = 0
else
probe.log(2, "Request to robot %s successful", nimaddr)
end
else
if alarms[suppkey] == nil then
alarms[suppkey] = 1
else
alarms[suppkey] = alarms[suppkey] + 1
end
if alarms[suppkey] >= failures then
probe.log(1, "Request to robot %s failed %d times (error = %d), sending alarm", nimaddr, alarms[suppkey], rc)
nimbus.alarm(alarm_level, "Robot "..nimaddr.." is NOT reachable", suppkey, nil, robot)
else
probe.log(1, "Request to robot %s failed %d times (error = %d)", nimaddr, alarms[suppkey], rc)
end
end