Skip to content

Commit

Permalink
Ingest node - user agent, move device to an object (elastic#38115) (e…
Browse files Browse the repository at this point in the history
…lastic#38121)

When the ingest node user_agent parses the device field, it
will result in a string value. To match the ecs schema
this commit moves the value of the parsed device to an
object with an inner field named 'name'. There are not
any passivity concerns since this modifies an unreleased change.

closes elastic#38094
relates elastic#37329
  • Loading branch information
jakelandis committed Feb 11, 2019
1 parent ab69dc5 commit eeb3176
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
4 changes: 3 additions & 1 deletion docs/reference/ingest/processors/user-agent.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ Which returns
"version": "10.10.5",
"full": "Mac OS X 10.10.5"
},
"device": "Other"
"device" : {
"name" : "Other"
},
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,13 @@ public IngestDocument execute(IngestDocument ingestDocument) {
}
break;
case DEVICE:
Map<String, String> deviceDetails = new HashMap<>(1);
if (uaClient.device != null && uaClient.device.name != null) {
uaDetails.put("device", uaClient.device.name);
deviceDetails.put("name", uaClient.device.name);
} else {
uaDetails.put("device", "Other");
deviceDetails.put("name", "Other");
}
uaDetails.put("device", deviceDetails);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ public void testCommonBrowser() throws Exception {
os.put("version", "10.9.2");
os.put("full", "Mac OS X 10.9.2");
assertThat(target.get("os"), is(os));
assertThat(target.get("device"), is("Other"));
Map<String, String> device = new HashMap<>();
device.put("name", "Other");
assertThat(target.get("device"), is(device));
}

@SuppressWarnings("unchecked")
Expand All @@ -136,7 +138,9 @@ public void testUncommonDevice() throws Exception {
os.put("full", "Android 3.0");
assertThat(target.get("os"), is(os));

assertThat(target.get("device"), is("Motorola Xoom"));
Map<String, String> device = new HashMap<>();
device.put("name", "Motorola Xoom");
assertThat(target.get("device"), is(device));
}

@SuppressWarnings("unchecked")
Expand All @@ -157,7 +161,9 @@ public void testSpider() throws Exception {
assertNull(target.get("version"));
assertNull(target.get("os"));

assertThat(target.get("device"), is("Spider"));
Map<String, String> device = new HashMap<>();
device.put("name", "Spider");
assertThat(target.get("device"), is(device));
}

@SuppressWarnings("unchecked")
Expand All @@ -181,6 +187,8 @@ public void testUnknown() throws Exception {

assertNull(target.get("os"));

assertThat(target.get("device"), is("Other"));
Map<String, String> device = new HashMap<>();
device.put("name", "Other");
assertThat(target.get("device"), is(device));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
- match: { _source.user_agent.original: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.149 Safari/537.36" }
- match: { _source.user_agent.os: {"name":"Mac OS X", "version":"10.9.2", "full":"Mac OS X 10.9.2"} }
- match: { _source.user_agent.version: "33.0.1750" }
- match: { _source.user_agent.device: "Other" }
- match: { _source.user_agent.device: {"name": "Other" }}

---
"Test user agent processor with parameters":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
id: 1
- match: { _source.field1: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.149 Safari/537.36" }
- match: { _source.user_agent.name: "Test" }
- match: { _source.user_agent.device: "Other" }
- match: { _source.user_agent.device: {"name": "Other" }}
- is_false: _source.user_agent.os
- is_false: _source.user_agent.version

0 comments on commit eeb3176

Please sign in to comment.