-
-
Notifications
You must be signed in to change notification settings - Fork 482
/
csv.go
50 lines (43 loc) · 966 Bytes
/
csv.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
package formats
import (
"fmt"
"github.com/evilsocket/opensnitch/daemon/ui/protocol"
)
// CSV name of the output format, used in json configs
const CSV = "csv"
// Csv object
type Csv struct {
}
// NewCSV returns a new CSV transformer object.
func NewCSV() *Csv {
return &Csv{}
}
// Transform takes input arguments and formats them to CSV.
func (c *Csv) Transform(args ...interface{}) (out string) {
p := args[0]
values := p.([]interface{})
for _, val := range values {
switch val.(type) {
case *protocol.Connection:
con := val.(*protocol.Connection)
out = fmt.Sprint(out,
con.SrcIp, ",",
con.SrcPort, ",",
con.DstIp, ",",
con.DstHost, ",",
con.DstPort, ",",
con.Protocol, ",",
con.ProcessId, ",",
con.UserId, ",",
//con.ProcessComm, ",",
con.ProcessPath, ",",
con.ProcessArgs, ",",
con.ProcessCwd, ",",
)
default:
out = fmt.Sprint(out, val, ",")
}
}
out = out[:len(out)-1]
return
}