styx/main.go

100 lines
1.9 KiB
Go
Raw Normal View History

package main
import (
"os"
"sync"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
"gitlab.dcso.lolcat/LABS/styx/broker"
2020-03-02 17:06:28 +01:00
"gitlab.dcso.lolcat/LABS/styx/graph"
"gitlab.dcso.lolcat/LABS/styx/matcher"
2020-02-25 10:05:31 +01:00
"gitlab.dcso.lolcat/LABS/styx/plugins"
)
func init() {
// Setting up logging.
logrus.SetFormatter(&logrus.TextFormatter{
FullTimestamp: true,
})
logrus.SetReportCaller(true)
viper.SetConfigName("config")
viper.SetConfigType("yaml")
viper.AddConfigPath(".")
}
func main() {
err := viper.ReadInConfig()
if err != nil {
panic(err)
}
os.Setenv("SHODAN_KEY", viper.GetString("shodan.key"))
2020-03-02 17:06:28 +01:00
logrus.Info("Starting to get data from the Internet...")
logrus.Info("Initializing Kafka...")
_, err = broker.SetUpKafkaConnecter()
if err != nil {
logrus.WithField("err", err).Error("error initialising kafka")
}
logrus.Info("done")
logrus.Info("Initializing Dgraph...")
dgraphClient, err := graph.ConnectToDgraph()
if err != nil {
logrus.WithField("err", err).Error("error initialising the graph database")
}
logrus.Info("done")
// stop channel
stopChan := make(chan os.Signal)
var wg sync.WaitGroup
2020-02-25 10:05:31 +01:00
// go broker.ReadEventFromKafka()
2020-02-04 10:35:18 +01:00
// certstream
2020-02-25 10:05:31 +01:00
c := plugins.CertStreamPlugin{}
if ok := c.Initialize(); !ok {
2020-03-02 17:06:28 +01:00
logrus.Info("certstream plugin not activated")
2020-03-19 09:27:15 +01:00
} else {
c.Run(&wg, dgraphClient)
}
// pastebin
2020-02-25 10:05:31 +01:00
p := plugins.PastebinPlugin{}
if ok := p.Initialize(); !ok {
2020-03-02 17:06:28 +01:00
logrus.Info("pastebin plugin not activated")
2020-03-19 09:27:15 +01:00
} else {
p.Run(&wg, dgraphClient)
}
// shodan
2020-02-25 10:05:31 +01:00
s := plugins.ShodanPlugin{}
if ok := s.Initialize(); !ok {
logrus.Info("shodan plugin not activated")
2020-03-19 09:27:15 +01:00
} else {
s.Run(&wg, dgraphClient)
}
// main matcher
m := matcher.Matcher{}
if ok := m.Initialize(); !ok {
logrus.Info("matcher is not activated")
} else {
m.Run(&wg, dgraphClient)
}
2020-02-25 10:05:31 +01:00
go func() {
<-stopChan
2020-03-02 17:06:28 +01:00
logrus.Info("Shutting down...")
2020-02-25 10:05:31 +01:00
c.Stop(&wg)
p.Stop(&wg)
s.Stop(&wg)
m.Stop(&wg)
2020-02-25 10:05:31 +01:00
}()
wg.Wait()
2020-03-02 17:06:28 +01:00
logrus.Info("done")
}