diff --git a/config/examples/file-input-filter-useragent-es-output.yml b/config/examples/file-input-filter-useragent-es-output.yml index 82c40866..273241b5 100644 --- a/config/examples/file-input-filter-useragent-es-output.yml +++ b/config/examples/file-input-filter-useragent-es-output.yml @@ -7,15 +7,18 @@ options: input: stdin: true files: - - '/var/log/**/*.log' + - '/var/log/**/*.log' outputFilter: httpDeviceDetector: module: httpDeviceDetector - # optional setting to configure the field name for the useragent - # will default to 'user_agent' if this config is omitted + # optional setting to configure the field name for the + # user agent and the user agent details + # userAgentFieldName will default to 'user_agent' if this config is omitted + # userAgentDetailsFieldName will default to 'user_agent_details' if this config is omitted # config: # userAgentFieldName: user_agent + # userAgentDetailsFieldName: user_agent_details output: # stdout: yaml diff --git a/lib/plugins/output-filter/httpDeviceDetector.js b/lib/plugins/output-filter/httpDeviceDetector.js index 2b30fc51..5cacdcca 100644 --- a/lib/plugins/output-filter/httpDeviceDetector.js +++ b/lib/plugins/output-filter/httpDeviceDetector.js @@ -4,10 +4,12 @@ const deviceDetector = new DeviceDetector() module.exports = function (context, config, eventEmitter, log, callback) { try { const userAgentFieldName = config.userAgentFieldName || 'user_agent' + const userAgentDetailsFieldName = config.userAgentDetailsFieldName || 'user_agent_details' + const userAgent = log[userAgentFieldName] const device = deviceDetector.parse(userAgent) - const logWithUserAgentDetails = { ...device, ...log } + const logWithUserAgentDetails = { [userAgentDetailsFieldName]: device, ...log } return callback(null, logWithUserAgentDetails) } catch (err) { return callback(null, log)