I have a firewall log: USG3 kernel: [LAN_IN-2002-R]IN=eth1.11 OUT=eth1.10 MAC=74:83:c2:d9:1d:74:02:42:c0:a8:0b:33:08:00:45:00:00:28 SRC=192.168.11.51 DST=192.168.10.101 LEN=40 TOS=0x00 PREC=0x00 TTL=63 ID=36555 DF PROTO=TCP SPT=8084 DPT=53034 WINDOW=0 RES=0x00 ACK RST URGP=0
I want some information in a seperate field so I created some extractors with grok and regex.
In [LAN_IN-2002-R] the “R” is for Rejected, a “A” for Allow and “D” for Drop. So I want to replace the R for Rejected in this case. How is it possible? I think with a rule in a pipeline.
I tested this:
rule “Replace Action”
when
has_field(“message”)
then
let result = regex("^.-(.+)\].$", to_string($message.message));
set_field(“var3”, result);
end
That created a field var3 with: {"0":"R"}
How is it possible to just set “R” or bether Rejected?
If I change has_field(“message”) to has_field(“ACTION”) the set_field does not work. ACTION is a self created extractor. It this case it is easier to replace R with Rejected instead of with the hole message.
Is it better to use extractors, pipelines/rules or a mix of both?
I would run a key-value function in the processing pipeline and in general use the the processing pipeline for such a work. It is not that easy as the extractors but more powerful.
With that regex I normally get the write string: ^.USG3 kernel: [(.+)-.
This is inside my rule:
let result = regex("^.*USG3 kernel: \\[(.+)-.*",to_string($message.message));
set_field(“Rule”,to_string(result));
The output is: {0=WAN_LOCAL-default}
How can I remove curly brackets and the “0=”?
Same for the field Action.