Events Handling

This section will explain the entire process of creating and catching events in Lua. In order to generate events from Lua, the setevent function can be used.

Create an Action Item on the ingress Node and name it "events_generator".

Paste inside its Lua Script Body the example in the setevent function description and run the code every time you want to fire an event.

The events that are set by scripts can be caught using a Script Events object that is on the same level or above the item generating the events. Create such an item (following the instructions in the linked Object Guide page).

Now, in order to manipulate the information of the events that are caught by "script_event", another action item is needed. Create one under the Node and name it "events_catcher". Set "script_event" as a triggering reference to it and name it "event".

The following code will display the information of each event that is fired by the script inside "events_generator":

function table_tostring(tab)
  local s = '[ '
  for k,v in pairs(tab) do
    local value = tostring(v)
    if type(v) == 'table' then
      value = table_tostring(v)
    end
    if type(k) == 'number' then
      s = s .. value .. ' '
    else
      s = s .. k .. '=' .. value .. ' '
    end
  end
  s = s .. ']'
  return s
end

local tab = syslib.getvalue("event")
local str = ""
for k,v in pairs(tab) do
  local value = tostring(v);
  if type(v) == "table" then
    value = table_tostring(v)
  end
  str = str .. k .. ' = ' .. value .. '\n'
end

return str

In order to obtain the information of events that are generated by other sources than scripts, all that is needed is an Action Item similar to "event_catcher", having as reference the object catching the events (e.g. an Event Stream object). The event data can be retrieved in the same way in script.