use of org.graylog2.indexer.results.SearchResult in project graylog2-server by Graylog2.
the class SearchesIT method searchDoesNotIncludeJestMetadata.
@Test
public void searchDoesNotIncludeJestMetadata() throws Exception {
importFixture("org/graylog2/indexer/searches/SearchesIT.json");
final AbsoluteRange range = AbsoluteRange.create(new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC).withZone(UTC), new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC).withZone(UTC));
final SearchResult searchResult = searches.search("_id:1", range, 0, 0, Sorting.DEFAULT);
assertThat(searchResult).isNotNull();
assertThat(searchResult.getTotalResults()).isEqualTo(1L);
assertThat(searchResult.getFields()).doesNotContain("es_metadata_id", "es_metadata_version");
}
use of org.graylog2.indexer.results.SearchResult in project graylog2-server by Graylog2.
the class SearchesIT method searchReturnsResultWithSelectiveFields.
@Test
public void searchReturnsResultWithSelectiveFields() throws Exception {
importFixture("org/graylog2/indexer/searches/SearchesIT.json");
final AbsoluteRange range = AbsoluteRange.create(new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC).withZone(UTC), new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC).withZone(UTC));
final SearchesConfig searchesConfig = SearchesConfig.builder().query("*").range(range).limit(1).offset(0).fields(Collections.singletonList("source")).build();
final SearchResult searchResult = searches.search(searchesConfig);
assertThat(searchResult).isNotNull();
assertThat(searchResult.getResults()).hasSize(1);
assertThat(searchResult.getTotalResults()).isEqualTo(10L);
}
use of org.graylog2.indexer.results.SearchResult in project graylog2-server by Graylog2.
the class FieldContentValueAlertConditionTest method testRunNoMatchingMessages.
@Test
public void testRunNoMatchingMessages() throws Exception {
final DateTime now = DateTime.now(DateTimeZone.UTC);
final IndexRange indexRange = MongoIndexRange.create("graylog_test", now.minusDays(1), now, now, 0);
final Set<IndexRange> indexRanges = Sets.newHashSet(indexRange);
final SearchResult searchResult = spy(new SearchResult(Collections.emptyList(), 0L, indexRanges, "message:something", null, 100L));
when(searches.search(anyString(), anyString(), any(RelativeRange.class), anyInt(), anyInt(), any(Sorting.class))).thenReturn(searchResult);
final FieldContentValueAlertCondition condition = getCondition(getParametersMap(0, "message", "something"), alertConditionTitle);
final AlertCondition.CheckResult result = condition.runCheck();
assertNotTriggered(result);
}
use of org.graylog2.indexer.results.SearchResult in project graylog2-server by Graylog2.
the class FieldContentValueAlertConditionTest method testRunMatchingMessagesInStream.
@Test
public void testRunMatchingMessagesInStream() throws Exception {
final ResultMessage searchHit = ResultMessage.parseFromSource("some_id", "graylog_test", Collections.singletonMap("message", "something is in here"));
final DateTime now = DateTime.now(DateTimeZone.UTC);
final IndexRange indexRange = MongoIndexRange.create("graylog_test", now.minusDays(1), now, now, 0);
final Set<IndexRange> indexRanges = Sets.newHashSet(indexRange);
final SearchResult searchResult = spy(new SearchResult(Collections.singletonList(searchHit), 1L, indexRanges, "message:something", null, 100L));
when(searchResult.getTotalResults()).thenReturn(1L);
when(searches.search(anyString(), anyString(), any(RelativeRange.class), anyInt(), anyInt(), any(Sorting.class))).thenReturn(searchResult);
final FieldContentValueAlertCondition condition = getCondition(getParametersMap(0, "message", "something"), "Alert Condition for testing");
final AlertCondition.CheckResult result = condition.runCheck();
assertTriggered(condition, result);
}
use of org.graylog2.indexer.results.SearchResult in project graylog2-server by Graylog2.
the class UnboundLDAPConnector method search.
public ImmutableList<LDAPEntry> search(LDAPConnection connection, String searchBase, Filter filter, String uniqueIdAttribute, Set<String> attributes) throws LDAPException {
final ImmutableSet<String> allAttributes = ImmutableSet.<String>builder().add(OBJECT_CLASS_ATTRIBUTE).addAll(attributes).build();
// TODO: Use LDAPEntrySource for a more memory efficient search
final SearchRequest searchRequest = new SearchRequest(searchBase, SearchScope.SUB, filter, allAttributes.toArray(new String[0]));
searchRequest.setTimeLimitSeconds(requestTimeoutSeconds);
if (LOG.isTraceEnabled()) {
LOG.trace("Search LDAP for <{}> using search base <{}>", filter.toNormalizedString(), searchBase);
}
final SearchResult searchResult = connection.search(searchRequest);
if (searchResult.getSearchEntries().isEmpty()) {
LOG.trace("No LDAP entry found for filter <{}>", filter.toNormalizedString());
return ImmutableList.of();
}
return searchResult.getSearchEntries().stream().map(entry -> createLDAPEntry(entry, uniqueIdAttribute)).collect(ImmutableList.toImmutableList());
}
Aggregations