Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jalogisch/2f288043696ae2fe50aa21c64405355e to your computer and use it in GitHub Desktop.
Save jalogisch/2f288043696ae2fe50aa21c64405355e to your computer and use it in GitHub Desktop.
import org.graylog2.plugin.Message
import java.util.regex.Matcher
import java.util.regex.Pattern
rule "Rename level field to avoid ES type collision"
when
m : Message( message matches ".*level=.*" );
then
Matcher matcher = Pattern.compile("level=(\\w+)(\\s|$)").matcher(m.getMessage());
if (matcher.find()) {
String x = matcher.group(1);
if(x.equals("debug")) {
m.addField("level", 7);
} else if(x.equals("info")) {
m.addField("level", 6);
} else if(x.equals("notice")) {
m.addField("level", 5);
} else if(x.equals("warning")) {
m.addField("level", 4);
} else if(x.equals("error")) {
m.addField("level", 3);
} else if(x.equals("critical")) {
m.addField("level", 2);
} else if(x.equals("alert")) {
m.addField("level", 1);
} else if(x.equals("emergency")) {
m.addField("level", 0);
} else {
m.addField("level", 6);
}
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment