Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

googlecloud/vpcflow fileset: Populate additional log fields #14608

Merged
merged 2 commits into from
Nov 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions filebeat/docs/modules/googlecloud.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Example config:
var.topic: googlecloud-vpc-flowlogs
var.subscription_name: filebeat-googlecloud-vpc-flowlogs-sub
var.credentials_file: ${path.config}/gcp-service-account-xyz.json
var.keep_original_message: false
----

include::../include/var-paths.asciidoc[]
Expand All @@ -61,6 +62,11 @@ exist it will be created.

Path to a JSON file containing the credentials and key used to subscribe.

*`var.keep_original_message`*::

Flag to control whether the original message is stored in the `log.original`
field. Defaults to `false`, meaning the original message is not saved.

:fileset_ex!:

:fileset_ex: firewall
Expand Down
6 changes: 6 additions & 0 deletions x-pack/filebeat/module/googlecloud/_meta/docs.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Example config:
var.topic: googlecloud-vpc-flowlogs
var.subscription_name: filebeat-googlecloud-vpc-flowlogs-sub
var.credentials_file: ${path.config}/gcp-service-account-xyz.json
var.keep_original_message: false
----

include::../include/var-paths.asciidoc[]
Expand All @@ -56,6 +57,11 @@ exist it will be created.

Path to a JSON file containing the credentials and key used to subscribe.

*`var.keep_original_message`*::

Flag to control whether the original message is stored in the `log.original`
field. Defaults to `false`, meaning the original message is not saved.

:fileset_ex!:

:fileset_ex: firewall
Expand Down
2 changes: 2 additions & 0 deletions x-pack/filebeat/module/googlecloud/vpcflow/config/input.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ processors:
lang: javascript
id: googlecloud_vpcflow_script
file: ${path.home}/module/googlecloud/vpcflow/config/pipeline.js
params:
keep_original_message: {{ .keep_original_message }}
31 changes: 29 additions & 2 deletions x-pack/filebeat/module/googlecloud/vpcflow/config/pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

var vpcflow = (function () {
function VPCFlow(keep_original_message) {
var processor = require("processor");

// The pub/sub input writes the Stackdriver LogEntry object into the message
Expand All @@ -21,6 +21,16 @@ var vpcflow = (function () {
ignore_missing: true,
});

var saveOriginalMessage = function(evt) {};
if (keep_original_message) {
saveOriginalMessage = new processor.Convert({
fields: [
{from: "message", to: "event.original"}
],
mode: "rename"
});
}

var dropPubSubFields = function(evt) {
evt.Delete("message");
evt.Delete("labels");
Expand All @@ -34,6 +44,14 @@ var vpcflow = (function () {
},
});


var saveMetadata = new processor.Convert({
fields: [
{from: "json.logName", to: "log.logger"},
],
ignore_missing: true
});

// Use the LogEntry object's timestamp. VPC flow logs are structured so the
// LogEntry includes a jsonPayload field.
// https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry
Expand Down Expand Up @@ -205,8 +223,10 @@ var vpcflow = (function () {
var pipeline = new processor.Chain()
.Add(decodeJson)
.Add(parseTimestamp)
.Add(saveOriginalMessage)
.Add(dropPubSubFields)
.Add(categorizeEvent)
.Add(saveMetadata)
.Add(convertLogEntry)
.Add(convertJsonPayload)
.Add(dropEmptyObjects)
Expand All @@ -223,7 +243,14 @@ var vpcflow = (function () {
return {
process: pipeline.Run,
};
})();
}

var vpcflow;

// Register params from configuration.
function register(params) {
vpcflow = new VPCFlow(params.keep_original_message);
}

function process(evt) {
return vpcflow.process(evt);
Expand Down
3 changes: 2 additions & 1 deletion x-pack/filebeat/module/googlecloud/vpcflow/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ var:
default: filebeat-googlecloud-vpcflow
- name: credentials_file
default: googlecloud-vpcflow-reader-service-identity.json

- name: keep_original_message
default: false
ingest_pipeline: ingest/pipeline.yml
input: config/input.yml

Expand Down
Loading