Skip to content

Commit

Permalink
Generate data for inbound and outbound connections too
Browse files Browse the repository at this point in the history
  • Loading branch information
jsoriano committed Jan 28, 2019
1 parent 5c31194 commit 5027a5b
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 10 deletions.
12 changes: 6 additions & 6 deletions metricbeat/module/system/socket/_meta/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@
},
"process": {
"args": [
"/tmp/go-build122914279/b001/socket.test",
"/tmp/go-build701928973/b001/socket.test",
"-data"
],
"executable": "/tmp/go-build122914279/b001/socket.test",
"executable": "/tmp/go-build701928973/b001/socket.test",
"name": "socket.test",
"pid": 20595
"pid": 9578
},
"server": {
"ip": "::",
"port": 32915
"port": 42573
},
"service": {
"type": "system"
Expand All @@ -37,10 +37,10 @@
"socket": {
"local": {
"ip": "::",
"port": 32915
"port": 42573
},
"process": {
"cmdline": "/tmp/go-build122914279/b001/socket.test -data"
"cmdline": "/tmp/go-build701928973/b001/socket.test -data"
}
}
},
Expand Down
46 changes: 46 additions & 0 deletions metricbeat/module/system/socket/_meta/data_inbound.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"@timestamp": "2017-10-12T08:05:34.853Z",
"agent": {
"hostname": "host.example.com",
"name": "host.example.com"
},
"event": {
"dataset": "system.socket",
"duration": 115000,
"module": "system"
},
"metricset": {
"name": "socket"
},
"network": {
"direction": "inbound",
"iana_number": "41",
"type": "ipv6"
},
"process": {
"pid": -1
},
"server": {
"ip": "::1",
"port": 42573
},
"service": {
"type": "system"
},
"system": {
"socket": {
"local": {
"ip": "::1",
"port": 42573
},
"remote": {
"ip": "::1",
"port": 37854
}
}
},
"user": {
"full_name": "root",
"id": "0"
}
}
46 changes: 46 additions & 0 deletions metricbeat/module/system/socket/_meta/data_outbound.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"@timestamp": "2017-10-12T08:05:34.853Z",
"agent": {
"hostname": "host.example.com",
"name": "host.example.com"
},
"event": {
"dataset": "system.socket",
"duration": 115000,
"module": "system"
},
"metricset": {
"name": "socket"
},
"network": {
"direction": "outbound",
"iana_number": "41",
"type": "ipv6"
},
"process": {
"pid": -1
},
"server": {
"ip": "::1",
"port": 37858
},
"service": {
"type": "system"
},
"system": {
"socket": {
"local": {
"ip": "::1",
"port": 37858
},
"remote": {
"ip": "::1",
"port": 42573
}
}
},
"user": {
"full_name": "root",
"id": "0"
}
}
37 changes: 33 additions & 4 deletions metricbeat/module/system/socket/socket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package socket

import (
"fmt"
"net"
"os"
"strconv"
Expand All @@ -31,20 +32,48 @@ import (
"github.com/stretchr/testify/require"

"github.com/elastic/beats/libbeat/common"
sock "github.com/elastic/beats/metricbeat/helper/socket"
mbtest "github.com/elastic/beats/metricbeat/mb/testing"
)

func TestData(t *testing.T) {
directionIs := func(direction string) func(e common.MapStr) bool {
return func(e common.MapStr) bool {
v, err := e.GetValue("network.direction")
return err == nil && v == direction
}
}

dataFiles := []struct {
direction string
path string
}{
{sock.ListeningName, "."},
{sock.InboundName, "./_meta/data_inbound.json"},
{sock.OutboundName, "./_meta/data_outbound.json"},
}

f := mbtest.NewReportingMetricSetV2(t, getConfig())

ln, err := net.Listen("tcp", ":0")
if err != nil {
t.Fatal(err)
}
defer ln.Close()

f := mbtest.NewReportingMetricSetV2(t, getConfig())
err = mbtest.WriteEventsReporterV2(f, t, ".")
if err != nil {
t.Fatal("write", err)
for _, df := range dataFiles {
c, err := net.Dial("tcp", ln.Addr().String())
if err != nil {
t.Fatal(err)
}
c.Close()

t.Run(fmt.Sprintf("direction:%s", df.direction), func(t *testing.T) {
err = mbtest.WriteEventsReporterV2Cond(f, t, df.path, directionIs(df.direction))
if err != nil {
t.Fatal("write", err)
}
})
}
}

Expand Down

0 comments on commit 5027a5b

Please sign in to comment.