This lua parser will merge two meta fields into a new meta field if the device type matches.
In this example we took the device type to be ciscoironport.
The meta to be merged was the content of event.source and a custom meta key called silca.mid
The results of this were put into a new meta key called uniquemid.
local lua_mergemeta= nw.createParser("MergeMeta", "Merges Two Meta Fields into 1 To Create Unqiue ID")
--[[
DESCRIPTION
Merges Two Meta fields into one to create a unique meta
AUTHOR
VERSION
DEPENDENCIES
None
--]]
-- Write meta into the following meta key(s)
lua_mergemeta:setKeys({
nwlanguagekey.create("uniquemid",nwtypes.Text),
})
function lua_mergemeta:sessionBegin()
meta1 = nil
meta2 = nil
devicetype = nil
end
function lua_mergemeta:CheckDevice(index,dtype)
if dtype == 'ciscoironport' then
devicetype = dtype
end
end
function lua_mergemeta:getMeta1(index,mymeta1)
if devicetype then
meta1 = mymeta1
end
end
function lua_mergemeta:getMeta2(index,mymeta2)
if devicetype and meta1 then
meta2 = mymeta2
end
end
function lua_mergemeta:sessionEnd()
if devicetype then
if meta1 then
if meta2 then
nw.createMeta(self.keys["uniquemid"], meta1 .. meta2)
end
end
end
end
-- declare what tokens and events we want to match
lua_mergemeta:setCallbacks({
[nwevents.OnSessionBegin] = lua_mergemeta.sessionBegin,
[nwlanguagekey.create("device.type", nwtypes.Text)] = lua_mergemeta.CheckDevice,
[nwlanguagekey.create("event.source", nwtypes.Text)] = lua_mergemeta.getMeta1,
[nwlanguagekey.create("silca.mid", nwtypes.Text)] = lua_mergemeta.getMeta2,
[nwevents.OnSessionEnd] = lua_mergemeta.sessionEnd,
})
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.