Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding wildcards for folders in the localfile configuration on Windows #15973

Merged
merged 5 commits into from Jul 28, 2023

Conversation

lsayanes
Copy link
Contributor

@lsayanes lsayanes commented Jan 18, 2023

Related issue
#12351

Description

Wildcard log monitoring for folders and files in Windows has been added to this branch.

Wildcards '*' and '?' are allowed in folders and files in Windows:

C:\Logs\10.0.01\date_10.0.0.1.log
C:\Logs\10.0.02\*.log
C:\Logs\10.0.03\date_10.0.0.?.log
C:\*\*\*.log
C:\Log?\*\date_10.0.0.2.log
C:\Logs\10.0.03\*log

Meaning: '*' as a complete word and '?' as a character

Sources:

The following files have been modified:

  • src\config\localfile-config.c
  • src\logcollector\logcollector.c
  • src\shared\file_op.c

Log deleted:
In the Read_Localfile function (in localfile-config.c) the call to the Win32 FindFirstFile function has been removed because it is not able to resolve wildcard paths, for this reason the following error message has also been removed:

GLOB_ERROR_WIN "(1141): Glob error. Invalid pattern: '%s' or no files found."

Proof of concept:

In this proof of concept for Windows Agent, three types of monitoring are established:

  1. Matching file
  2. Folder doesn't exist:
  3. File doesn't exist:

The ossec.conf has been configured for:

<!-- Log analysis -->
 <localfile>
    <location>c:\log\one\*.log</location>
    <log_format>syslog</log_format>
  </localfile>

  <localfile>
    <location>c:\one\*.log</location>
    <log_format>syslog</log_format>
  </localfile>

  <localfile>
    <location>c:\log\one\two.*</location>
    <log_format>syslog</log_format>
  </localfile>

Given this folder structure:

       C:
        |
        |-----\log
                |
                |-----\one
                |       |
                |       |---- one.log
                |
                |-----\two
                |        |
                |        |-----two.log
                |
                |-----\three
                        |
                        |-----three.log

The following log (extract) was obtained with windows.debug=2

2023/02/14 16:20:43 wazuh-agent[8284] logcollector.c:1571 at check_pattern_expand(): INFO: (1957): New file that matches the 'c:\log\one\*.log' pattern: 'c:\log\one\one.log'.
2023/02/14 16:20:43 wazuh-agent[8284] logcollector.c:1257 at set_read(): DEBUG: Socket target for 'c:\log\one\one.log' -> agent
2023/02/14 16:20:43 wazuh-agent[8284] logcollector.c:431 at LogCollectorStart(): INFO: (1950): Analyzing file: 'c:\log\one\one.log'.

2023/02/14 16:20:43 wazuh-agent[8284] file_op.c:2035 at expand_win32_wildcards(): DEBUG: No folder that matches c:\one\*.log.
2023/02/14 16:20:43 wazuh-agent[8284] file_op.c:2032 at expand_win32_wildcards(): DEBUG: No file that matches c:\log\one\two.*.


2023/02/14 16:20:47 wazuh-agent[8284] read_syslog.c:150 at read_syslog(): DEBUG: Read 0 lines from c:\log\one\one.log

Tests

  • Compilation without warnings in every supported platform
    • Linux
    • Windows
    • MAC OS X
  • Source installation
  • Package installation
  • Source upgrade
  • Package upgrade
  • Review logs syntax and correct language
  • QA templates contemplate the added capabilities
  • Memory tests for Linux
    • Scan-build report
    • Coverity
    • Valgrind (memcheck and descriptor leaks check)
    • Dr. Memory
    • AddressSanitizer
  • Memory tests for Windows
    • Scan-build report
    • Coverity
    • Dr. Memory
  • Memory tests for macOS
    • Scan-build report
    • Leaks
    • AddressSanitizer
  • Retrocompatibility with older Wazuh versions
  • Working on cluster environments
  • Configuration on demand reports new parameters
  • The data flow works as expected (agent-manager-api-app)
  • Added unit tests (for new features)
  • Stress test for affected components
  • Decoder/Rule tests
    • Added unit testing files ".ini"
    • runtests.py executed without errors

@MarcelKemp MarcelKemp self-requested a review January 20, 2023 11:09
@MarcelKemp MarcelKemp linked an issue Jan 20, 2023 that may be closed by this pull request
@MarcelKemp MarcelKemp changed the title Monitoring logs using wildcard for folders on Windows issue #12351 Adding wildcards for folders in the localfile configuration on Windows Jan 20, 2023
src/logcollector/logcollector.c Outdated Show resolved Hide resolved
src/logcollector/logcollector.c Show resolved Hide resolved
src/config/localfile-config.c Outdated Show resolved Hide resolved
src/config/localfile-config.c Outdated Show resolved Hide resolved
src/config/localfile-config.c Outdated Show resolved Hide resolved
src/logcollector/logcollector.c Outdated Show resolved Hide resolved
src/logcollector/logcollector.c Outdated Show resolved Hide resolved
src/config/localfile-config.c Outdated Show resolved Hide resolved
src/config/localfile-config.c Outdated Show resolved Hide resolved
src/config/localfile-config.c Outdated Show resolved Hide resolved
@MarcelKemp MarcelKemp self-requested a review February 7, 2023 14:21
@MarcelKemp MarcelKemp changed the base branch from master to 4.5 February 8, 2023 12:32
@lsayanes lsayanes force-pushed the 12351_wildcard_logcollector branch 2 times, most recently from b59f081 to 06ee983 Compare February 14, 2023 17:39
src/logcollector/logcollector.c Outdated Show resolved Hide resolved
src/logcollector/logcollector.c Outdated Show resolved Hide resolved
src/logcollector/logcollector.c Outdated Show resolved Hide resolved
src/logcollector/logcollector.c Outdated Show resolved Hide resolved
src/shared/file_op.c Outdated Show resolved Hide resolved
src/shared/file_op.c Outdated Show resolved Hide resolved
MarcelKemp
MarcelKemp previously approved these changes Feb 17, 2023
Copy link
Member

@jnasselle jnasselle left a comment

Choose a reason for hiding this comment

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

Hi @lsayanes ,

Unfortunately, this PR needs a rebase since #17639 issue moves 4.5.0 to 4.6.0, and this PR is not aligned with such changes.

Thanks in advance,
Nico

lsayanes added 5 commits July 25, 2023 17:31
Wildcard windows issue fixed

Scan-build ok

Style C asked, applied

Correction

Jenkins error compiler fixed

The function expand_win32_wildcards into check_pattern_expand
@lsayanes lsayanes force-pushed the 12351_wildcard_logcollector branch from 84907de to db44930 Compare July 25, 2023 21:47
@davidjiglesias davidjiglesias merged commit b4786ba into 4.6.0 Jul 28, 2023
66 checks passed
@davidjiglesias davidjiglesias deleted the 12351_wildcard_logcollector branch July 28, 2023 06:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Monitoring logs using wildcard for folders on Windows
5 participants