From 6474851c5ca3e001e15bc341aa2db8cd19343c87 Mon Sep 17 00:00:00 2001 From: Ahmet Ozturk Date: Fri, 17 Jul 2026 15:21:59 +0200 Subject: [PATCH 1/5] check_files: remove all directories when a pattern is used previously the files would be selectively added matching the pattern with their filenames, and directories which did not contain any of those files were removed from entryList now remove all directories completely when pattern is used --- pkg/snclient/check_files.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/pkg/snclient/check_files.go b/pkg/snclient/check_files.go index 1e354b11..2b576a49 100644 --- a/pkg/snclient/check_files.go +++ b/pkg/snclient/check_files.go @@ -168,7 +168,9 @@ func (l *CheckFiles) Check(_ context.Context, _ *Agent, check *CheckData, _ []Ar // Cleanup the listData if a filter is used if l.pattern != "*" { - l.removeDirectoriesWithoutFilesUnder(check) + // l.removeDirectoriesWithoutFilesUnder(check) + + l.removeDirectories(check) } if l.calculateSubdirectorySizes { @@ -558,6 +560,18 @@ func checkSlowFileOperations(check *CheckData, entry map[string]string, path str return nil } +func (l *CheckFiles) removeDirectories(check *CheckData) { + newListData := make([]map[string]string, 0) + + for _, data := range check.listData { + if data["type"] != "dir" { + newListData = append(newListData, data) + } + } + + check.listData = newListData +} + // The WalkDir normally adds every directory and files under the search path. // If a pattern is specified, this prevents files that dont match the pattern to be skipped. // This can lead to some directories being in the listData, while not having any matched files under them. From 6e97b01f0586b8e3895ef131d566f69905150189 Mon Sep 17 00:00:00 2001 From: Ahmet Oeztuerk Date: Fri, 17 Jul 2026 16:08:28 +0200 Subject: [PATCH 2/5] check_files: make patterns apply to the directory names previously, pattersns only applied to file names. afterwards, directories that did not contain any matching files were removed now, the patterns apply directly to the directories as well. no futher processing for directories are done --- pkg/snclient/check_files.go | 28 ++++++++++++++++------------ pkg/snclient/check_files_test.go | 18 ++++++++++++++---- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/pkg/snclient/check_files.go b/pkg/snclient/check_files.go index 2b576a49..8136fa12 100644 --- a/pkg/snclient/check_files.go +++ b/pkg/snclient/check_files.go @@ -166,12 +166,7 @@ func (l *CheckFiles) Check(_ context.Context, _ *Agent, check *CheckData, _ []Ar } } - // Cleanup the listData if a filter is used - if l.pattern != "*" { - // l.removeDirectoriesWithoutFilesUnder(check) - - l.removeDirectories(check) - } + l.removeDirectoriesThatDontMatchPattern(check) if l.calculateSubdirectorySizes { l.addSubdirectorySizes(check) @@ -560,22 +555,31 @@ func checkSlowFileOperations(check *CheckData, entry map[string]string, path str return nil } -func (l *CheckFiles) removeDirectories(check *CheckData) { - newListData := make([]map[string]string, 0) +func (l *CheckFiles) removeDirectoriesThatDontMatchPattern(check *CheckData) { + if l.pattern == "*" { + return + } + + newListdata := make([]map[string]string, 0) for _, data := range check.listData { - if data["type"] != "dir" { - newListData = append(newListData, data) + if data["type"] == "dir" { + if match, _ := filepath.Match(l.pattern, data["filename"]); !match { + continue + } } + newListdata = append(newListdata, data) } - check.listData = newListData + check.listData = newListdata } // The WalkDir normally adds every directory and files under the search path. -// If a pattern is specified, this prevents files that dont match the pattern to be skipped. +// If a pattern/filter is specified, this prevents files that dont match the pattern/filter to be skipped. // This can lead to some directories being in the listData, while not having any matched files under them. // This function cleans those directories up. +// +//nolint:unused // this function was called if pattern was specified, in previous versions. still keeping it for possible future use with filters. func (l *CheckFiles) removeDirectoriesWithoutFilesUnder(check *CheckData) { fileFilepaths := make([]string, 0) diff --git a/pkg/snclient/check_files_test.go b/pkg/snclient/check_files_test.go index 223c5fed..2bc5939d 100644 --- a/pkg/snclient/check_files_test.go +++ b/pkg/snclient/check_files_test.go @@ -493,7 +493,7 @@ func TestCheckFilesSizePerfdata(t *testing.T) { // The second pass should remove the "a" folder where files with "a" extension is found res = snc.RunCheck("check_files", []string{"path=" + geneartionDirectory, "pattern=*.b", "crit='size > 100MiB'"}) outputString = string(res.BuildPluginOutput()) - assert.Containsf(t, outputString, "OK - All 6 files are ok", "output matches") + assert.Containsf(t, outputString, "OK - All 5 files are ok", "output matches") res = snc.RunCheck("check_files", []string{"path=" + geneartionDirectory, "pattern=*.b", "crit='size > 100MiB'", "filter=' type == file'"}) outputString = string(res.BuildPluginOutput()) assert.Containsf(t, outputString, "OK - All 5 files are ok", "output matches") @@ -517,9 +517,19 @@ func TestCheckFilesSizePerfdata(t *testing.T) { // When using a pattern and calculate subdirectory sizes is enabled, it will add the subdirectory sizes as metrics res = snc.RunCheck("check_files", []string{"path=" + geneartionDirectory, "pattern=*_3.*", "crit='size > 0Mib'", "calculate-subdirectory-sizes=true"}) outputString = string(res.BuildPluginOutput()) - assert.Containsf(t, outputString, "CRITICAL - 6/6 files (3.50 MiB) critical", "output matches") - assert.Containsf(t, outputString, "'a size'=1048576B", "should calculate the size of the subfolder a") - assert.Containsf(t, outputString, "'b size'=1048576B", "should calculate the size of the subfolder b") + assert.Containsf(t, outputString, "CRITICAL - 4/4 files (3.50 MiB) critical", "output matches") + assert.NotContainsf(t, outputString, "'a size'=1048576B", "should calculate the size of the subfolder a, as it does not match pattern") + assert.NotContainsf(t, outputString, "'b size'=1048576B", "should calculate the size of the subfolder b, as it does not match pattern") + + // only matches the directory "a" itself + res = snc.RunCheck("check_files", []string{"path=" + geneartionDirectory, "pattern=a"}) + outputString = string(res.BuildPluginOutput()) + assert.Containsf(t, outputString, "OK - All 1 files are ok: (0 B)", "output matches") + + // matches the four files inside directory "a": file_1024kb_1.a , file_1024kb_2.a , file_1024kb_3.a , file_1024kb_4.a + res = snc.RunCheck("check_files", []string{"path=" + geneartionDirectory, "pattern=*.a"}) + outputString = string(res.BuildPluginOutput()) + assert.Containsf(t, outputString, "OK - All 4 files are ok: (4.00 MiB)", "output matches") StopTestAgent(t, snc) } From a1224fa2799e055f42f38e95552c4ce6d980beee Mon Sep 17 00:00:00 2001 From: Ahmet Oeztuerk Date: Mon, 20 Jul 2026 13:52:56 +0200 Subject: [PATCH 3/5] check_files: remove unused function removeDirectoriesWithoutFilesUnder --- pkg/snclient/check_files.go | 43 ------------------------------------- 1 file changed, 43 deletions(-) diff --git a/pkg/snclient/check_files.go b/pkg/snclient/check_files.go index 8136fa12..48de83fd 100644 --- a/pkg/snclient/check_files.go +++ b/pkg/snclient/check_files.go @@ -574,49 +574,6 @@ func (l *CheckFiles) removeDirectoriesThatDontMatchPattern(check *CheckData) { check.listData = newListdata } -// The WalkDir normally adds every directory and files under the search path. -// If a pattern/filter is specified, this prevents files that dont match the pattern/filter to be skipped. -// This can lead to some directories being in the listData, while not having any matched files under them. -// This function cleans those directories up. -// -//nolint:unused // this function was called if pattern was specified, in previous versions. still keeping it for possible future use with filters. -func (l *CheckFiles) removeDirectoriesWithoutFilesUnder(check *CheckData) { - fileFilepaths := make([]string, 0) - - for _, data := range check.listData { - if data["type"] == "file" { - fileFilepaths = append(fileFilepaths, data["fullname"]) - } - } - - newListData := make([]map[string]string, 0) - - for _, data := range check.listData { - // only filter the directories, files are automatically added - if data["type"] == "dir" { - hasFilesUnder := false - for _, fileFilepath := range fileFilepaths { - prefixToMatch := fmt.Sprintf("%s%c", data["fullname"], os.PathSeparator) - rest, found := strings.CutPrefix(fileFilepath, prefixToMatch) - if found && rest != "" { - hasFilesUnder = true - - break - } - } - if hasFilesUnder { - newListData = append(newListData, data) - } else { - log.Debugf("Skipping directory from the new listData, as it does not have any files found under it: %s", data["fullname"]) - } - } else { - newListData = append(newListData, data) - } - } - - check.listData = newListData -} - // Files are checked by their individual attributes, with directories we have to count and size them up // This function should be called with the final check.listData func (l *CheckFiles) addGeneralMetrics(check *CheckData) { From 3d78ada5ad30d62158bbc6047bcbe686219d7f39 Mon Sep 17 00:00:00 2001 From: Ahmet Oeztuerk Date: Mon, 20 Jul 2026 15:01:08 +0200 Subject: [PATCH 4/5] check_files: clear up some test function comments --- pkg/snclient/check_files_test.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pkg/snclient/check_files_test.go b/pkg/snclient/check_files_test.go index 2bc5939d..d8b7f497 100644 --- a/pkg/snclient/check_files_test.go +++ b/pkg/snclient/check_files_test.go @@ -489,8 +489,7 @@ func TestCheckFilesSizePerfdata(t *testing.T) { assert.Contains(t, outputString, "total_size'=3670016") // Search on the root, but use pattern that only matches files with "b" extension - // The pattern matching should remove the files with "root" and "a" extensions - // The second pass should remove the "a" folder where files with "a" extension is found + // The pattern matching should remove the files and folders with "root" and "a" extensions res = snc.RunCheck("check_files", []string{"path=" + geneartionDirectory, "pattern=*.b", "crit='size > 100MiB'"}) outputString = string(res.BuildPluginOutput()) assert.Containsf(t, outputString, "OK - All 5 files are ok", "output matches") @@ -504,7 +503,7 @@ func TestCheckFilesSizePerfdata(t *testing.T) { res = snc.RunCheck("check_files", []string{"paths=" + aDirectory + "," + bDirectory, "critical='check_path != " + aDirectory + " '"}) outputString = string(res.BuildPluginOutput()) assert.Containsf(t, outputString, "CRITICAL - 5/9 files", "output matches") - assert.NotContainsf(t, outputString, "file_1024kb_1.a", "output matches") + assert.NotContainsf(t, outputString, "file_1024kb_1.a", "file_1024kb_1.a is not deemed critical, should not be in output") // check if calculate-subdirectory-sizes works res = snc.RunCheck("check_files", []string{"path=" + geneartionDirectory, "crit='size > 4Mib'", "calculate-subdirectory-sizes=true"}) @@ -518,8 +517,8 @@ func TestCheckFilesSizePerfdata(t *testing.T) { res = snc.RunCheck("check_files", []string{"path=" + geneartionDirectory, "pattern=*_3.*", "crit='size > 0Mib'", "calculate-subdirectory-sizes=true"}) outputString = string(res.BuildPluginOutput()) assert.Containsf(t, outputString, "CRITICAL - 4/4 files (3.50 MiB) critical", "output matches") - assert.NotContainsf(t, outputString, "'a size'=1048576B", "should calculate the size of the subfolder a, as it does not match pattern") - assert.NotContainsf(t, outputString, "'b size'=1048576B", "should calculate the size of the subfolder b, as it does not match pattern") + assert.NotContainsf(t, outputString, "'a size'=1048576B", "should not calculate the size of the subfolder a, as it does not match pattern") + assert.NotContainsf(t, outputString, "'b size'=1048576B", "should not calculate the size of the subfolder b, as it does not match pattern") // only matches the directory "a" itself res = snc.RunCheck("check_files", []string{"path=" + geneartionDirectory, "pattern=a"}) From d9ce67e6645ddedd8d7f90179a79fb44e8204492 Mon Sep 17 00:00:00 2001 From: Ahmet Oeztuerk Date: Mon, 20 Jul 2026 18:00:28 +0200 Subject: [PATCH 5/5] check_files: fix typos, improve comments, function names --- pkg/snclient/check_files.go | 12 ++--- pkg/snclient/check_files_test.go | 92 ++++++++++++++++---------------- 2 files changed, 52 insertions(+), 52 deletions(-) diff --git a/pkg/snclient/check_files.go b/pkg/snclient/check_files.go index 48de83fd..69963206 100644 --- a/pkg/snclient/check_files.go +++ b/pkg/snclient/check_files.go @@ -25,8 +25,8 @@ func init() { type FileInfoUnified struct { Atime time.Time // Access time - Mtime time.Time // Modify time - Ctime time.Time // Create time + Mtime time.Time // Modify time i.e last file content change time + Ctime time.Time // On Windows creation time , Unix last metadata/inode change } const ( @@ -166,7 +166,7 @@ func (l *CheckFiles) Check(_ context.Context, _ *Agent, check *CheckData, _ []Ar } } - l.removeDirectoriesThatDontMatchPattern(check) + l.removeDirectoriesNotMatchingPattern(check) if l.calculateSubdirectorySizes { l.addSubdirectorySizes(check) @@ -275,7 +275,7 @@ func (w *fileWalker) walk(realRoot, displayRoot string, usedSymlink bool) error return w.cf.addFile(w.check, displayPath, w.checkPath, dirEntry, isSymlink, err) } - log.Tracef("enty on path: %s of type: %s symlink status: %t", path, entryType, isSymlink) + log.Tracef("entry on path: %s of type: %s symlink status: %t", path, entryType, isSymlink) if isSymlink { if w.cf.followSymlinks { @@ -555,7 +555,7 @@ func checkSlowFileOperations(check *CheckData, entry map[string]string, path str return nil } -func (l *CheckFiles) removeDirectoriesThatDontMatchPattern(check *CheckData) { +func (l *CheckFiles) removeDirectoriesNotMatchingPattern(check *CheckData) { if l.pattern == "*" { return } @@ -623,7 +623,7 @@ func (l *CheckFiles) addGeneralMetrics(check *CheckData) { } if check.HasThreshold("size") { - log.Warn("check_files - Using 'size' in a threshold argument meant to mean \"summation of all found files sizes\" is wrong. " + + log.Warn("check_files - Using 'size' in a threshold argument to mean \"summation of all found files sizes\" is wrong. " + "This collides with each file entry 'size' attribute during checks. Using 'size' in a condition will check each files 'size' attribute. " + "If you want to check for the sum of sizes, use 'total_size' in your condition instead. ") } diff --git a/pkg/snclient/check_files_test.go b/pkg/snclient/check_files_test.go index d8b7f497..fa9ffe7e 100644 --- a/pkg/snclient/check_files_test.go +++ b/pkg/snclient/check_files_test.go @@ -319,10 +319,10 @@ func TestCheckFilesRecursiveArguments(t *testing.T) { config := checkFilesTestConfigWithScript(t, scriptsDir, scriptName, scriptFilename) snc := StartTestAgent(t, config) - // capture this since t.TempDir() is dyanic - geneartionDirectory := t.TempDir() + // capture this since t.TempDir() is dynamic + generationDirectory := t.TempDir() - res := snc.RunCheck(scriptName, []string{geneartionDirectory}) + res := snc.RunCheck(scriptName, []string{generationDirectory}) assert.Equalf(t, CheckExitOK, res.State, "state matches") assert.Containsf(t, string(res.BuildPluginOutput()), "ok - Generated 11 files for testing", "output matches") @@ -350,7 +350,7 @@ func TestCheckFilesRecursiveArguments(t *testing.T) { // No arguments: Recursion enabled. Should find everything under the folder. // 11 files and 6 folders => Reports 17 files - res = snc.RunCheck("check_files", []string{"path=" + geneartionDirectory}) + res = snc.RunCheck("check_files", []string{"path=" + generationDirectory}) assert.Containsf(t, string(res.BuildPluginOutput()), "OK - All 17 files are ok", "output matches") // Max-depth=0 @@ -358,36 +358,36 @@ func TestCheckFilesRecursiveArguments(t *testing.T) { // So only the path itself is going to have depth 0. Anything under it requires an appended / // But the check will always include files directly under it // file1.txt , file2 , directory1 , directory2 - res = snc.RunCheck("check_files", []string{"path=" + geneartionDirectory, "max-depth=0"}) + res = snc.RunCheck("check_files", []string{"path=" + generationDirectory, "max-depth=0"}) assert.Containsf(t, string(res.BuildPluginOutput()), "OK - All 4 files are ok", "output matches") // Max-depth=1 // These items fit the depth condition, as they require one more separator to type after the base path // file1.txt , file2 , directory1 , directory2 - res = snc.RunCheck("check_files", []string{"path=" + geneartionDirectory, "max-depth=1"}) + res = snc.RunCheck("check_files", []string{"path=" + generationDirectory, "max-depth=1"}) assert.Containsf(t, string(res.BuildPluginOutput()), "OK - All 4 files are ok", "output matches") // Max-depth=2 // file1.txt , file2 , directory1 , directory1-file3.txt, directory1-file4 , directory1-directory2, directory4, // directory4-file9.exe , directory4-file10.html , directory4-directory5 , directory4-directory6 - res = snc.RunCheck("check_files", []string{"path=" + geneartionDirectory, "max-depth=2"}) + res = snc.RunCheck("check_files", []string{"path=" + generationDirectory, "max-depth=2"}) assert.Containsf(t, string(res.BuildPluginOutput()), "OK - All 11 files are ok", "output matches") // Max-depth=3 // Adds 5 more: directory1-directory2-directory3, directory1-directory2-file5 , directory1-directory2-file6, directory1-directory2-file7, directory4-directory5-file11 - res = snc.RunCheck("check_files", []string{"path=" + geneartionDirectory, "max-depth=3"}) + res = snc.RunCheck("check_files", []string{"path=" + generationDirectory, "max-depth=3"}) assert.Containsf(t, string(res.BuildPluginOutput()), "OK - All 16 files are ok", "output matches") // Max-depth=4 // Adds the last file: directory1-directory2-directory3-file8 - res = snc.RunCheck("check_files", []string{"path=" + geneartionDirectory, "max-depth=4"}) + res = snc.RunCheck("check_files", []string{"path=" + generationDirectory, "max-depth=4"}) assert.Containsf(t, string(res.BuildPluginOutput()), "OK - All 17 files are ok", "output matches") // File and directory type checks - res = snc.RunCheck("check_files", []string{"path=" + geneartionDirectory, "filter='type=file'"}) + res = snc.RunCheck("check_files", []string{"path=" + generationDirectory, "filter='type=file'"}) assert.Containsf(t, string(res.BuildPluginOutput()), "OK - All 11 files are ok", "output matches") - res = snc.RunCheck("check_files", []string{"path=" + geneartionDirectory, "filter='type=dir'"}) + res = snc.RunCheck("check_files", []string{"path=" + generationDirectory, "filter='type=dir'"}) assert.Containsf(t, string(res.BuildPluginOutput()), "OK - All 6 files are ok", "output matches") StopTestAgent(t, snc) @@ -414,9 +414,9 @@ func TestCheckFilesSizePerfdata(t *testing.T) { snc := StartTestAgent(t, config) // capture this since t.TempDir() is dyanic - geneartionDirectory := t.TempDir() + generationDirectory := t.TempDir() - res := snc.RunCheck("check_files_perfdata_generate_files", []string{geneartionDirectory}) + res := snc.RunCheck("check_files_perfdata_generate_files", []string{generationDirectory}) assert.Equalf(t, CheckExitOK, res.State, "state matches") outputString := string(res.BuildPluginOutput()) assert.Containsf(t, outputString, "ok - Generated 16 files for testing", "output matches") @@ -447,12 +447,12 @@ func TestCheckFilesSizePerfdata(t *testing.T) { // 3 directories, 16 files // Total size should be exactly 14 mb - res = snc.RunCheck("check_files", []string{"path=" + geneartionDirectory, "crit='total_size > 100Mb'"}) + res = snc.RunCheck("check_files", []string{"path=" + generationDirectory, "crit='total_size > 100Mb'"}) outputString = string(res.BuildPluginOutput()) // This check includes the directories as well assert.Containsf(t, outputString, "OK - All 18 files are ok", "output matches") - res = snc.RunCheck("check_files", []string{"path=" + geneartionDirectory, "crit='total_size > 100Mb'", "filter='type == file'"}) + res = snc.RunCheck("check_files", []string{"path=" + generationDirectory, "crit='total_size > 100Mb'", "filter='type == file'"}) outputString = string(res.BuildPluginOutput()) // This filters out the two directories assert.Containsf(t, outputString, "OK - All 16 files are ok", "output matches") @@ -466,13 +466,13 @@ func TestCheckFilesSizePerfdata(t *testing.T) { // file_512kb_2.root // file_512kb_3.root // file_512kb_4.root - res = snc.RunCheck("check_files", []string{"path=" + geneartionDirectory, "max-depth=0", "crit='total_size > 100Mb'", "filter='type == file'"}) + res = snc.RunCheck("check_files", []string{"path=" + generationDirectory, "max-depth=0", "crit='total_size > 100Mb'", "filter='type == file'"}) outputString = string(res.BuildPluginOutput()) assert.Containsf(t, outputString, "OK - All 7 files are ok", "output matches") assert.Contains(t, outputString, "'total_size'=5242880B") // only match the root files, but return critical if size is above 512kb - res = snc.RunCheck("check_files", []string{"path=" + geneartionDirectory, "max-depth=0", "crit='size > 512Kb'", "filter='type == file'"}) + res = snc.RunCheck("check_files", []string{"path=" + generationDirectory, "max-depth=0", "crit='size > 512Kb'", "filter='type == file'"}) outputString = string(res.BuildPluginOutput()) assert.Containsf(t, outputString, "CRITICAL - 3/7 files (5.00 MiB)", "output matches") assert.Containsf(t, outputString, "file_1024kb_1.root size'=1048576B", "Should include metrics named ' size' for all files") @@ -481,7 +481,7 @@ func TestCheckFilesSizePerfdata(t *testing.T) { // "file_1024kb_1.root", // "a/file_1024kb_1.a", // "b/file_1024kb_1.b", - res = snc.RunCheck("check_files", []string{"path=" + geneartionDirectory, "pattern=file_*_1.*", "crit='total_size != 3670016'", "filter='type == file'"}) + res = snc.RunCheck("check_files", []string{"path=" + generationDirectory, "pattern=file_*_1.*", "crit='total_size != 3670016'", "filter='type == file'"}) outputString = string(res.BuildPluginOutput()) // the metric check for 'total_size' sets the status to critical // files do not have a 'total_size' attribute, so they do not result towards setting the status @@ -490,23 +490,23 @@ func TestCheckFilesSizePerfdata(t *testing.T) { // Search on the root, but use pattern that only matches files with "b" extension // The pattern matching should remove the files and folders with "root" and "a" extensions - res = snc.RunCheck("check_files", []string{"path=" + geneartionDirectory, "pattern=*.b", "crit='size > 100MiB'"}) + res = snc.RunCheck("check_files", []string{"path=" + generationDirectory, "pattern=*.b", "crit='size > 100MiB'"}) outputString = string(res.BuildPluginOutput()) assert.Containsf(t, outputString, "OK - All 5 files are ok", "output matches") - res = snc.RunCheck("check_files", []string{"path=" + geneartionDirectory, "pattern=*.b", "crit='size > 100MiB'", "filter=' type == file'"}) + res = snc.RunCheck("check_files", []string{"path=" + generationDirectory, "pattern=*.b", "crit='size > 100MiB'", "filter=' type == file'"}) outputString = string(res.BuildPluginOutput()) assert.Containsf(t, outputString, "OK - All 5 files are ok", "output matches") // check if the search_path attribute is being populated - aDirectory := filepath.Join(geneartionDirectory, "a") - bDirectory := filepath.Join(geneartionDirectory, "b") + aDirectory := filepath.Join(generationDirectory, "a") + bDirectory := filepath.Join(generationDirectory, "b") res = snc.RunCheck("check_files", []string{"paths=" + aDirectory + "," + bDirectory, "critical='check_path != " + aDirectory + " '"}) outputString = string(res.BuildPluginOutput()) assert.Containsf(t, outputString, "CRITICAL - 5/9 files", "output matches") assert.NotContainsf(t, outputString, "file_1024kb_1.a", "file_1024kb_1.a is not deemed critical, should not be in output") // check if calculate-subdirectory-sizes works - res = snc.RunCheck("check_files", []string{"path=" + geneartionDirectory, "crit='size > 4Mib'", "calculate-subdirectory-sizes=true"}) + res = snc.RunCheck("check_files", []string{"path=" + generationDirectory, "crit='size > 4Mib'", "calculate-subdirectory-sizes=true"}) outputString = string(res.BuildPluginOutput()) // files themselves are all 512 Kib or 1 Mib // directory 'a' contains four 1 MiB files, @@ -514,19 +514,19 @@ func TestCheckFilesSizePerfdata(t *testing.T) { assert.Containsf(t, outputString, "CRITICAL - 1/18 files (14.00 MiB) critical(b)", "output matches") // When using a pattern and calculate subdirectory sizes is enabled, it will add the subdirectory sizes as metrics - res = snc.RunCheck("check_files", []string{"path=" + geneartionDirectory, "pattern=*_3.*", "crit='size > 0Mib'", "calculate-subdirectory-sizes=true"}) + res = snc.RunCheck("check_files", []string{"path=" + generationDirectory, "pattern=*_3.*", "crit='size > 0Mib'", "calculate-subdirectory-sizes=true"}) outputString = string(res.BuildPluginOutput()) assert.Containsf(t, outputString, "CRITICAL - 4/4 files (3.50 MiB) critical", "output matches") - assert.NotContainsf(t, outputString, "'a size'=1048576B", "should not calculate the size of the subfolder a, as it does not match pattern") - assert.NotContainsf(t, outputString, "'b size'=1048576B", "should not calculate the size of the subfolder b, as it does not match pattern") + assert.NotContainsf(t, outputString, "'a size'", "should not calculate the size of the subfolder a, as it does not match pattern") + assert.NotContainsf(t, outputString, "'b size'", "should not calculate the size of the subfolder b, as it does not match pattern") // only matches the directory "a" itself - res = snc.RunCheck("check_files", []string{"path=" + geneartionDirectory, "pattern=a"}) + res = snc.RunCheck("check_files", []string{"path=" + generationDirectory, "pattern=a"}) outputString = string(res.BuildPluginOutput()) assert.Containsf(t, outputString, "OK - All 1 files are ok: (0 B)", "output matches") // matches the four files inside directory "a": file_1024kb_1.a , file_1024kb_2.a , file_1024kb_3.a , file_1024kb_4.a - res = snc.RunCheck("check_files", []string{"path=" + geneartionDirectory, "pattern=*.a"}) + res = snc.RunCheck("check_files", []string{"path=" + generationDirectory, "pattern=*.a"}) outputString = string(res.BuildPluginOutput()) assert.Containsf(t, outputString, "OK - All 4 files are ok: (4.00 MiB)", "output matches") @@ -553,9 +553,9 @@ func TestCheckFilesFilesystemLinks(t *testing.T) { config := checkFilesTestConfigWithScript(t, scriptsDir, scriptName, scriptFilename) snc := StartTestAgent(t, config) - geneartionDirectory := t.TempDir() + generationDirectory := t.TempDir() - res := snc.RunCheck(scriptName, []string{geneartionDirectory}) + res := snc.RunCheck(scriptName, []string{generationDirectory}) assert.Equalf(t, CheckExitOK, res.State, "script return state check is correct") outputString := string(res.BuildPluginOutput()) @@ -580,7 +580,7 @@ func TestCheckFilesFilesystemLinks(t *testing.T) { assert.Containsf(t, outputString, `Hardlink created for file1_hardlink1.txt <<===>> dir1\file1.txt`, "output matches") assert.Containsf(t, outputString, `Junction created for dir1_junction1 <<===>> dir1`, "output matches") - res = snc.RunCheck("check_files", []string{"path=" + geneartionDirectory, "filter=type eq file", "show-all"}) + res = snc.RunCheck("check_files", []string{"path=" + generationDirectory, "filter=type eq file", "show-all"}) assert.Equalf(t, CheckExitOK, res.State, "state OK") outputString = string(res.BuildPluginOutput()) assert.Containsf(t, outputString, "file1.txt", "output has file") @@ -589,7 +589,7 @@ func TestCheckFilesFilesystemLinks(t *testing.T) { assert.NotContainsf(t, outputString, "dir1", "output does not have directory") assert.NotContainsf(t, outputString, "dir1_junction1", "output does not have junction directory") - res = snc.RunCheck("check_files", []string{"path=" + geneartionDirectory, "filter=type eq file and is_symlink eq true", "show-all"}) + res = snc.RunCheck("check_files", []string{"path=" + generationDirectory, "filter=type eq file and is_symlink eq true", "show-all"}) assert.Equalf(t, CheckExitOK, res.State, "state OK") outputString = string(res.BuildPluginOutput()) assert.Containsf(t, outputString, "file1_symlink1.txt", "output does have symlink file") @@ -597,14 +597,14 @@ func TestCheckFilesFilesystemLinks(t *testing.T) { assert.NotContainsf(t, outputString, "dir1", "output does not have directory") assert.NotContainsf(t, outputString, "dir1_junction1", "output does not have junction directory") - res = snc.RunCheck("check_files", []string{"path=" + geneartionDirectory, "filter=type eq dir", "show-all"}) + res = snc.RunCheck("check_files", []string{"path=" + generationDirectory, "filter=type eq dir", "show-all"}) assert.Equalf(t, CheckExitOK, res.State, "state OK") outputString = string(res.BuildPluginOutput()) assert.Containsf(t, outputString, "dir1", "output has directory") assert.Containsf(t, outputString, "dir1_junction1", "output has directory") assert.Containsf(t, outputString, "dir1_symlink1", "output has directory") - res = snc.RunCheck("check_files", []string{"path=" + geneartionDirectory, "filter=type eq dir and is_symlink eq true", "show-all"}) + res = snc.RunCheck("check_files", []string{"path=" + generationDirectory, "filter=type eq dir and is_symlink eq true", "show-all"}) assert.Equalf(t, CheckExitOK, res.State, "state OK") outputString = string(res.BuildPluginOutput()) assert.Containsf(t, outputString, "dir1_junction1", "output has directory") @@ -626,7 +626,7 @@ func TestCheckFilesFilesystemLinks(t *testing.T) { assert.Containsf(t, outputString, "ok - Generated 2 files for testing", "output matches") assert.Containsf(t, outputString, "ok - Generated 1 directories for testing", "output matches") - res = snc.RunCheck("check_files", []string{"path=" + geneartionDirectory, "filter=type eq file", "show-all"}) + res = snc.RunCheck("check_files", []string{"path=" + generationDirectory, "filter=type eq file", "show-all"}) assert.Equalf(t, CheckExitOK, res.State, "state OK") outputString = string(res.BuildPluginOutput()) assert.Containsf(t, outputString, "file1.txt", "output has file") @@ -635,11 +635,11 @@ func TestCheckFilesFilesystemLinks(t *testing.T) { assert.Containsf(t, outputString, "file1_physical1.txt", "output does have hardlink file") assert.NotContainsf(t, outputString, "dir1", "output does not have directory") - res = snc.RunCheck("check_files", []string{"path=" + geneartionDirectory, "filter=type eq file"}) + res = snc.RunCheck("check_files", []string{"path=" + generationDirectory, "filter=type eq file"}) assert.Equalf(t, CheckExitOK, res.State, "state OK") assert.Containsf(t, string(res.BuildPluginOutput()), "All 6 files are ok", "should count 6 files") - res = snc.RunCheck("check_files", []string{"path=" + geneartionDirectory, "filter=type eq file and is_symlink eq true", "show-all"}) + res = snc.RunCheck("check_files", []string{"path=" + generationDirectory, "filter=type eq file and is_symlink eq true", "show-all"}) assert.Equalf(t, CheckExitOK, res.State, "state OK") outputString = string(res.BuildPluginOutput()) assert.Containsf(t, outputString, "file1_symbolic1.txt", "output does have symlink file") @@ -648,14 +648,14 @@ func TestCheckFilesFilesystemLinks(t *testing.T) { assert.NotContainsf(t, outputString, "file1.txt", "output does not have regular file") assert.NotContainsf(t, outputString, "dir1", "output does not have directory") - res = snc.RunCheck("check_files", []string{"path=" + geneartionDirectory, "filter=type eq dir", "show-all"}) + res = snc.RunCheck("check_files", []string{"path=" + generationDirectory, "filter=type eq dir", "show-all"}) assert.Equalf(t, CheckExitOK, res.State, "state OK") outputString = string(res.BuildPluginOutput()) assert.Containsf(t, outputString, "dir1", "output has directory") assert.Containsf(t, outputString, "dir1_symbolic1", "output has symlink directory") assert.Containsf(t, outputString, "dir1_relative1", "output has relative symlink directory") - res = snc.RunCheck("check_files", []string{"path=" + geneartionDirectory, "filter=type eq dir and is_symlink eq true", "show-all"}) + res = snc.RunCheck("check_files", []string{"path=" + generationDirectory, "filter=type eq dir and is_symlink eq true", "show-all"}) assert.Equalf(t, CheckExitOK, res.State, "state OK") outputString = string(res.BuildPluginOutput()) assert.Containsf(t, outputString, "dir1_symbolic1", "output has symlink directory") @@ -684,9 +684,9 @@ func TestCheckFilesFilesystemLinks2(t *testing.T) { config := checkFilesTestConfigWithScript(t, scriptsDir, scriptName, scriptFilename) snc := StartTestAgent(t, config) - geneartionDirectory := t.TempDir() + generationDirectory := t.TempDir() - res := snc.RunCheck(scriptName, []string{geneartionDirectory}) + res := snc.RunCheck(scriptName, []string{generationDirectory}) assert.Equalf(t, CheckExitOK, res.State, "script return state check is correct") outputString := string(res.BuildPluginOutput()) @@ -707,7 +707,7 @@ func TestCheckFilesFilesystemLinks2(t *testing.T) { assert.Containsf(t, outputString, `ok - Generated 4 directories for testing`, "output matches") // with add-files-only-once=true, it must not cause an infinite loop - res = snc.RunCheck("check_files", []string{"path=" + geneartionDirectory, "follow-symlinks=true", "add-files-only-once=true", `detail-syntax="(%(fullname) - %(is_symlink))`, "show-all"}) + res = snc.RunCheck("check_files", []string{"path=" + generationDirectory, "follow-symlinks=true", "add-files-only-once=true", `detail-syntax="(%(fullname) - %(is_symlink))`, "show-all"}) assert.Equalf(t, CheckExitOK, res.State, "cyclic symlinks with add-files-only-once=true should complete OK") outputString = string(res.BuildPluginOutput()) assert.Containsf(t, outputString, `A - false`, `folder A should be found`) @@ -719,7 +719,7 @@ func TestCheckFilesFilesystemLinks2(t *testing.T) { // with add-files-only-once=false (default), the cyclic symlinks cause an infinite loop // this is the expected behavior - res = snc.RunCheck("check_files", []string{"path=" + geneartionDirectory, "follow-symlinks=true", "add-files-only-once=false", `detail-syntax="(%(fullname) - %(is_symlink))`, "show-all"}) + res = snc.RunCheck("check_files", []string{"path=" + generationDirectory, "follow-symlinks=true", "add-files-only-once=false", `detail-syntax="(%(fullname) - %(is_symlink))`, "show-all"}) assert.Equalf(t, CheckExitOK, res.State, "state OK") outputString = string(res.BuildPluginOutput()) assert.Containsf(t, outputString, `toA\toB\toA\file.txt - false`, "file file.txt should be accessible over many symlinks") @@ -738,7 +738,7 @@ func TestCheckFilesFilesystemLinks2(t *testing.T) { assert.Containsf(t, outputString, `ok - Generated 4 directories for testing`, "output matches") // with add-files-only-once=true, it must not cause an infinite loop - res = snc.RunCheck("check_files", []string{"path=" + geneartionDirectory, "follow-symlinks=true", "add-files-only-once=true", `detail-syntax="(%(fullname) - %(is_symlink))`, "show-all"}) + res = snc.RunCheck("check_files", []string{"path=" + generationDirectory, "follow-symlinks=true", "add-files-only-once=true", `detail-syntax="(%(fullname) - %(is_symlink))`, "show-all"}) assert.Equalf(t, CheckExitOK, res.State, "cyclic symlinks with add-files-only-once=true should complete OK") outputString = string(res.BuildPluginOutput()) assert.Containsf(t, outputString, `A - false`, `folder A should be found`) @@ -753,7 +753,7 @@ func TestCheckFilesFilesystemLinks2(t *testing.T) { // if max-depth is not specified, maximum of default max-depth and a ceiling max-depth with symlinks is set as max-depth // this prevents unending recursion - res = snc.RunCheck("check_files", []string{"path=" + geneartionDirectory, "follow-symlinks=true", "add-files-only-once=false", `detail-syntax="(%(fullname) - %(is_symlink))`, "show-all"}) + res = snc.RunCheck("check_files", []string{"path=" + generationDirectory, "follow-symlinks=true", "add-files-only-once=false", `detail-syntax="(%(fullname) - %(is_symlink))`, "show-all"}) assert.Equalf(t, CheckExitOK, res.State, "state OK") outputString = string(res.BuildPluginOutput()) assert.Containsf(t, outputString, `toA/toB/toA/file.txt - false`, "file file.txt should be accessible over many symlinks") @@ -761,7 +761,7 @@ func TestCheckFilesFilesystemLinks2(t *testing.T) { // if max-depth is specified, it is untouched res = snc.RunCheck("check_files", []string{ - "path=" + geneartionDirectory, "max-depth=5", "follow-symlinks=true", + "path=" + generationDirectory, "max-depth=5", "follow-symlinks=true", "add-files-only-once=false", `detail-syntax="(%(fullname) - %(is_symlink))`, "show-all", }) assert.Equalf(t, CheckExitOK, res.State, "state OK")