-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmain.go
66 lines (50 loc) · 1.17 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
package main
import (
"context"
"fmt"
"github.com/go-routeros/routeros/v3"
"github.com/rs/zerolog/log"
"golang.org/x/sync/errgroup"
csbouncer "github.com/crowdsecurity/go-cs-bouncer"
)
type mikrotikAddrList struct {
c *routeros.Client
cache map[string]string
}
func main() {
// zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
initConfig()
bouncer := &csbouncer.StreamBouncer{
APIKey: crowdsecBouncerAPIKey,
APIUrl: crowdsecBouncerURL,
TickerInterval: "5s",
Origins: crowdsecOrigins,
}
if err := bouncer.Init(); err != nil {
log.Fatal().Err(err).Msg("Bouncer init failed")
}
var mal mikrotikAddrList
mal.initMikrotik()
defer mal.c.Close()
g, ctx := errgroup.WithContext(context.Background())
g.Go(func() error {
bouncer.Run(ctx)
return fmt.Errorf("bouncer stream halted")
})
g.Go(func() error {
log.Printf("Processing new and deleted decisions . . .")
for {
select {
case <-ctx.Done():
log.Error().Msg("terminating bouncer process")
return nil
case decisions := <-bouncer.Stream:
mal.decisionProcess(decisions)
}
}
})
err := g.Wait()
if err != nil {
log.Error().Err(err).Send()
}
}