forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pub.go
122 lines (97 loc) · 2.46 KB
/
pub.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package cassandra
import (
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/packetbeat/publish"
)
// Transaction Publisher.
type transPub struct {
sendRequest bool
sendResponse bool
sendRequestHeader bool
sendResponseHeader bool
ignoredOps string
results publish.Transactions
}
func (pub *transPub) onTransaction(requ, resp *message) error {
if pub.results == nil {
return nil
}
event := pub.createEvent(requ, resp)
if event != nil {
pub.results.PublishTransaction(event)
}
return nil
}
func (pub *transPub) createEvent(requ, resp *message) common.MapStr {
status := common.OK_STATUS
if resp.failed {
status = common.ERROR_STATUS
}
//ignore
if (resp != nil && resp.ignored) || (requ != nil && requ.ignored) {
return nil
}
event := common.MapStr{
"type": "cassandra",
"status": status,
"cassandra": common.MapStr{},
}
//requ can be null, if the message is a PUSHed message
if requ != nil {
// resp_time in milliseconds
responseTime := int32(resp.Ts.Sub(requ.Ts).Nanoseconds() / 1e6)
src := &common.Endpoint{
IP: requ.Tuple.SrcIP.String(),
Port: requ.Tuple.SrcPort,
Proc: string(requ.CmdlineTuple.Src),
}
event["@timestamp"] = common.Time(requ.Ts)
event["responsetime"] = responseTime
event["bytes_in"] = requ.Size
event["src"] = src
// add processing notes/errors to event
if len(requ.Notes)+len(resp.Notes) > 0 {
event["notes"] = append(requ.Notes, resp.Notes...)
}
if pub.sendRequest {
if pub.sendRequestHeader {
if requ.data == nil {
requ.data = map[string]interface{}{}
}
requ.data["headers"] = requ.header
}
if len(requ.data) > 0 {
event["cassandra"].(common.MapStr)["request"] = requ.data
}
}
dst := &common.Endpoint{
IP: requ.Tuple.DstIP.String(),
Port: requ.Tuple.DstPort,
Proc: string(requ.CmdlineTuple.Dst),
}
event["dst"] = dst
} else {
//dealing with PUSH message
event["no_request"] = true
event["@timestamp"] = common.Time(resp.Ts)
dst := &common.Endpoint{
IP: resp.Tuple.DstIP.String(),
Port: resp.Tuple.DstPort,
Proc: string(resp.CmdlineTuple.Dst),
}
event["dst"] = dst
}
event["bytes_out"] = resp.Size
if pub.sendResponse {
if pub.sendResponseHeader {
if resp.data == nil {
resp.data = map[string]interface{}{}
}
resp.data["headers"] = resp.header
}
if len(resp.data) > 0 {
event["cassandra"].(common.MapStr)["response"] = resp.data
}
}
return event
}