Last active
December 30, 2015 08:19
-
-
Save Tombar/7801481 to your computer and use it in GitHub Desktop.
Logstash ruby filter to parse our nginx multipart postdata
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
filter { | |
ruby { | |
code => "# ruby filter to parse and extract postdata multipart encoded into fields | |
if event['postdata']['request_body'] =~ /Boundary/ | |
fields = event['postdata']['request_body'].gsub('x0Dx0Ax0Dx0A', '=') | |
.gsub('Content-Disposition: form-data; name=', '') | |
.gsub('x0Dx0A', '') | |
.gsub('--', '') | |
.gsub('x22', '') | |
.split('Boundary+0xAbCdEfGbOuNdArY') | |
else | |
fields = event['postdata']['request_body'].split('&') | |
end | |
fields.each do |f| | |
unless f.nil? or f.empty? | |
tmp = f.split('=') | |
event['postdata'][tmp[0]] = tmp[1] | |
end | |
end | |
" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment