Files
beelzebub/main.go

83 lines
2.2 KiB
Go
Raw Normal View History

2022-05-08 20:49:53 +02:00
package main
import (
"beelzebub/parser"
"beelzebub/protocols"
"beelzebub/tracer"
2022-05-08 20:49:53 +02:00
log "github.com/sirupsen/logrus"
"io"
"os"
)
var quit = make(chan struct{})
func main() {
configurationsParser := parser.Init("./configurations/beelzebub.yaml", "./configurations/services/")
coreConfigurations, err := configurationsParser.ReadConfigurationsCore()
if err != nil {
log.Fatal(err)
}
fileLogs := configureLogging(coreConfigurations.Core.Logging)
defer fileLogs.Close()
beelzebubServicesConfiguration, err := configurationsParser.ReadConfigurationsServices()
if err != nil {
log.Fatal(err)
}
// Protocol strategies
secureShellStrategy := &protocols.SecureShellStrategy{}
hypertextTransferProtocolStrategy := &protocols.HypertextTransferProtocolStrategy{}
// Protocol manager
serviceManager := protocols.InitProtocolManager(logStrategy, hypertextTransferProtocolStrategy)
2022-05-08 20:49:53 +02:00
for _, beelzebubServiceConfiguration := range beelzebubServicesConfiguration {
switch beelzebubServiceConfiguration.Protocol {
case "http":
serviceManager.SetProtocolStrategy(hypertextTransferProtocolStrategy)
break
case "ssh":
serviceManager.SetProtocolStrategy(secureShellStrategy)
break
default:
log.Fatalf("Protocol %s not managed", beelzebubServiceConfiguration.Protocol)
continue
}
err := serviceManager.InitService(beelzebubServiceConfiguration)
if err != nil {
log.Errorf("Error during init protocol: %s, %s", beelzebubServiceConfiguration.Protocol, err.Error())
}
}
<-quit
}
func logStrategy(event tracer.Event) {
log.WithFields(log.Fields{
"status": event.Status.String(),
"event": event,
}).Info("New Event")
}
2022-05-08 20:49:53 +02:00
func configureLogging(configurations parser.Logging) *os.File {
file, err := os.OpenFile(configurations.LogsPath, os.O_APPEND|os.O_CREATE|os.O_RDWR, 0666)
if err != nil {
log.Fatalf("error opening file: %v", err)
}
log.SetOutput(io.MultiWriter(os.Stdout, file))
2022-05-08 20:49:53 +02:00
log.SetFormatter(&log.JSONFormatter{
DisableTimestamp: configurations.LogDisableTimestamp,
})
log.SetReportCaller(configurations.DebugReportCaller)
if configurations.Debug {
log.SetLevel(log.DebugLevel)
} else {
log.SetLevel(log.InfoLevel)
}
return file
}