Skip to content

Commit 47c0c72

Browse files
authored
Do not overwrite content type if it is multipart in Kibana loader (#27424)
## What does this PR do? This PR fixes dashboard loading. Kibana loader overwrites every content type to application/json. However, for multipart file transfer it has to be set to multipart/formdata and application/ndjson. Otherwise, loading the assets fails. Also, a module file has not been updated with new dashboard names.
1 parent feac0a9 commit 47c0c72

3 files changed

Lines changed: 37 additions & 8 deletions

File tree

libbeat/kibana/client.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"fmt"
2525
"io"
2626
"io/ioutil"
27+
"mime"
2728
"mime/multipart"
2829
"net/http"
2930
"net/textproto"
@@ -214,6 +215,7 @@ func (conn *Connection) SendWithContext(ctx context.Context, method, extraPath s
214215
addHeaders(req.Header, headers)
215216

216217
contentType := req.Header.Get("Content-Type")
218+
contentType, _, _ = mime.ParseMediaType(contentType)
217219
if contentType != "multipart/form-data" && contentType != "application/ndjson" {
218220
req.Header.Set("Content-Type", "application/json")
219221
}

libbeat/kibana/client_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,30 @@ headers:
119119
assert.Equal(t, []string{"1"}, requests[1].Header.Values("kbn-xsrf"))
120120

121121
}
122+
123+
func TestNewKibanaClientWithMultipartData(t *testing.T) {
124+
var requests []*http.Request
125+
kibanaTs := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
126+
requests = append(requests, r)
127+
if r.URL.Path == "/api/status" {
128+
w.Write([]byte(`{"version":{"number":"1.2.3-beta","build_snapshot":true}}`))
129+
}
130+
}))
131+
defer kibanaTs.Close()
132+
133+
client, err := NewKibanaClient(common.MustNewConfigFrom(fmt.Sprintf(`
134+
protocol: http
135+
host: %s
136+
headers:
137+
content-type: multipart/form-data; boundary=46bea21be603a2c2ea6f51571a5e1baf5ea3be8ebd7101199320607b36ff
138+
accept: text/plain
139+
kbn-xsrf: 0
140+
`, kibanaTs.Listener.Addr().String())))
141+
require.NoError(t, err)
142+
require.NotNil(t, client)
143+
144+
client.Request(http.MethodPost, "/foo", url.Values{}, http.Header{"key": []string{"another_value"}}, nil)
145+
146+
assert.Equal(t, []string{"multipart/form-data; boundary=46bea21be603a2c2ea6f51571a5e1baf5ea3be8ebd7101199320607b36ff"}, requests[1].Header.Values("Content-Type"))
147+
148+
}

x-pack/filebeat/module/netflow/dashboards.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@
22

33
dashboards:
44
- id: 77326664-23be-4bf1-a126-6d7e60cfc024
5-
file: filebeat-netflow-geo-location.json
5+
file: filebeat-netflow-geo-location.ndjson
66

77
- id: 38012abe-c611-4124-8497-381fcd85acc8
8-
file: filebeat-netflow-traffic-analysis.json
8+
file: filebeat-netflow-traffic-analysis.ndjson
99

1010
- id: c64665f9-d222-421e-90b0-c7310d944b8a
11-
file: filebeat-netflow-autonomous-systems.json
11+
file: filebeat-netflow-autonomous-systems.ndjson
1212

1313
- id: acd7a630-0c71-4840-bc9e-4a3801374a32
14-
file: filebeat-netflow-conversation-partners.json
14+
file: filebeat-netflow-conversation-partners.ndjson
1515

1616
- id: 34e26884-161a-4448-9556-43b5bf2f62a2
17-
file: filebeat-netflow-overview.json
17+
file: filebeat-netflow-overview.ndjson
1818

1919
- id: feebb4e6-b13e-4e4e-b9fc-d3a178276425
20-
file: filebeat-netflow-flow-exporters.json
20+
file: filebeat-netflow-flow-exporters.ndjson
2121

2222
- id: 94972700-de4a-4272-9143-2fa8d4981365
23-
file: filebeat-netflow-flow-records.json
23+
file: filebeat-netflow-flow-records.ndjson
2424

2525
- id: 14387a13-53bc-43a4-b9cd-63977aa8d87c
26-
file: filebeat-netflow-top-n.json
26+
file: filebeat-netflow-top-n.ndjson

0 commit comments

Comments
 (0)