-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #258 from sematext/sc-9544-journald-fix
- Loading branch information
Showing
7 changed files
with
118 additions
and
33 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
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 |
---|---|---|
@@ -1,30 +1,62 @@ | ||
options: | ||
# print stats every 60 seconds | ||
printStats: 60 | ||
# Enable/disable GeoIP lookups | ||
geoipEnabled: false | ||
# Directory to store Logagent status and temporary files | ||
# this is equals to LOGS_TMP_DIR env variable | ||
diskBufferDir: /tmp/sematext-logagent | ||
debug: true | ||
suppress: false | ||
|
||
input: | ||
journald-json: | ||
journald-json: | ||
module: command | ||
# note journalctl -u unitName can filter logs for systemd-units | ||
command: journalctl -o json --since="$QUERY_TIME" | ||
sourceName: journald | ||
|
||
# date format for replacing $QUERY_TIME and $NOW | ||
# the following works for journalctl, the default is ISO 8601 | ||
dateFormat: YYYY-MM-DD HH:mm:ss | ||
|
||
dateFormat: YYYY-MM-DD HH:mm:ss # date format for $QUERY_TIME and $NOW | ||
restart: 1 # seconds to wait between runs | ||
# where to persist last $QUERY_TIME | ||
# defaults to os.tmpdir()+'logagentLastQueryTimeFile' | ||
# lastQueryTimeFile: /tmp/logagentLastQueryTimeFile | ||
lastQueryTimeFile: /var/run/logagentLastQueryTimeFile | ||
|
||
# value for $QUERY_TIME if nothing was persisted. Default below | ||
# initialQueryTime: "2001-01-01 00:00:00" | ||
# pull logs from one week ago initially | ||
initialQueryTime: "$ONE_WEEK_AGO" | ||
# 100MB pipe buffer | ||
maxBuffer: 100000000 | ||
|
||
# memory for the pipe between the command and Logagent | ||
# it should fit the maximum size of the command's stdout/stderr | ||
# size in bytes. Default below | ||
# maxBuffer: 50000000 | ||
# here we parse journald logs and remove extra fields | ||
outputFilter: | ||
journald-format: | ||
module: journald-format | ||
# Run Logagent parser for the message field | ||
parseMessageField: true | ||
|
||
# after finishing the command, wait for N seconds then run it again | ||
restart: 1 | ||
lowercase-fields: | ||
module: lowercase-fields # this fliter only lowercases root fields, not nested fields | ||
# JS regular expression to match log source name | ||
matchSource: !!js/regexp .* | ||
allFields: true # this will lowercase all root fields | ||
# fields: | ||
# - fieldName: SELINUX_CONTEXT # this will lowercase only certain root fields, this is an array and you can specify multiple fields | ||
|
||
removeFields: | ||
module: remove-fields | ||
# JS regular expression to match log source name | ||
matchSource: !!js/regexp .* | ||
# Note: journald format converts to lower case | ||
fields: | ||
- __cursor | ||
- __monotonic_timestamp | ||
- _transport | ||
|
||
output: | ||
es-local: | ||
stdout: yaml | ||
|
||
# index logs in Elasticsearch or Sematext Logs | ||
elasticsearch: | ||
module: elasticsearch | ||
url: http://localhost:9200 | ||
index: journald_logs | ||
url: url | ||
# default index (Logs token) to use: | ||
index: 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,16 @@ | ||
outputFilter: | ||
lowercase-fields: | ||
module: lowercase-fields | ||
# JS regular expression to match log source name | ||
matchSource: !!js/regexp .* | ||
allFields: true # this will lowercase all fields | ||
fields: | ||
- fieldName: SELINUX_CONTEXT # this will lowercase only certain fields, this is an array and you can specify multiple fields | ||
|
||
# Exmple, input: | ||
# {"USER": "{ name: root }", "SELINUX_CONTEXT": "unconfined", "message": "Client connect: root", "originalLine": "INFO Client connect: root"} | ||
# Example, output | ||
# {"user": "{ name: root }", "selinux_context": "unconfined", "message": "Client connect: root", "originalLine": "INFO Client connect: root"} | ||
|
||
# Note: | ||
# This filter will only lowercase root fields, not any nested field names! |
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,43 @@ | ||
const get = require('get-value') | ||
const unset = require('unset-value') | ||
const set = require('set-value') | ||
|
||
function renameFields (context, config, eventEmitter, data, callback) { | ||
if (data === undefined) { | ||
return callback(new Error('data is null'), null) | ||
} | ||
if (config.allFields !== true) { | ||
config.allFields = false | ||
} | ||
|
||
try { | ||
if (!config.matchSource.test(context.sourceName || data.logSource)) { | ||
return callback(null, data) | ||
} | ||
|
||
if (config.allFields === true) { | ||
const fields = Object.keys(data) | ||
fields.forEach(field => { | ||
const lowerCaseField = field.toLowerCase() | ||
const fieldValue = get(data, field) | ||
unset(data, field) | ||
set(data, lowerCaseField, fieldValue) | ||
}) | ||
return callback(null, data) | ||
} | ||
|
||
const fields = config.fields | ||
fields.forEach(field => { | ||
const { fieldName } = field | ||
const lowerCaseField = fieldName.toLowerCase() | ||
const fieldValue = get(data, fieldName) | ||
unset(data, fieldName) | ||
set(data, lowerCaseField, fieldValue) | ||
}) | ||
|
||
callback(null, data) | ||
} catch (ex) { | ||
callback(ex, null) | ||
} | ||
} | ||
module.exports = renameFields |
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