forked from ntop/libebpfflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ebpflowexport.go
49 lines (41 loc) · 1.1 KB
/
ebpflowexport.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
package main
import (
ebpf_flow "./go"
"os"
"syscall"
"os/signal"
"fmt"
)
var gRUNNING bool = true
func main () {
// Open ebpflow
ebpf := ebpf_flow.NewEbpflow(event_handler, 0)
fmt.Println("Initialzed")
// Handle interruption
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
<-c
gRUNNING = false
}()
// Poll events
for gRUNNING == true {
ebpf.PollEvent(10)
}
// Clean resources
ebpf.Close()
}
func event_handler (event ebpf_flow.EBPFevent) {
fmt.Printf("[pid:%d][etype:%d][%s][task:%s][path:%s]",
event.Proc.Pid, event.EType, event.Ifname,
event.Proc.Task, event.Proc.Full_Task_Path)
fmt.Printf("[%s:%d <-> %s:%d]",
event.Saddr.String(), event.Sport, event.Daddr.String(), event.Dport)
if (event.Docker != nil) {
fmt.Printf("[container_id: %s][name: %s]", event.Container_id[:16], event.Docker.Name)
} else if (event.Kube != nil) {
fmt.Printf("[container_id: %s][name: %s][ns: %s][pod: %s]",
event.Container_id[:16], event.Kube.Name, event.Kube.Ns, event.Kube.Pod)
}
fmt.Printf("\n")
}