Skip to content

Commit

Permalink
part one of pull request #92:
Browse files Browse the repository at this point in the history
Parse key=values even with whitespace around the equals sign.
Prevent ArrayOutOfBounds exception.
  • Loading branch information
Kay Roepke committed Oct 14, 2012
1 parent 80e7b3a commit c70f626
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/main/java/org/graylog2/filters/TokenizerFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@

import com.yammer.metrics.Metrics;
import com.yammer.metrics.core.TimerContext;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.graylog2.logmessage.LogMessageImpl;
import org.graylog2.plugin.GraylogServer;
import org.graylog2.plugin.filters.MessageFilter;
import org.graylog2.plugin.logmessage.LogMessage;

import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;

/**
* @author Lennart Koopmann <[email protected]>
*/
Expand Down Expand Up @@ -60,12 +60,13 @@ public void filter(LogMessage msg, GraylogServer server) {
int extracted = 0;
if (msg.getShortMessage().contains("=")) {
try {
String[] parts = msg.getShortMessage().split(" ");
String nmsg = msg.getShortMessage().replaceAll("\\s?=\\s?", "=");
String[] parts = nmsg.split(" ");
if (parts != null) {
for (String part : parts) {
if (part.contains("=") && StringUtils.countMatches(part, "=") == 1) {
String[] kv = part.split("=");
if (kv[0] != null && kv[1] != null && p.matcher(kv[0]).matches() && !msg.getAdditionalData().containsKey("_" + kv[0])) {
if (kv.length == 2 && p.matcher(kv[0]).matches() && !msg.getAdditionalData().containsKey("_" + kv[0])) {
msg.addAdditionalData(kv[0].trim(), kv[1].trim());
extracted++;
}
Expand Down

0 comments on commit c70f626

Please sign in to comment.