Files
beelzebub/main.go
Bryan Nolen d677cd20b9 Feature: Enhance Performance, Logging & Stability: Precompile Regex, Command Matching, Golang 1.24, History Cleanup & memLimitMiB Flag. (#182)
* Feat: Add support for logging which "command" was matched for SSH and HTTP strategies.

* Feat: Convert to precompiling regexp at config load time. This allows for errors to be presented to the user during startup, and provides better performance for complex regexp.

* Feat:Bump Golang version to latest stable 1.24

* Feat: Add a cleanup routine for HistoryStore, default TTL for events is 1 hour since last interaction.

* Feat: Add new command line flag "memLimitMiB" with a default value of 100.

---------

Signed-off-by: Bryan Nolen <bryan@arc.net.au>
Signed-off-by: Mario Candela <mario.candela.personal@gmail.com>
Co-authored-by: Mario Candela <mario.candela.personal@gmail.com>
2025-03-23 19:16:34 +01:00

60 lines
1.7 KiB
Go

package main
import (
"flag"
"runtime/debug"
"github.com/mariocandela/beelzebub/v3/builder"
"github.com/mariocandela/beelzebub/v3/parser"
log "github.com/sirupsen/logrus"
)
func main() {
var (
quit = make(chan struct{})
configurationsCorePath string
configurationsServicesDirectory string
memLimitMiB int
)
flag.StringVar(&configurationsCorePath, "confCore", "./configurations/beelzebub.yaml", "Provide the path of configurations core")
flag.StringVar(&configurationsServicesDirectory, "confServices", "./configurations/services/", "Directory config services")
flag.IntVar(&memLimitMiB, "memLimitMiB", 100, "Process Memory in MiB (default 100, set to -1 to use system default)")
flag.Parse()
if memLimitMiB > 0 {
// SetMemoryLimit takes an int64 value for the number of bytes.
// bytes value = MiB value * 1024 * 1024
debug.SetMemoryLimit(int64(memLimitMiB * 1024 * 1024))
}
parser := parser.Init(configurationsCorePath, configurationsServicesDirectory)
coreConfigurations, err := parser.ReadConfigurationsCore()
failOnError(err, "Error during ReadConfigurationsCore: ")
beelzebubServicesConfiguration, err := parser.ReadConfigurationsServices()
failOnError(err, "Error during ReadConfigurationsServices: ")
beelzebubBuilder := builder.NewBuilder()
director := builder.NewDirector(beelzebubBuilder)
beelzebubBuilder, err = director.BuildBeelzebub(coreConfigurations, beelzebubServicesConfiguration)
failOnError(err, "Error during BuildBeelzebub: ")
err = beelzebubBuilder.Run()
failOnError(err, "Error during run beelzebub core: ")
defer beelzebubBuilder.Close()
<-quit
}
func failOnError(err error, msg string) {
if err != nil {
log.Fatalf("%s: %s", msg, err)
}
}