diff --git a/configs/go/fileshot/fileshot.yaml b/configs/go/fileshot/fileshot.yaml index ef17c2c7..238c743a 100644 --- a/configs/go/fileshot/fileshot.yaml +++ b/configs/go/fileshot/fileshot.yaml @@ -1,3 +1,5 @@ +version: + 2023-10-03 client: 'go-fileshot-default' conn: server: 'localhost:57314' diff --git a/src/go/cmd/strelka-fileshot/main.go b/src/go/cmd/strelka-fileshot/main.go index 3486a943..85383f50 100644 --- a/src/go/cmd/strelka-fileshot/main.go +++ b/src/go/cmd/strelka-fileshot/main.go @@ -37,8 +37,8 @@ type matchRich struct { func main() { // Declare flags - confPath := flag.String("c", "/etc/strelka/fileshot.yaml", "Path to fileshot configuration file.") - hashPath := flag.String("e", "", "Path to MD5 exclusions list.") + configPath := flag.String("c", "/etc/strelka/fileshot.yaml", "Path to fileshot configuration file.") + hashPath := flag.String("e", "", "Path to hash exclusions list.") verbose := flag.Bool("v", false, "Enables additional error logging.") cpuProf := flag.Bool("cpu", false, "Enables cpu profiling.") heapProf := flag.Bool("heap", false, "Enables heap profiling.") @@ -61,11 +61,21 @@ func main() { } // Read configuration file - confData, err := os.ReadFile(*confPath) + confData, err := os.ReadFile(*configPath) if err != nil { - log.Fatalf("failed to read config file %s: %v", *confPath, err) + log.Fatalf("failed to read config file %s: %v", *configPath, err) } + // Try to recover absolute config file path + absConfigPath, _ := filepath.Abs(*configPath) + if absConfigPath == "" { + absConfigPath = *configPath + } + + // Create a new config hash + configHasher := md5.New() + configHasher.Write([]byte(confData)) + // Unmarshal configuration data into struct var conf structs.FileShot err = yaml.Unmarshal(confData, &conf) @@ -105,6 +115,12 @@ func main() { } + if conf.Version != "" { + log.Printf("Loaded config file v%s %s %s", conf.Version, fmt.Sprintf("%x", configHasher.Sum(nil)), absConfigPath) + } else { + log.Printf("Loaded config file %s %s", fmt.Sprintf("%x", configHasher.Sum(nil)), absConfigPath) + } + // Create a slice to hold the lines of the file hashes := make([]string, 0) diff --git a/src/go/pkg/structs/structs.go b/src/go/pkg/structs/structs.go index bdf54cf7..a037fee3 100644 --- a/src/go/pkg/structs/structs.go +++ b/src/go/pkg/structs/structs.go @@ -96,6 +96,7 @@ type ConfResponse struct { // defines structures of configuration files type FileShot struct { + Version string // optional Client string // optional Conn ConfConn // required Throughput ConfThroughput // required