2016-07-14 02:52 AM
Does there exist a function to get the value of a specific meta key when writing LUA parsers for log content? My use case is the following:
I want to perform some additional processing on the url meta when it is registered but only in the case where the device.type associated with the log event is A. If the device.type is, say, B instead, I do not want to do anything. I.e.:
if meta 'url' is registered and 'device.type' equals 'A' then
call function parseURL
end
Or if that is not possible, then:
if meta 'url' is registered then
call function parseURL
if 'device.type' is not nil and 'device.type' equals 'A' then
...do something...
end
end
To put it short, I am kind of looking for the opposite of "nwlanguage.create
" - something like 'nwlanguage.get("metaKey")
'. I suppose this could be done by simply looking for a string in the payload, but that seems like unnecessarily heavy if such a getter exists.
2016-07-14 08:17 AM
You can use a meta key as a callback.
A caveat, because you're talking about logs: meta-callbacks from log parsers occur in no particular order. You can't assume that device.type will be registered before url, or that url will be registered before device.type.
So I'd suggest something like this:
function myParser.onBegin()
deviceType = nil
url = nil
end
function myParser:doStuff()
if deviceType and url then
...
end
end
function myParser:onURL(idx, vlu)
url = vlu
self:doStuff()
end
function myParser:onDeviceType(idx, vlu)
deviceType = vlu
self:doStuff()
end
myParser:setCallbacks({
[nwevents.OnSessionBegin] = myParser.onBegin,
[nwlanguagekey.create("url")] = myParser.onURL,
[nwlanguagekey.create("device.type")] = myParser.onDeviceType
})