-
Notifications
You must be signed in to change notification settings - Fork 148
/
main.go
83 lines (71 loc) · 1.69 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// tool to keep track of messages sent for all deployed apps
// usage: . setup.sh && go run main.go
package main
import (
"crypto/tls"
"fmt"
"log"
"net/http"
"os"
"os/signal"
"time"
"tools/logcounterapp/cflib"
"tools/logcounterapp/config"
"tools/logcounterapp/logcounter"
"github.com/cloudfoundry/noaa/consumer"
)
func init() {
http.DefaultClient.Timeout = 10 * time.Second
http.DefaultClient.Transport = &http.Transport{
TLSHandshakeTimeout: time.Second,
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
}
}
func main() {
cfg, err := config.ParseEnv()
if err != nil {
log.Fatal(err)
}
uaa := &cflib.UAA{
URL: cfg.UaaURL,
Username: cfg.Username,
Password: cfg.Password,
ClientID: cfg.ClientID,
ClientSecret: cfg.ClientSecret,
}
cc := &cflib.CC{
URL: cfg.ApiURL,
}
logcounter := logcounter.New(uaa, cc, cfg)
go func() {
if err := logcounter.Start(); err != nil {
log.Fatal(err)
}
}()
consumer := consumer.New(cfg.DopplerURL, &tls.Config{InsecureSkipVerify: true}, nil)
fmt.Println("===== Streaming Firehose (will only succeed if you have admin credentials)")
// notify on ctrl+c
terminate := make(chan os.Signal, 1)
signal.Notify(terminate, os.Interrupt)
go func() {
for range terminate {
logcounter.Stop()
}
}()
for {
authToken, err := uaa.GetAuthToken()
if err != nil || authToken == "" {
fmt.Fprintf(os.Stderr, "error getting token %s\n", err)
continue
}
fmt.Println("got new oauth token")
msgs, errors := consumer.FirehoseWithoutReconnect(cfg.SubscriptionID, authToken)
go logcounter.HandleMessages(msgs)
done := logcounter.HandleErrors(errors, terminate, consumer)
if done {
return
}
}
}