-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Update Zeek DNS pipeline with ECS DNS fields #13324
Merged
andrewkroh
merged 6 commits into
elastic:master
from
andrewkroh:feature/fb/zeek-dns-ecs
Aug 27, 2019
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5b6ea8f
Update zeek dns pipeline with ECS DNS fields
andrewkroh be00e38
Update changelog
andrewkroh 6d83da4
Set @timestamp after setting event.created
andrewkroh d2eeb68
Address review comments
andrewkroh ca81c60
Add dns.resolved_ip
andrewkroh d63720d
Fix changelog
andrewkroh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package net | ||
|
||
import ( | ||
"net" | ||
|
||
"github.com/dop251/goja" | ||
"github.com/dop251/goja_nodejs/require" | ||
) | ||
|
||
// Require registers the net module that provides utilities for working with IP | ||
// addresses. It can be accessed using: | ||
// | ||
// // javascript | ||
// var net = require('net'); | ||
// | ||
func Require(vm *goja.Runtime, module *goja.Object) { | ||
o := module.Get("exports").(*goja.Object) | ||
o.Set("isIP", isIP) | ||
o.Set("isIPv4", isIPv4) | ||
o.Set("isIPv6", isIPv6) | ||
} | ||
|
||
func isIP(input string) int32 { | ||
ip := net.ParseIP(input) | ||
if ip == nil { | ||
return 0 | ||
} | ||
|
||
if ip.To4() != nil { | ||
return 4 | ||
} | ||
|
||
return 6 | ||
} | ||
|
||
func isIPv4(input string) bool { | ||
return 4 == isIP(input) | ||
} | ||
|
||
func isIPv6(input string) bool { | ||
return 6 == isIP(input) | ||
} | ||
|
||
// Enable adds net to the given runtime. | ||
func Enable(runtime *goja.Runtime) { | ||
runtime.Set("net", require.Require(runtime, "net")) | ||
} | ||
|
||
func init() { | ||
require.RegisterNativeModule("net", Require) | ||
} |
98 changes: 98 additions & 0 deletions
98
libbeat/processors/script/javascript/module/net/net_test.go
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,98 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package net_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/elastic/beats/libbeat/beat" | ||
"github.com/elastic/beats/libbeat/common" | ||
"github.com/elastic/beats/libbeat/processors/script/javascript" | ||
|
||
_ "github.com/elastic/beats/libbeat/processors/script/javascript/module/net" | ||
_ "github.com/elastic/beats/libbeat/processors/script/javascript/module/require" | ||
) | ||
|
||
func TestNetIsIP(t *testing.T) { | ||
const script = ` | ||
var net = require('net'); | ||
|
||
function process(evt) { | ||
var ip = evt.Get("ip"); | ||
var ipType = net.isIP(ip); | ||
switch (ipType) { | ||
case 4: | ||
evt.Put("network.type", "ipv4"); | ||
break | ||
case 6: | ||
evt.Put("network.type", "ipv6"); | ||
break | ||
} | ||
} | ||
` | ||
|
||
p, err := javascript.NewFromConfig(javascript.Config{Source: script}, nil) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
for ip, typ := range map[string]interface{}{ | ||
"192.168.0.1": "ipv4", | ||
"::ffff:192.168.0.1": "ipv4", | ||
"2001:0db8:0000:0000:0000:ff00:0042:8329": "ipv6", | ||
"2001:db8:0:0:0:ff00:42:8329": "ipv6", | ||
"2001:db8::ff00:42:8329": "ipv6", | ||
"www.elastic.co": nil, | ||
} { | ||
evt, err := p.Run(&beat.Event{Fields: common.MapStr{"ip": ip}}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
fields := evt.Fields.Flatten() | ||
assert.Equal(t, typ, fields["network.type"]) | ||
} | ||
} | ||
|
||
func TestNetIsIPvN(t *testing.T) { | ||
const script = ` | ||
var net = require('net'); | ||
|
||
function process(evt) { | ||
if (net.isIPv4("192.168.0.1") !== true) { | ||
throw "isIPv4 failed"; | ||
} | ||
|
||
if (net.isIPv6("2001:db8::ff00:42:8329") !== true) { | ||
throw "isIPv6 failed"; | ||
} | ||
} | ||
` | ||
|
||
p, err := javascript.NewFromConfig(javascript.Config{Source: script}, nil) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
_, err = p.Run(&beat.Event{Fields: common.MapStr{}}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would hope that doesn't happen, but good check.
But if it does happen, I would suggest appending an error message to that effect to
error.message
instead of just returning.Not a blocker, though. Can also be improved later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'll wait on this. I'd like to find out how common of a condition this will be.