mirror of
https://github.com/mariocandela/beelzebub.git
synced 2025-07-01 18:47:26 -04:00
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>
This commit is contained in:
@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
@ -76,11 +77,13 @@ type BeelzebubServiceConfiguration struct {
|
||||
|
||||
// Command is the struct that contains the configurations of the commands
|
||||
type Command struct {
|
||||
Regex string `yaml:"regex"`
|
||||
Handler string `yaml:"handler"`
|
||||
Headers []string `yaml:"headers"`
|
||||
StatusCode int `yaml:"statusCode"`
|
||||
Plugin string `yaml:"plugin"`
|
||||
RegexStr string `yaml:"regex"`
|
||||
Regex *regexp.Regexp `yaml:"-"` // This field is parsed, not stored in the config itself.
|
||||
Handler string `yaml:"handler"`
|
||||
Headers []string `yaml:"headers"`
|
||||
StatusCode int `yaml:"statusCode"`
|
||||
Plugin string `yaml:"plugin"`
|
||||
Name string `yaml:"name"`
|
||||
}
|
||||
|
||||
type configurationsParser struct {
|
||||
@ -140,12 +143,29 @@ func (bp configurationsParser) ReadConfigurationsServices() ([]BeelzebubServiceC
|
||||
return nil, fmt.Errorf("in file %s: %v", filePath, err)
|
||||
}
|
||||
log.Debug(beelzebubServiceConfiguration)
|
||||
if err := beelzebubServiceConfiguration.CompileCommandRegex(); err != nil {
|
||||
return nil, fmt.Errorf("in file %s: invalid regex: %v", filePath, err)
|
||||
}
|
||||
servicesConfiguration = append(servicesConfiguration, *beelzebubServiceConfiguration)
|
||||
}
|
||||
|
||||
return servicesConfiguration, nil
|
||||
}
|
||||
|
||||
// CompileCommandRegex is the method that compiles the regular expression for each configured Command.
|
||||
func (c *BeelzebubServiceConfiguration) CompileCommandRegex() error {
|
||||
for i, command := range c.Commands {
|
||||
if command.RegexStr != "" {
|
||||
rex, err := regexp.Compile(command.RegexStr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c.Commands[i].Regex = rex
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func gelAllFilesNameByDirName(dirName string) ([]string, error) {
|
||||
files, err := os.ReadDir(dirName)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user