Hi
Fawwas,
By default JSON log not required to create decoder to extract details, however your logs timestamp is not in right format to indexed properly, Therefore we can add extra parameter for log, then while predecoding part we can ignore taking timestamp.
We can use <out_format> tag in localfile to add extra parameter.
For example:
<out_format>saprouter: $(log)</out_format>
Once you configured log will receive to a manager like this.
saprouter: {"timestamp": "Wed Mar 19", "status": "11:09:54", "session": "2025", "host_info": "Connected TO S1002/2913 host 1.1.1.1/3230 (1.1.1.1)"}
<localfile>
<log_format>json</log_format>
<location>/var/log/test.json</location>
<out_format>saprouter: $(log)</out_format>
</localfile>
Then you need to create custom decoders to extract these fields.
nano
/var/ossec/etc/decoders/ saprouter_custom_decoders.xml
<decoder name="saprouter">
<prematch>saprouter</prematch>
</decoder>
<decoder name="saprouter-custom">
<parent>saprouter</parent>
<regex>\.+"timestamp":"(\.+)"</regex>
<order>LogTime</order>
</decoder>
<decoder name="saprouter-custom">
<parent>saprouter</parent>
<regex>\.+"status":"(\.+)"</regex>
<order>Status</order>
</decoder>
<decoder name="saprouter-custom">
<parent>saprouter</parent>
<regex>\.+"session":"(\.+)"</regex>
<order>Session</order>
</decoder>
<decoder name="saprouter-custom">
<parent>saprouter</parent>
<regex>\.+"host_info":"(\.+)"</regex>
<order>host_info</order>
</decoder>
Save and close the file, then set the file permissions.
chmod 660 /var/ossec/etc/decoders/
saprouter_custom_decoders.xml
chown wazuh:wazuh /var/ossec/etc/decoders/ saprouter_custom_rules.xml
Then you need to add these rules to the custom rule creation file.
nano /var/ossec/etc/rules/saprouter_custom_rules.xml
<group name="saprouter">
<rule id="100211" level="5">
<decoded_as>saprouter</decoded_as>
<description>SAP Router log detected.</description>
</rule>
<rule id="100212" level="12">
<if_sid>100211</if_sid>
<match>DENIED</match>
<description>SAP Router connection denied.</description>
</rule>
</group>
chmod 660 /var/ossec/etc/rules/saprouter_custom_rules.xml
chown wazuh:wazuh /var/ossec/etc/rules/saprouter_custom_rules.xml
After adding make sure to restart Wazuh manager to apply changes.
systemctl restart wazuh-manager
Further, you can learn more about how to create custom decoders and rules by following the documents.
https://documentation.wazuh.com/current/user-manual/ruleset/decoders/custom.html
https://documentation.wazuh.com/current/user-manual/ruleset/ruleset-xml-syntax/decoders.html
https://documentation.wazuh.com/current/user-manual/ruleset/ruleset-xml-syntax/rules.html
https://documentation.wazuh.com/current/user-manual/ruleset/rules/custom.html#custom-rules
https://wazuh.com/blog/creating-decoders-and-rules-from-scratch/
Let me know if you need further assistance on this.
Regards,
Hasitha Upekshitha