styx/main.go
Christopher Talib f61fe566a5 Basic connection to Dgraph DB
The first work and input to the graph db is set up in this work. It's
for the moment very basic and doesn't cover relations and only works for
certstream data.
2020-03-04 15:16:59 +01:00

83 lines
1.5 KiB
Go

package main
import (
"os"
"sync"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
"gitlab.dcso.lolcat/LABS/styx/graph"
"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"))
logrus.Info("Starting to get data from the Internet...")
// The false flag specifies that we want heartbeat messages.
// conn, err := broker.SetUpKafkaConnecter()
// if err != nil {
// panic(err)
// }
dgraphClient, err := graph.ConnectToDgraph()
if err != nil {
logrus.WithField("err", err).Error("error initialising the graph database")
}
// stop channel
stopChan := make(chan os.Signal)
var wg sync.WaitGroup
// go broker.ReadEventFromKafka()
// certstream
c := plugins.CertStreamPlugin{}
if ok := c.Initialize(); !ok {
logrus.Info("certstream plugin not activated")
}
c.Run(&wg, dgraphClient)
// pastebin
p := plugins.PastebinPlugin{}
if ok := p.Initialize(); !ok {
logrus.Info("pastebin plugin not activated")
}
p.Run(&wg)
// shodan
s := plugins.ShodanPlugin{}
if ok := s.Initialize(); !ok {
logrus.Info("shodan plugin not activated")
}
p.Run(&wg)
go func() {
<-stopChan
logrus.Info("Shutting down...")
c.Stop(&wg)
p.Stop(&wg)
s.Stop(&wg)
}()
wg.Wait()
logrus.Info("done")
}