Skip to content

check_logfile: imporve file scanning and keep track of lines matched in each file#390

Draft
inqrphl wants to merge 5 commits into
mainfrom
check-logfile-improve-line-count-tracking-and-output
Draft

check_logfile: imporve file scanning and keep track of lines matched in each file#390
inqrphl wants to merge 5 commits into
mainfrom
check-logfile-improve-line-count-tracking-and-output

Conversation

@inqrphl

@inqrphl inqrphl commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

apply conditional filters to the lines early on while adding them, this was not the case before. now the count of lines being passing the filter is correct.

add function to generate a detail string from files and the count of matched lines in the file. this can be added to the detail-syntax when needed. this is saved in check.detail as "file_counts"

Files exist, but do not have matching lines:

ahmet@jelinek:~/repositories/snclient$ ./snclient --logfile stdout run check_logfile files=./pkg/snclient/t/test*.log filter='line LIKE this-pattern-does-not-exist-in-the-test-files'
OK - No matching lines found in files (pkg/snclient/t/test.log: 0, pkg/snclient/t/test2.log: 0)

No file found:

ahmet@jelinek:~/repositories/snclient$ ./snclient --logfile stdout run check_logfile files=./pkg/snclient/t/testfiledoesnotexist.log
UNKNOWN - No files found to search lines in, search paths: './pkg/snclient/t/testfiledoesnotexist.log'

@inqrphl inqrphl marked this pull request as draft June 15, 2026 14:16
…in each file

apply conditional filters to the lines early on while adding them, this was not the case before. now the count of lines being passing the filter is correct.

add function to generate a detail string from files and the count of matched lines in the file. this  can be added to the detailed syntax when needed.

if there are no lines matched across all files, change the main output line to say "No matching lines found in files"
@inqrphl inqrphl force-pushed the check-logfile-improve-line-count-tracking-and-output branch from 112f913 to ad5c627 Compare June 16, 2026 16:17
differentiate between empty states
1) where no files are found, due to given file paths
2) where files are found but do not contain matched lines.

write different outputs for both of them, and add tests
@inqrphl inqrphl force-pushed the check-logfile-improve-line-count-tracking-and-output branch from ad5c627 to e1d777c Compare June 17, 2026 11:42
@inqrphl inqrphl marked this pull request as ready for review June 17, 2026 11:43
@lgmu

lgmu commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Should still be UNKNOWN when the file does not exist at all.
Only should be OK when the file exists but the filter doesn't match any lines.

…s exist without matched lines

checkdata.finalizeOutput() requires explicit filters or implicit argument filters to apply emptySyntax on output. apply empty syntax on empty state, by setting the "file" and files" argument is set as a filter.
Comment thread pkg/snclient/check_logfile.go Outdated
}

if !check.MatchMapCondition(check.filter, entry, false) {
log.Tracef("file: %s , line : %s, did not match the filter set in the check, not ading to check.listData", fileName, line)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo "ading"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@lgmu

lgmu commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

check_logfile
OK - All 0 / 0 Lines OK

check_files
UNKNOWN - no path specified

-> In my opinion if file or files is not set, it should throw an UNKNOWN like check_files does.


check_logfile file=snclienti.ini offset=0 "filter=line regexp 'nnone'" show-all
UNKNOWN - No files found to search lines in, search paths: 'snclienti.ini,'

-> Trailing , should be removed probably


check_logfile file=snclient.ini offset=0 "filter=line regexp 'nnone'"
OK - No matching lines found in files (snclient.ini: 0)

check_logfile files=snclient.ini,snclient.ini2 offset=0 "filter=line regexp 'nnone'" show-all
OK - No matching lines found in files (snclient.ini: 0, snclient.ini2: 0)

check_logfile files=snclient.ini,snclient.ini2 offset=0 "filter=line regexp 'none'"
OK - All 2 / 1014 Lines OK

-> Only shows the amount of matching lines per file if nothing matches?

I'm not sure how we should handle searching in multiple files, I think like this it's not really clear what it does

@inqrphl inqrphl marked this pull request as draft July 8, 2026 14:30
FilePathPatternsCS was default initialized to "" , and when split up for commas it became an string[]{""}

This empty string then messed up some logs, and prevented returning an error for the case where no file paths were specified

additionally, add the file-line count details to the ok state syntax.

change the test files a bit, and add a test specifically checking a line that only exists on the second test log file, and how the file-line count details are added

move processing of the arguments into a separate function, to prevent linter from complaining about long CheckLogFile.Check function
@inqrphl

inqrphl commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

There was actually a hidden bug - comma separated path string was default initialized to "" , and after being split it was appended to the paths as ""

I wasnt checking if the user specified a different one, just blindly appending to the list


No arguments

./snclient -vvv --logfile stdout run check_logfile

UNKNOWN - no file defined, specify some file path patterns


No dangling comma at the end if search paths dont have files

./snclient -vvv --logfile stdout run check_logfile file=./nofolder1 files=./nofolder2,./nofolder3,./nofolder4 filter="line LIKE testUser2"

UNKNOWN - No files found to search lines in, search paths: './nofolder1 , ./nofolder2 , ./nofolder3 , ./nofolder4'


If files were found, but did not have matching lines, I would display their counts even when they were all zeros. At least this way, it showed which files were searched for lines

I toggled that file-count pairing to the default ok output as well. Is that fine?

./snclient -vvv --logfile stdout run check_logfile files=./pkg/snclient/t/test.log
OK - All 8 / 8 Lines OK (./pkg/snclient/t/test.log: 8)

./snclient -vvv --logfile stdout run check_logfile files=./pkg/snclient/t/test* filter="line LIKE testUser2"
OK - All 1 / 16 Lines OK (pkg/snclient/t/test.log: 0, pkg/snclient/t/test2.log: 1)

it uses backward slashes, so fully typing the detail prevents a match
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants