Skip to content

Commit

Permalink
added dedicated user agent details field name
Browse files Browse the repository at this point in the history
  • Loading branch information
adnanrahic committed Apr 3, 2020
1 parent 87c77c9 commit f01c0d2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 6 additions & 3 deletions config/examples/file-input-filter-useragent-es-output.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion lib/plugins/output-filter/httpDeviceDetector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f01c0d2

Please sign in to comment.