-
Notifications
You must be signed in to change notification settings - Fork 8
/
output.go
59 lines (48 loc) · 1.4 KB
/
output.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
package main
import (
"fmt"
"strconv"
)
type output interface {
PrintHeader()
PrintLine(eventPayload)
}
func newOutput(printAll bool) output {
return newTableOutput(printAll)
}
type tableOutput struct {
printAll bool
}
func (t tableOutput) PrintHeader() {
var header string
var args []interface{}
if t.printAll {
header = "%-9s %-9s %-6s %-42s %-16s %-20s %s\n"
args = []interface{}{"TIME", "AF", "PID", "PROCESS", "USER", "DESTINATION", "AS-INFO"}
} else {
header = "%-9s %-9s %-6s %-34s %-16s %-20s\n"
args = []interface{}{"TIME", "AF", "PID", "PROCESS", "USER", "DESTINATION"}
}
fmt.Printf(header, args...)
}
func (t tableOutput) PrintLine(e eventPayload) {
time := e.GoTime.Format("15:04:05")
dest := e.DestIP.String() + " " + strconv.Itoa(int(e.DestPort))
var header string
var args []interface{}
if t.printAll {
var asText = ""
if (ASNameInfo{}) != e.ASNameInfo {
asText = "AS" + strconv.Itoa(int(e.ASNameInfo.AsNumber)) + " (" + e.ASNameInfo.Name + ")"
}
header = "%-9s %-9s %-6d %-42s %-16s %-20s %s\n"
args = []interface{}{time, e.AddressFamily, e.Pid, e.ProcessPath + " " + e.ProcessArgs, e.User, dest, asText}
} else {
header = "%-9s %-9s %-6d %-34s %-16s %-20s\n"
args = []interface{}{time, e.AddressFamily, e.Pid, e.ProcessPath, e.User, dest}
}
fmt.Printf(header, args...)
}
func newTableOutput(includeAsNumbers bool) output {
return &tableOutput{includeAsNumbers}
}