Graylog2 / graylog-plugin-pipeline-processor

[DEPRECATED] Graylog Pipeline Message Processor Plugins
https://www.graylog.org/
GNU General Public License v3.0
21 stars 15 forks source link

`with` rule block for one-time calculations and variable assignments #110

Closed coffee-squirrel closed 7 years ago

coffee-squirrel commented 8 years ago

Problem description

It might be useful to have a with (or using... whatever) block, alongside when and then, to do one-time calculations and variable assignments for a rule. The examples below show my attempt at mapping one value to another, and how I'd use a with block.

rule "Map a letter to a number (map creation in 'then' block)"
when
  grok("^%{TIMESTAMP_ISO8601:ts} [CEWID] ", to_string($message.message)).matches == true
then
  let result = grok("^%{TIMESTAMP_ISO8601:UNWANTED} %{DATA:severityLetter} ", to_string($message.message));
  let levelMap = key_value("C=2 E=3 W=4 I=6 D=7");
  set_field("my_severity", to_long(levelMap[to_string(result["severityLetter"])]));
end
rule "Map a letter to a number (map creation in 'using' block)"
with
  let levelMap = key_value("C=2 E=3 W=4 I=6 D=7");
when
  grok("^%{TIMESTAMP_ISO8601:ts} [CEWID] ", to_string($message.message)).matches == true
then
  let result = grok("^%{TIMESTAMP_ISO8601:UNWANTED} %{DATA:severityLetter} ", to_string($message.message));
  set_field("my_severity", to_long(levelMap[to_string(result["severityLetter"])]));
end

Environment

kroepke commented 7 years ago

In 2.2 we introduce dynamic code generation, which will precompute all constant expressions (including maps and arrays), automatically providing these kinds of optimizations without extra syntax.

kroepke commented 7 years ago

fixed in #129