forked from jessfraz/junk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
61 lines (52 loc) · 1.19 KB
/
main.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
package main
import (
"fmt"
"log"
"os"
"os/signal"
"sync"
"syscall"
"time"
"github.com/google/gopacket/pcap"
"github.com/jessfraz/junk/paws/totessafe/reflector"
)
var (
wg sync.WaitGroup
)
func main() {
ticker := time.NewTicker(30 * time.Second)
// On ^C, or SIGTERM handle exit.
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
signal.Notify(c, syscall.SIGTERM)
go func() {
for sig := range c {
ticker.Stop()
fmt.Printf("Received %s, exiting.\n", sig.String())
os.Exit(0)
}
}()
// Create our client to totessafe.
client := reflector.NewInternalReflectorClient("totessafe.contained.af", 14410)
if err := client.Connect(); err != nil {
log.Fatalf("creating client to totessafe failed: %v", err)
}
// Process network packets.
// Find all devices.
devices, err := pcap.FindAllDevs()
if err != nil {
log.Fatal(err)
}
// Iterate over the devices and watch for packets.
for _, device := range devices {
wg.Add(1)
go watchDevice(client, device)
}
// Get information from the /proc filesystem for the processes.
go func(t *time.Ticker, client *reflector.InternalReflectorClient) {
for range t.C {
getProcInfo(client)
}
}(ticker, client)
wg.Wait()
}