-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathmain.go
58 lines (54 loc) · 1.23 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
package main
import (
"fmt"
"os"
"os/signal"
"rulecat/app"
"rulecat/utils"
"rulecat/utils/kafka"
log2 "rulecat/utils/log"
"sync"
"syscall"
)
func main() {
topic := [...]string{"conn", "ssh", "redis", "mysql", "mongodb", "icmp", "dns", "http"}
outPut := make(chan *sync.Map, 48)
for _, topicItem := range topic {
kafkaC := kafka.InitKakfaConsumer(app.ConfigG.InPut.Kafka.Server, app.ConfigG.InPut.Kafka.GroupId,
[]string{"nids-" + topicItem})
kafkaC.Open()
e := app.NewEngine(topicItem)
e.ReadRules()
for i := 0; i <= 5; i++ {
go func() {
for {
message := <-kafkaC.Message
e.InPutC <- string(message.Value)
}
}()
}
go e.ResCheck(128, outPut)
go func() {
for {
data := <-outPut
sjson, _ := utils.MarshalSMapToJSON(data)
app.SendKafka(sjson)
app.SendEs("nids", "alert", string(sjson))
app.SendMail(data)
app.SendJson(sjson)
}
}()
}
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt, os.Kill, syscall.SIGTERM)
for {
select {
case killSignal := <-interrupt:
fmt.Println("Main app got signal:", killSignal)
if killSignal == os.Interrupt {
err := "Main app was interruped by system signal"
log2.Error.Fatalln(err)
}
}
}
}