AnsweredAssumed Answered

Working with integers in LUA-NWDB

Question asked by Nick Mikhal on Apr 16, 2019
Latest reply on May 13, 2019 by Nick Mikhal

Good afternoon,


I am working on LUA script on top of proxy parsers to extract ports from url's among other things.
I have an issue working with integers, while strings are extracted properly.
Not to post full script here are the main parts, which work fine in LUA IDE, but have issues with integers in SA:

-Sample target, need to extract 8080:

-I define target metakey:


-Then I extract it as string (just a sample from code to get the idea):
ip_dstport= string.sub(fullpath, firstColon + 1, firstSlash - 1)


-Then I assign to nwdb metakey and do some checks:
if ip_dstport and not (ip_dstport == nil or ip_dstport == "") then
    nw.createMeta(self.keys["ip.dstport"], tonumber(ip_dstport))


- Type check returns number:


- When I deploy this in SA I get the following:
Invalid registered lua key 'ip.dstport' type specified for parser XXX. Got 'Text' expected 'Uint16'


- table-map.xml:
    <mapping envisionName="dport" nwName="ip.dstport" flags="None" format="UInt16" envisionDisplayName="ForeignPort|DestinationPort" nullTokens="-|(null)|null"/>


While other string based extractions are working in SA fine in same parser. So how do you work with integers in LUA-NWDB setup? Why is it treating number as integer and how to convert from LUA number/string to NWDB UInt16?

I can of course use string based metakeys instead for port extraction, but it would be nice to unify LUA extraction with existing meta model and to put ip.dstport to ip.dstport not to ip.dstport.string or something.

Maybe I can convert string to ip.dstport via some table map or index magic?