Skip to content

Commit 7fbda4a

Browse files
legoguy1000mergify-bot
authored andcommitted
[Packetbeat] Add url.extension to Packetbeat HTTP events (#25999)
* #25990: Add `url.extension` to Packetbeat HTTP events * update changelog * add tests * updated per comment (cherry picked from commit 3d341a8)
1 parent 3c9c96a commit 7fbda4a

3 files changed

Lines changed: 70 additions & 0 deletions

File tree

CHANGELOG.next.asciidoc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,19 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
658658
*Packetbeat*
659659

660660

661+
- Add an example to packetbeat.yml of using the `forwarded` tag to disable
662+
`host` metadata fields when processing network data from network tap or mirror
663+
port. {pull}19209[19209]
664+
- Add ECS fields for x509 certs, event categorization, and related IP info. {pull}19167[19167]
665+
- Add 100-continue support {issue}15830[15830] {pull}19349[19349]
666+
- Add initial SIP protocol support {pull}21221[21221]
667+
- Add support for overriding the published index on a per-protocol/flow basis. {pull}22134[22134]
668+
- Change build process for x-pack distribution {pull}21979[21979]
669+
- Tuned the internal queue size to reduce the chances of events being dropped. {pull}22650[22650]
670+
- Add support for "http.request.mime_type" and "http.response.mime_type". {pull}22940[22940]
671+
- Upgrade to ECS 1.8.0. {pull}23783[23783]
672+
- Add `event.type: [connection]` to flow events and include `end` for final flows. {pull}24564[24564]
673+
- Add `url.extension` to HTTP events {issue}25990[25990] {pull}25999[25999]
661674

662675
*Functionbeat*
663676

packetbeat/protos/http/event.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ func newURL(host string, port int64, path, query string) *ecs.Url {
9090
if port != 80 {
9191
u.Port = port
9292
}
93+
if path != "" {
94+
periodIndex := strings.LastIndex(path, ".")
95+
if periodIndex != -1 && periodIndex < len(path) {
96+
u.Extension = path[(periodIndex + 1):]
97+
}
98+
}
9399
u.Full = synthesizeFullURL(u, port)
94100
return u
95101
}

packetbeat/protos/http/http_test.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,6 +1845,57 @@ func TestHttpParser_hostHeader(t *testing.T) {
18451845
}
18461846
}
18471847

1848+
func TestHttpParser_Extension(t *testing.T) {
1849+
template := "HEAD %s HTTP/1.1\r\n" +
1850+
"Host: abc.com\r\n" +
1851+
"\r\n"
1852+
var store eventStore
1853+
http := httpModForTests(&store)
1854+
for _, test := range []struct {
1855+
title, path string
1856+
expected common.MapStr
1857+
}{
1858+
{
1859+
title: "Zip Extension",
1860+
path: "/files.zip",
1861+
expected: common.MapStr{
1862+
"url.full": "http://abc.com/files.zip",
1863+
"url.extension": "zip",
1864+
},
1865+
},
1866+
{
1867+
title: "No Extension",
1868+
path: "/files",
1869+
expected: common.MapStr{
1870+
"url.full": "http://abc.com/files",
1871+
"url.extension": nil,
1872+
},
1873+
},
1874+
} {
1875+
t.Run(test.title, func(t *testing.T) {
1876+
request := fmt.Sprintf(template, test.path)
1877+
tcptuple := testCreateTCPTuple()
1878+
packet := protos.Packet{Payload: []byte(request)}
1879+
private := protos.ProtocolData(&httpConnectionData{})
1880+
private = http.Parse(&packet, tcptuple, 1, private)
1881+
http.Expired(tcptuple, private)
1882+
trans := expectTransaction(t, &store)
1883+
if !assert.NotNil(t, trans) {
1884+
t.Fatal("nil transaction")
1885+
}
1886+
for field, expected := range test.expected {
1887+
actual, err := trans.GetValue(field)
1888+
assert.Equal(t, expected, actual, field)
1889+
if expected != nil {
1890+
assert.Nil(t, err, field)
1891+
} else {
1892+
assert.Equal(t, common.ErrKeyNotFound, err, field)
1893+
}
1894+
}
1895+
})
1896+
}
1897+
}
1898+
18481899
func benchmarkHTTPMessage(b *testing.B, data []byte) {
18491900
http := httpModForTests(nil)
18501901
parser := newParser(&http.parserConfig)

0 commit comments

Comments
 (0)