-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added input filter for device detection and parsing of userAgent head…
…ers for web logs
- Loading branch information
1 parent
38b87d7
commit 6a44fb3
Showing
4 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Global options | ||
options: | ||
includeOriginalLine: false | ||
printStats: 10 | ||
maxInputRate: 1mb # per second | ||
|
||
input: | ||
stdin: true | ||
files: | ||
- '/var/log/**/*.log' | ||
|
||
inputFilter: | ||
- module: httpDeviceDetector | ||
# optional setting to configure the field name for the useragent | ||
# will default to 'useragent' if this config is omitted | ||
# config: | ||
# userAgentFieldName: useragent | ||
|
||
output: | ||
# stdout: yaml | ||
sematext-logs: | ||
module: elasticsearch | ||
url: https://logsene-receiver.sematext.com | ||
index: LOGS_TOKEN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const DeviceDetector = require('device-detector-js') | ||
const deviceDetector = new DeviceDetector() | ||
var safeStringify = require('fast-safe-stringify') | ||
function jsonParse (text) { | ||
try { | ||
return JSON.parse(text) | ||
} catch (err) { | ||
return null | ||
} | ||
} | ||
|
||
module.exports = function (context, config, data, callback) { | ||
try { | ||
const userAgentFieldName = config.userAgentFieldName || 'useragent' | ||
const parsedData = jsonParse(data) | ||
const useragent = parsedData[userAgentFieldName] | ||
|
||
const device = deviceDetector.parse(useragent) | ||
const dataWithUseragentDetails = { ...device, ...parsedData } | ||
|
||
return callback(null, safeStringify(dataWithUseragentDetails)) | ||
} catch (err) { | ||
return callback(null, data) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters