/
httpevent.go
44 lines (37 loc) · 1.01 KB
/
httpevent.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package beater
import (
"github.com/elastic/beats/libbeat/common"
"time"
)
type HttpEvent struct {
ReadTime time.Time
DocumentType string
Fields map[string]string
Request Request
Response Response
}
type Request struct {
Url string `json:"url"`
Method string `json:"method"`
Headers map[string]string `json:"headers,omitempty"`
Body string `json:"body,omitempty"`
}
type Response struct {
StatusCode int `json:"code"`
StatusPhrase string `json:"phrase"`
Headers map[string]string `json:"headers,omitempty"`
Body string `json:"body,omitempty"`
JsonBody map[string]interface{} `json:"jsonBody,omitempty"`
}
func (h *HttpEvent) ToMapStr() common.MapStr {
event := common.MapStr{
"@timestamp": common.Time(h.ReadTime),
"type": h.DocumentType,
"request": h.Request,
"response": h.Response,
}
if h.Fields != nil {
event["fields"] = h.Fields
}
return event
}