Skip to content

Commit

Permalink
Merge pull request #98 from r-duran/develop
Browse files Browse the repository at this point in the history
Prevent Tokenizer filter to add _id to additional fields
  • Loading branch information
Lennart Koopmann committed Oct 18, 2012
2 parents 7b481d7 + c4540ba commit f3a4e6e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/graylog2/filters/TokenizerFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void filter(LogMessage msg, GraylogServer server) {
for (String part : parts) {
if (part.contains("=") && StringUtils.countMatches(part, "=") == 1) {
String[] kv = part.split("=");
if (kv.length == 2 && p.matcher(kv[0]).matches() && !msg.getAdditionalData().containsKey("_" + kv[0])) {
if (kv.length == 2 && p.matcher(kv[0]).matches() && !msg.getAdditionalData().containsKey("_" + kv[0]) && !kv[0].equals("id")) {
msg.addAdditionalData(kv[0].trim(), kv[1].trim());
extracted++;
}
Expand Down
12 changes: 11 additions & 1 deletion src/test/java/org/graylog2/filters/TokenizerFilterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,14 @@ public void testFilterWithWhitespaceAroundKV() {
assertEquals("v4", msg.getAdditionalData().get("_k4"));
}

}
@Test
public void testFilterWithIDAdditionalField() {
LogMessageImpl msg = new LogMessageImpl();
msg.setShortMessage("otters id=123 more otters");
TokenizerFilter f = new TokenizerFilter();
f.filter(msg, new GraylogServerStub());

assertEquals(false, msg.getAdditionalData().containsKey("_id"));
}

}

0 comments on commit f3a4e6e

Please sign in to comment.