use of org.graylog2.plugin.Message in project graylog2-server by Graylog2.
the class GeoIpResolverEngineTest method testGetIpAddressFieldsEnforceGraylogSchemaFalse.
@Test
public void testGetIpAddressFieldsEnforceGraylogSchemaFalse() {
GeoIpResolverConfig conf = config.toBuilder().enforceGraylogSchema(false).build();
final GeoIpResolverEngine engine = new GeoIpResolverEngine(geoIpVendorResolverService, conf, metricRegistry);
Map<String, Object> fields = new HashMap<>();
fields.put("_id", java.util.UUID.randomUUID().toString());
fields.put("source_ip", "127.0.0.1");
fields.put("src_ip", "127.0.0.1");
fields.put("destination_ip", "127.0.0.1");
fields.put("dest_ip", "127.0.0.1");
fields.put("gl2_test", "127.0.0.1");
Message message = new Message(fields);
List<String> ipFields = engine.getIpAddressFields(message);
// without enforcing the Graylog Schema, all but the gl2_* fields should be returned.
Assertions.assertEquals(5, ipFields.size());
}
use of org.graylog2.plugin.Message in project graylog2-server by Graylog2.
the class MessagesAdapterES6Test method bulkIndexingParsesIndexMappingErrors.
@Test
public void bulkIndexingParsesIndexMappingErrors() throws Exception {
final String messageId = "BOOMID";
final BulkResult jestResult = mock(BulkResult.class);
final BulkResult.BulkResultItem bulkResultItem = new MockedBulkResult().createResultItem("index", "someindex", "message", messageId, 400, "{\"type\":\"mapper_parsing_exception\",\"reason\":\"failed to parse [http_response_code]\",\"caused_by\":{\"type\":\"number_format_exception\",\"reason\":\"For input string: \\\"FOOBAR\\\"\"}}", null, "mapper_parsing_exception", "failed to parse [http_response_code]");
when(jestResult.isSucceeded()).thenReturn(false);
when(jestResult.getFailedItems()).thenReturn(ImmutableList.of(bulkResultItem));
when(jestClient.execute(any())).thenReturn(jestResult).thenThrow(new IllegalStateException("JestResult#execute should not be called twice."));
final List<IndexingRequest> messageList = messageListWith(messageWithId(messageId));
final List<Messages.IndexingError> result = messagesAdapter.bulkIndex(messageList);
assertThat(result).hasSize(1).extracting(indexingError -> indexingError.message().getId(), Messages.IndexingError::errorType, Messages.IndexingError::errorMessage).containsExactly(tuple(messageId, Messages.IndexingError.ErrorType.MappingError, "failed to parse [http_response_code]"));
}
use of org.graylog2.plugin.Message in project graylog2-server by Graylog2.
the class MessagesES6IT method getResultDoesNotContainJestMetadataFields.
@Test
public void getResultDoesNotContainJestMetadataFields() throws Exception {
final String index = client().createRandomIndex("random");
final Map<String, Object> source = new HashMap<>();
source.put("message", "message");
source.put("source", "source");
source.put("timestamp", "2017-04-13 15:29:00.000");
assertThat(indexMessage(index, source, "1")).isTrue();
final ResultMessage resultMessage = messages.get("1", index);
final Message message = resultMessage.getMessage();
assertThat(message).isNotNull();
assertThat(message.hasField(JestResult.ES_METADATA_ID)).isFalse();
assertThat(message.hasField(JestResult.ES_METADATA_VERSION)).isFalse();
}
use of org.graylog2.plugin.Message in project graylog2-server by Graylog2.
the class ScrollResultES6IT method nextChunkDoesNotContainJestMetadata.
@Test
public void nextChunkDoesNotContainJestMetadata() throws IOException {
importFixture("ScrollResultIT.json");
final String query = SearchSourceBuilder.searchSource().query(matchAllQuery()).toString();
final Search request = new Search.Builder(query).addIndex(INDEX_NAME).addType(IndexMapping.TYPE_MESSAGE).setParameter(Parameters.SCROLL, "1m").setParameter(Parameters.SIZE, 5).build();
final SearchResult searchResult = JestUtils.execute(jestClient(elasticsearch), request, () -> "Exception");
assertThat(jestClient(elasticsearch)).isNotNull();
final ScrollResult scrollResult = new ScrollResultES6(jestClient(elasticsearch), objectMapper, searchResult, "*", Collections.singletonList("message"), -1);
scrollResult.nextChunk().getMessages().forEach(message -> assertThat(message.getMessage().getFields()).doesNotContainKeys("es_metadata_id", "es_metadata_version"));
scrollResult.nextChunk().getMessages().forEach(message -> assertThat(message.getMessage().getFields()).doesNotContainKeys("es_metadata_id", "es_metadata_version"));
assertThat(scrollResult.nextChunk()).isNull();
}
use of org.graylog2.plugin.Message in project graylog2-server by Graylog2.
the class JestUtilsTest method executeFailsWithCustomMessage.
@Test
public void executeFailsWithCustomMessage() throws Exception {
final Ping request = new Ping.Builder().build();
final JestResult resultMock = mock(JestResult.class);
when(resultMock.isSucceeded()).thenReturn(false);
final ObjectNode responseStub = objectMapper.createObjectNode();
final ObjectNode errorStub = objectMapper.createObjectNode();
responseStub.set("Message", new TextNode("Authorization header requires 'Credential' parameter."));
errorStub.set("error", responseStub);
when(resultMock.getJsonObject()).thenReturn(errorStub);
when(clientMock.execute(request)).thenReturn(resultMock);
try {
JestUtils.execute(clientMock, request, () -> "BOOM");
fail("Expected ElasticsearchException to be thrown");
} catch (ElasticsearchException e) {
assertThat(e).hasMessageStartingWith("BOOM").hasMessageEndingWith("{\"Message\":\"Authorization header requires 'Credential' parameter.\"}").hasNoSuppressedExceptions();
assertThat(e.getErrorDetails()).containsExactly("{\"Message\":\"Authorization header requires 'Credential' parameter.\"}");
}
}
Aggregations