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

Parse also the port from log sources #9460

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha1...master[Check the HEAD d
- Fix installation of haproxy dashboard. {issue}9307[9307] {pull}9313[9313]
- Don't generate incomplete configurations when logs collection is disabled by hints. {pull}9305[9305]
- Stop runners disabled by hints after previously being started. {pull}9305[9305]
- Use a separate field for source port on network inputs. {pull}9460[9460]

*Heartbeat*

Expand Down
2 changes: 1 addition & 1 deletion dev-tools/ecs-migration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
alias: true

- from: source
to: ["log.file.path", "log.source.ip"]
to: ["log.file.path", "log.source.ip", "log.source.port"]
alias: false

- from: beat.name
Expand Down
6 changes: 6 additions & 0 deletions filebeat/_meta/fields.common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
description: >
Source IP from which the log event was read / sent from.

- name: log.source.port
type: long
required: false
description: >
Source port from which the log event was read / sent from.

- name: log.offset
type: long
required: false
Expand Down
12 changes: 12 additions & 0 deletions filebeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -4709,6 +4709,18 @@ required: False
Source IP from which the log event was read / sent from.


--

*`log.source.port`*::
+
--
type: long

required: False

Source port from which the log event was read / sent from.


--

*`log.offset`*::
Expand Down
2 changes: 1 addition & 1 deletion filebeat/include/fields.go

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion filebeat/input/syslog/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package syslog

import (
"net"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -201,14 +202,18 @@ func (p *Input) Wait() {
}

func createEvent(ev *event, metadata inputsource.NetworkMetadata, timezone *time.Location, log *logp.Logger) *beat.Event {
remoteHost, remotePort, _ := net.SplitHostPort(metadata.RemoteAddr.String())
f := common.MapStr{
"message": strings.TrimRight(ev.Message(), "\n"),
"log": common.MapStr{
"source": common.MapStr{
"ip": metadata.RemoteAddr.String(),
"ip": remoteHost,
},
},
}
if remotePort != "" {
f.Put("log.source.port", remotePort)
}

syslog := common.MapStr{}
event := common.MapStr{}
Expand Down
7 changes: 6 additions & 1 deletion filebeat/input/tcp/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package tcp

import (
"fmt"
"net"
"sync"
"time"

Expand Down Expand Up @@ -126,17 +127,21 @@ func (p *Input) Wait() {
}

func createEvent(raw []byte, metadata inputsource.NetworkMetadata) *util.Data {
remoteHost, remotePort, _ := net.SplitHostPort(metadata.RemoteAddr.String())
data := util.NewData()
data.Event = beat.Event{
Timestamp: time.Now(),
Fields: common.MapStr{
"message": string(raw),
"log": common.MapStr{
"source": common.MapStr{
"ip": metadata.RemoteAddr.String(),
"ip": remoteHost,
},
},
},
}
if remotePort != "" {
data.Event.Fields.Put("log.source.port", remotePort)
}
return data
}
7 changes: 6 additions & 1 deletion filebeat/input/udp/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package udp

import (
"net"
"sync"
"time"

Expand Down Expand Up @@ -66,6 +67,7 @@ func NewInput(

forwarder := harvester.NewForwarder(out)
callback := func(data []byte, metadata inputsource.NetworkMetadata) {
remoteHost, remotePort, _ := net.SplitHostPort(metadata.RemoteAddr.String())
e := util.NewData()
e.Event = beat.Event{
Timestamp: time.Now(),
Expand All @@ -76,11 +78,14 @@ func NewInput(
"message": string(data),
"log": common.MapStr{
"source": common.MapStr{
"ip": metadata.RemoteAddr.String(),
"ip": remoteHost,
},
},
},
}
if remotePort != "" {
e.Event.Fields.Put("log.source.port", remotePort)
}
forwarder.Send(e)
}

Expand Down