graylog2 - Regex to find spaces between quotes in Graylog -
working on input extractor issue iis logs using "advanced" iis login tool collect more basic logs provide. it's adding double quotes , spaces many of fields , trying extractor correct this. beginning of example message:
2016-02-08 16:46:35.957 "site" "source" xx.xx.xx.xx /blah/etc/etc/file.ext - 80 - "xx.xx.xx.xx" "http/1.1" "mozilla/5.0 (windows nt 6.1; wow64; trident/7.0; yie11; rv:11.0) gecko"
we've written extractor remove added quotes before running through other extractors populate fields, etc., want replace spaces between quotes + before match old logging style.
can point in right direction this? closest i've come far catching " " between site , source , replacing using "([\s]*)". result:
2016-02-08 16:46:35.957 "site+source" xx.xx.xx.xx /blah/etc/etc/file.ext - 80 - "xx.xx.xx.xx+http/1.1+mozilla/5.0 (windows nt 6.1; wow64; trident/7.0; yie11; rv:11.0) gecko"
i can't seem spaces between quotes.
any appreciated. thanks.
further clarification. portion of string:
"mozilla/5.0 (windows nt 6.1; wow64; trident/7.0; yie11; rv:11.0) gecko"
should be:
"mozilla/5.0+(windows+nt+6.1;+wow64;+trident/7.0;+yie11;+rv:11.0)+like+gecko"
everything else should remain same spaces inside of quoted section of string.
is possible regex?
i'm afraid regular expressions not best tool this. have "count" quotes determine whether space within quotes or not.
you can try (python):
text = '2016-02-08 16:46:35.957 "site" "source" xx.xx.xx.xx /blah/etc/etc/file.ext - 80 - "xx.xx.xx.xx" "http/1.1" "mozilla/5.0 (windows nt 6.1; wow64; trident/7.0; yie11; rv:11.0) gecko"' escaped = "" count = 0 c in text: if c == '"': count += 1 if c == " " , count % 2 == 1: escaped += "+" else: escaped += c afterwards, escaped this:
2016-02-08 16:46:35.957 "site" "source" xx.xx.xx.xx /blah/etc/etc/file.ext - 80 - "xx.xx.xx.xx" "http/1.1" "mozilla/5.0+(windows+nt+6.1;+wow64;+trident/7.0;+yie11;+rv:11.0)+like+gecko"
Comments
Post a Comment