v3/master JSON support
Hello!,
I've been running tests nginx 1.12 w/ libmodsecurity using the v3/master branch and currently all is going well with the tests. I am currently using the JSON output using the YAJL libraries, as suggested in the documentation however the default configuration in the code from the following two files:
modsecurity.cc
yajl_gen_config(g, yajl_gen_beautify, 1);
transactions.cc
yajl_gen_config(g, yajl_gen_beautify, 1);
Which enables pretty JSON in the log output by default, which would require additional parsing steps when adding the data into log aggregation such as Elastic stack, for example.
I've modified this to be
modsecurity.cc
yajl_gen_config(g, yajl_gen_beautify, 0);
transactions.cc
yajl_gen_config(g, yajl_gen_beautify, 0);
As well as the following additional changes:
modsecurity.cc line: 370
json->assign(reinterpret_cast<const char*>(buf), jsonSize);
*json += "\n";
transactions.cc line: 1654
return log + "\n";
- It is worth noting I do not know cpp and as such these modifications are likely clumsy and not best practice.
As when disabling yajl_gen_beautify the file did not end with a \n character and particular shipping applications such as Elastic's Filebeat would not register the file as closed, and would not ship the data.
I was wondering if these features could either be added to the project as optional flags in the configure steps, or something which can be added to the configuration of ModSecurity so that it would be easier to change? Otherwise, I think that it would generally be more useful to have the JSON output this way as it is very easy to beautify JSON and a little trickier to reverse that process after-the-fact.
Any thoughts?
edit: If it's easier I am happy to create a pull request for the changes that have been made. :-)
+1
I'm having problems parsing modsecurity logs using fluentd because it needs one json map per line. This change would be really useful.
Hi @met3or,
I think your suggestion is very relevant and I encourage you to sent the modifications in the format of a pull request. As you said it is very easy to "prettify" a JSON, so we don't have to have a configuration option, rather we can make it the default behavior. Don't worry about the code format, the modification is very small if there is something to be fixed I fix it after merge your patch.
Hi @zimmerle
I have submitted the pull request, please review and let me know if all is good. (It's my first commit using GitHub so hoping I've done this correctly..)
Thanks for looking over this,
David
Improvement is already commit to v3/master tree. Thanks @met3or and @averges.