Skip to content

Commit

Permalink
input-journald-upload: use removeFields from config
Browse files Browse the repository at this point in the history
  • Loading branch information
mikolasan committed Jul 2, 2021
1 parent af1661e commit 6aadf20
Showing 1 changed file with 12 additions and 25 deletions.
37 changes: 12 additions & 25 deletions lib/plugins/input/journald-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ const keyValueFieldRegex = /^\S+=.+$/ // key=value
const cursorRegex = /^__CURSOR=/
// const exportRecordRegex = /^(\S+)=(.+)$|^(\S+)$\n$\n([\S|\s]+)\n$/gm
class Parser {
constructor (emitEvent, token) {
constructor (emitEvent, token, removeFields) {
this.token = token
this.emitEvent = emitEvent
this.removeFields = removeFields
this.multiLineMode = false
this.log = {}
this.multiLineFieldValue = ''
Expand Down Expand Up @@ -46,7 +47,7 @@ class Parser {
if (!isNaN(value)) {
value = Number(value)
}
if (fieldName.length > 0) {
if (fieldName.length > 0 && !this.removeFields[fieldName]) {
this.log[fieldName] = value
}
}
Expand Down Expand Up @@ -175,17 +176,19 @@ JournaldUpload.prototype.emitEvent = function (log, token) {
if (
config.systemdUnitFilter !== undefined &&
config.systemdUnitFilter.include &&
!config.systemdUnitFilter.include.test(log._SYSTEMD_UNIT)
!config.systemdUnitFilter.include.test(systemdUnit)
) {
return
}
if (
config.systemdUnitFilter !== undefined &&
config.systemdUnitFilter.exclude &&
config.systemdUnitFilter.exclude.test(log._SYSTEMD_UNIT)
config.systemdUnitFilter.exclude.test(systemdUnit)
) {
return
}
} else {
// ignore messages not from systemd
}
const context = {
sourceName: log[_SYSTEMD_UNIT] || log[SYSLOG_IDENTIFIER] || 'journald',
Expand Down Expand Up @@ -239,30 +242,14 @@ JournaldUpload.prototype.getHttpServer = function (aport, handler) {
}
}

JournaldUpload.prototype.parseLine = function (log, line) {
if (!line) {
return log
}
const index = line.indexOf('=')
const fieldName = line.substr(0, index).toLowerCase()
let value = line.substr(index + 1, line.length)
if (!isNaN(value)) {
value = Number(value)
}
if (!this.removeFields[fieldName]) {
log[fieldName] = value
}
return log
}

JournaldUpload.prototype.journaldHttpHandler = function (req, res) {
try {
this.config.useIndexFromUrlPath = true
const self = this
const path = req.url.split('/')
let token = null

if (self.config.useIndexFromUrlPath === true && path.length > 1) {
if (this.config.useIndexFromUrlPath === true && path.length > 1) {
if (path[1] && path[1].length > 31 && tokenFormatRegEx.test(path[1])) {
const match = path[1].match(extractTokenRegEx)
if (match && match.length > 1) {
Expand All @@ -276,15 +263,15 @@ JournaldUpload.prototype.journaldHttpHandler = function (req, res) {
}

if (
(self.config.useIndexFromUrlPath === true && !token) ||
self.tokenBlackList.isTokenInvalid(token)
(this.config.useIndexFromUrlPath === true && !token) ||
this.tokenBlackList.isTokenInvalid(token)
) {
res.statusCode = self.config.invalidTokenStatus || 403
res.statusCode = this.config.invalidTokenStatus || 403
res.end(`invalid logs token in url ${req.url}\n`)
return
}

const parserState = new Parser(self.emitEvent.bind(self), token)
const parserState = new Parser(this.emitEvent.bind(this), token, this.removeFields)
req
.pipe(createStreamThrottle(this.throughputPerClient))
.pipe(split())
Expand Down

0 comments on commit 6aadf20

Please sign in to comment.