Added support for wildcards and mac
This commit is contained in:
1 parent
f58c5604c2
commit
eb92d35b51
2 files changed
+43
-5
No files matched your search
+39
-1
@@ -2,6 +2,28 @@ config = require './config'
|
|||||||
common = require './common'
|
common = require './common'
|
||||||
|
|
||||||
|
|
||||||
|
stringToRegexp = (input) ->
|
||||||
|
if (input.indexOf('*') == -1)
|
||||||
|
return false
|
||||||
|
|
||||||
|
output = input.replace(/[\[\]\\\^\$\.\|\?\+\(\)]/, "\\$&")
|
||||||
|
if output[0] == '*'
|
||||||
|
prefix = '/'
|
||||||
|
output = output.replace(/^\*+/g, '')
|
||||||
|
else
|
||||||
|
prefix = '/^'
|
||||||
|
|
||||||
|
if output[output.length - 1] == '*'
|
||||||
|
suffix = '/'
|
||||||
|
output = output.replace(/\*+$/g, '')
|
||||||
|
else
|
||||||
|
suffix = '$/'
|
||||||
|
|
||||||
|
output = output.replace(/[\*]/, '.*')
|
||||||
|
|
||||||
|
return eval(prefix + output + suffix)
|
||||||
|
|
||||||
|
|
||||||
normalizers = {}
|
normalizers = {}
|
||||||
|
|
||||||
normalizers.default = (input, normType) ->
|
normalizers.default = (input, normType) ->
|
||||||
@@ -20,6 +42,11 @@ normalizers.default = (input, normType) ->
|
|||||||
d = new Date(input)
|
d = new Date(input)
|
||||||
if input.length >= 8 and d.getFullYear() > 1983
|
if input.length >= 8 and d.getFullYear() > 1983
|
||||||
vals.push(d)
|
vals.push(d)
|
||||||
|
|
||||||
|
r = stringToRegexp(input)
|
||||||
|
if r isnt false
|
||||||
|
vals.push({'$regex' : r})
|
||||||
|
|
||||||
return vals
|
return vals
|
||||||
return input
|
return input
|
||||||
|
|
||||||
@@ -44,8 +71,19 @@ normalizers.string = (input, normType) ->
|
|||||||
input
|
input
|
||||||
|
|
||||||
|
|
||||||
|
normalizers.mac = (input, normType) ->
|
||||||
|
if normType isnt 'query'
|
||||||
|
return input
|
||||||
|
|
||||||
|
input = input.toUpperCase().replace(/[^0-9A-F]/g, '')
|
||||||
|
if input.length == 12
|
||||||
|
return input.substring(2).replace(/[0-9A-F]{2}(?!$)/g, '$&:')
|
||||||
|
|
||||||
|
return {'$regex' : eval('/' + input.replace(/[0-9A-F]{1}(?!$)/g, '$&:?') + '/')}
|
||||||
|
|
||||||
|
|
||||||
exports.normalize = (path, value, normType) ->
|
exports.normalize = (path, value, normType) ->
|
||||||
if path of config.PARAMETERS and config.PARAMETERS[path].type?
|
if path of config.PARAMETERS and config.PARAMETERS[path].type?
|
||||||
return normalizers[config.PARAMETERS[path].type](value)
|
return normalizers[config.PARAMETERS[path].type](value, normType)
|
||||||
else
|
else
|
||||||
return normalizers['default'](value, normType)
|
return normalizers['default'](value, normType)
|
||||||
+4
-4
@@ -6,12 +6,12 @@
|
|||||||
"InternetGatewayDevice.DeviceInfo.ManufacturerOUI" : {"alias" : "summary.oui"},
|
"InternetGatewayDevice.DeviceInfo.ManufacturerOUI" : {"alias" : "summary.oui"},
|
||||||
"InternetGatewayDevice.DeviceInfo.HardwareVersion" : {"alias" : "summary.hardwareVersion"},
|
"InternetGatewayDevice.DeviceInfo.HardwareVersion" : {"alias" : "summary.hardwareVersion"},
|
||||||
"InternetGatewayDevice.DeviceInfo.SoftwareVersion" : {"alias" : "summary.softwareVersion"},
|
"InternetGatewayDevice.DeviceInfo.SoftwareVersion" : {"alias" : "summary.softwareVersion"},
|
||||||
"InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.MACAddress" : {"alias" : "summary.mac"},
|
"InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.MACAddress" : {"alias" : "summary.mac", "type" : "mac"},
|
||||||
"InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.ExternalIPAddress" : {"alias" : "summary.ip"},
|
"InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.ExternalIPAddress" : {"alias" : "summary.ip"},
|
||||||
|
|
||||||
"InternetGatewayDevice.WiMAX.Status.BSID" : {"alias" : "summary.bsid"},
|
"InternetGatewayDevice.WiMAX.Status.BSID" : {"alias" : "summary.bsid", "type" : "mac"},
|
||||||
"InternetGatewayDevice.X_CommunicationsInc_WiMAX_device_metrics.ServingBSID" : {"alias" : "summary.bsid"},
|
"InternetGatewayDevice.X_CommunicationsInc_WiMAX_device_metrics.ServingBSID" : {"alias" : "summary.bsid", "type" : "mac"},
|
||||||
"InternetGatewayDevice.WANDevice.1.WiMAXInterfaceConfig.RadioModule.ServBSID" : {"alias" : "summary.bsid"},
|
"InternetGatewayDevice.WANDevice.1.WiMAXInterfaceConfig.RadioModule.ServBSID" : {"alias" : "summary.bsid", "type" : "mac"},
|
||||||
|
|
||||||
"InternetGatewayDevice.WiMAX.Status.RSSI" : {"alias" : "summary.rssi", "type" : "float"},
|
"InternetGatewayDevice.WiMAX.Status.RSSI" : {"alias" : "summary.rssi", "type" : "float"},
|
||||||
"InternetGatewayDevice.X_MTK_WiMAX_Param.RSSI_level" : {"alias" : "summary.rssi", "type" : "float"},
|
"InternetGatewayDevice.X_MTK_WiMAX_Param.RSSI_level" : {"alias" : "summary.rssi", "type" : "float"},
|
||||||
|
|||||||
Reference in new issue
Block a user