From 93de7df71f8583e964a416ef12c3425962e6f669 Mon Sep 17 00:00:00 2001 From: Corbin Phelps Date: Wed, 27 Apr 2022 09:00:25 -0400 Subject: [PATCH] feat(plugin): Added Mongodb log plugin (#374) * Added mongodb plugin Signed-off-by: Corbin Phelps * Added multiple logging paths to mongo Signed-off-by: Corbin Phelps * Fixedup mondb plugin Signed-off-by: Corbin Phelps * Added example log line to mongodb plugin Signed-off-by: Corbin Phelps --- plugins/mongodb_logs.yaml | 136 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 plugins/mongodb_logs.yaml diff --git a/plugins/mongodb_logs.yaml b/plugins/mongodb_logs.yaml new file mode 100644 index 000000000..ec8eb6098 --- /dev/null +++ b/plugins/mongodb_logs.yaml @@ -0,0 +1,136 @@ +version: 0.0.1 +title: MongoDB +description: Log parser for MongoDB +parameters: + - name: log_paths + type: "[]string" + default: + - "/var/log/mongodb/mongodb.log*" + - "/var/log/mongodb/mongod.log*" + - name: start_at + type: string + supported: + - beginning + - end + default: end +template: | + receivers: + filelog: + include: + {{ range $fp := .log_paths }} + - '{{ $fp }}' + {{end}} + exclude: + {{ range $fp := .log_paths }} + - '{{ $fp }}*.gz' + {{end}} + start_at: {{ .start_at }} + operators: + - type: router + default: legacy_parser + routes: + - expr: 'body matches "^{.*}$|^{.*}\\n$"' + output: 4_4_parser + + - id: legacy_parser + type: regex_parser + regex: '^(?P\S+)\s+(?P\w+)\s+(?P[\w-]+)\s+\[(?P\S+)\]\s+(?P.*)$' + timestamp: + parse_from: attributes.timestamp + #2019-02-06T09:22:43.967-0500 + layout: '%Y-%m-%dT%H:%M:%S.%f%z' + severity: + parse_from: attributes.severity + mapping: + fatal: F + error: E + warn: W + info: I + debug: + - D + - D1 + - D2 + - D3 + - D4 + - D5 + output: add_log_type + + # Example log line: + # {"t":{"$date":"2022-04-26T16:15:44.876+00:00"},"s":"I", "c":"INDEX", "id":20345, "ctx":"LogicalSessionCacheRefresh","msg":"Index build: done building","attr":{"buildUUID":null,"namespace":"config.system.sessions","index":"lsidTTLIndex","commitTimestamp":null}} + - id: 4_4_parser + type: json_parser + parse_from: body + timestamp: + parse_from: attributes.t.$date + #2020-11-03T14:24:07.436-05:00 + layout: '%Y-%m-%dT%H:%M:%S.%f%j' + severity: + parse_from: attributes.s + mapping: + fatal: F + error: E + warn: W + info: I + debug: + - D + - D1 + - D2 + - D3 + - D4 + - D5 + output: move_component + # Commented out remove operatore out and output until remove operator is added in. + # Tracking in PR https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/9545 + #output: remove_t + + + # - id: remove_t + # type: remove + # field: attributes.t + + - id: move_component + type: move + from: attributes.c + to: attributes.component + + - id: move_context + type: move + from: attributes.ctx + to: attributes.context + + - id: move_message + type: move + from: attributes.msg + to: attributes.message + + # When message is 'WiredTiger message', data.attr.message + # always exists, and should be promoted to message + - id: wiredtiger_router + type: router + default: add_log_type + routes: + - expr: 'attributes.message == "WiredTiger message"' + output: move_wiredtiger_type + + - id: move_wiredtiger_type + type: move + from: attributes.message + to: attributes.message_type + output: move_wiredtiger_msg + + - id: move_wiredtiger_msg + type: move + from: attributes.attr.message + to: attributes.message + output: add_log_type + + - id: add_log_type + type: add + field: 'attributes.log_type' + value: 'mongodb' + + service: + pipelines: + logs: + receivers: + - filelog