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:
Bryan Nolen
2025-03-24 05:16:34 +11:00
committed by GitHub
parent 16b012784c
commit d677cd20b9
14 changed files with 249 additions and 89 deletions

View File

@ -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 {