Hi, I finished analyzing this issue, here are my findings and a possible solution:
IssueApparently, the logs in the file contained some tabs instead of spaces. That caused the regex not to match and therefore the rule not to trigger. Additionally, the
full_log field didn't show any tabs, but instead contained less spaces than the original log. That caused some issues with Wazuh's predecoder, that was taking spaces as part of the timestamp, and interfering with the way in which the custom decoder was supposed to work.
Here you can see the different logs, the dots are spaces and the arrows are tabs:
Possible solution- To solve the problem with the tabs, we can switch the decoder regex to PCRE2. In that format, the /s expression will match spaces and tabs.
- To solve the predecoder issue, we have to do a workaround: in the localfile configuration, we can set an out_format. That will add some information at the beginning of the log, and that will prevent the predecoder to interfere with the log. Additionally, with this approach we can set text that will be decoded as program_name, and will make it easier to match with the decoder.
Here are the final configuration with those changes:
Agent.conf:
<agent_config name="sontm1">
<!-- Shared agent configuration here -->
<localfile>
<log_format>syslog</log_format>
<location>/var/lib/mysql/sontm1.log</location>
<out_format>$(timestamp) $(hostname) customsql: $(log)</out_format>
</localfile>
</agent_config>
That will transform a log like 2022-11-17T07:49:43.789887Z 12 Query select @@version_comment limit 1 into Nov 11
07:49:43 Agent01 customsql: 2022-11-17T07:49:43.789887Z 12 Query select @@version_comment limit 1, adding a timestamp, the name of the agent and "customsql:" at the beginning.
Decoder:
<decoder name="custom_mysql">
<program_name>customsql</program_name>
<regex type="pcre2">(\d+)\s(\w+)\s+(\w.*)</regex>
<order>code, _action, command</order>
</decoder>
Note that the
program_name is the same text that we added in the
out_format configuration. You can change both to any text that you prefer, but take into account that some texts may cause the log to be decoded with another decoder.
I hope you find this information helpful, please let me know if the solution works or if you have any other questions.
Kind regards,