-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker.go
51 lines (43 loc) · 933 Bytes
/
worker.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
package certmon
import (
"github.com/labstack/echo"
"time"
)
func Worker(config Config, storage Store, count *Counter, l echo.Logger) {
stream, errs := CertStreamEventStream(config)
ticker := time.NewTicker(60 * time.Second)
quit := make(chan struct{})
for {
select {
case <-quit:
ticker.Stop()
return
case entry := <-stream:
count.Increment("consumed")
yes, err := storage.IsMonitored(&entry)
if err != nil {
continue
}
if yes {
match := &Match{entry, ""}
count.Increment("matched")
l.Debug("Found match ", entry.Data.LeafCert.AllDomains)
b, err := json.Marshal(entry)
match.EntryString = string(b)
storage.Record(*match)
if err != nil {
count.Increment("json_error")
}
/*
for _, n := range notifiers {
n.Notify(*match)
}
*/
}
case <-errs:
count.Increment("stream_errors")
case <-ticker.C:
l.Info(count)
}
}
}