styx/main.go
Christopher Talib b1ca4b3c5f Shodan in Dgraph, first part
Implementing first version for shodan node, missing yet some models, but
the overal approach works and can be queried in Ratel.
2020-05-18 16:09:04 +02:00

86 lines
1.6 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")
} else {
c.Run(&wg, dgraphClient)
}
// pastebin
p := plugins.PastebinPlugin{}
if ok := p.Initialize(); !ok {
logrus.Info("pastebin plugin not activated")
} else {
p.Run(&wg)
}
// shodan
s := plugins.ShodanPlugin{}
if ok := s.Initialize(); !ok {
logrus.Info("shodan plugin not activated")
} else {
s.Run(&wg, dgraphClient)
}
go func() {
<-stopChan
logrus.Info("Shutting down...")
c.Stop(&wg)
p.Stop(&wg)
s.Stop(&wg)
}()
wg.Wait()
logrus.Info("done")
}