Search in sources :

Example 71 with Result

use of org.graylog2.plugin.inputs.Extractor.Result in project graylog2-server by Graylog2.

the class UserServiceImpl method loadAllForRole.

@Override
public Collection<User> loadAllForRole(Role role) {
    final String roleId = role.getId();
    final DBObject query = BasicDBObjectBuilder.start(UserImpl.ROLES, new ObjectId(roleId)).get();
    final List<DBObject> result = query(UserImpl.class, query);
    if (result == null || result.isEmpty()) {
        return Collections.emptySet();
    }
    final Set<User> users = Sets.newHashSetWithExpectedSize(result.size());
    for (DBObject dbObject : result) {
        //noinspection unchecked
        users.add(userFactory.create((ObjectId) dbObject.get("_id"), dbObject.toMap()));
    }
    return users;
}
Also used : User(org.graylog2.plugin.database.users.User) ObjectId(org.bson.types.ObjectId) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject)

Example 72 with Result

use of org.graylog2.plugin.inputs.Extractor.Result in project graylog2-server by Graylog2.

the class AlarmCallbackHistoryServiceImplTest method testError.

@Test
public void testError() throws Exception {
    final AlarmCallbackConfiguration alarmCallbackConfiguration = mockAlarmCallbackConfiguration(new Date());
    final Alert alert = mockAlert();
    final AlertCondition alertCondition = mockAlertCondition();
    final String errorMessage = "Dummy Error Message";
    final AlarmCallbackHistory alarmCallbackHistory = this.alarmCallbackHistoryService.error(alarmCallbackConfiguration, alert, alertCondition, errorMessage);
    verifyAlarmCallbackHistory(alarmCallbackHistory, alert, alertCondition);
    assertThat(alarmCallbackHistory.result()).isNotNull().isInstanceOf(AlarmCallbackError.class);
    assertThat(alarmCallbackHistory.result().type()).isEqualTo("error");
    final AlarmCallbackError result = (AlarmCallbackError) alarmCallbackHistory.result();
    assertThat(result.error()).isEqualTo(errorMessage);
}
Also used : AlarmCallbackError(org.graylog2.rest.models.alarmcallbacks.AlarmCallbackError) AlertCondition(org.graylog2.plugin.alarms.AlertCondition) Alert(org.graylog2.alerts.Alert) Date(java.util.Date) MongoDBServiceTest(org.graylog2.database.MongoDBServiceTest) Test(org.junit.Test)

Example 73 with Result

use of org.graylog2.plugin.inputs.Extractor.Result in project graylog2-server by Graylog2.

the class GelfChunkAggregatorTest method missingChunk.

@Test
public void missingChunk() {
    final DateTime initialTime = new DateTime(2014, 1, 1, 1, 59, 59, 0, DateTimeZone.UTC);
    final InstantMillisProvider clock = new InstantMillisProvider(initialTime);
    DateTimeUtils.setCurrentMillisProvider(clock);
    // we don't want the clean up task to run automatically
    poolExecutor = mock(ScheduledThreadPoolExecutor.class);
    final MetricRegistry metricRegistry = new MetricRegistry();
    aggregator = new GelfChunkAggregator(poolExecutor, metricRegistry);
    final GelfChunkAggregator.ChunkEvictionTask evictionTask = aggregator.new ChunkEvictionTask();
    // creates 5 chunks
    final ChannelBuffer[] chunks = createChunkedMessage(4096 + 512, 1024);
    int i = 0;
    for (final ChannelBuffer chunk : chunks) {
        final CodecAggregator.Result result;
        // skip first chunk
        if (i++ == 0) {
            continue;
        }
        result = aggregator.addChunk(chunk);
        assertTrue(result.isValid());
        assertNull("chunks not complete", result.getMessage());
    }
    // move clock forward enough to evict all of the chunks
    clock.tick(Period.seconds(10));
    evictionTask.run();
    final CodecAggregator.Result result = aggregator.addChunk(chunks[0]);
    assertNull("message should not be complete because chunks were evicted already", result.getMessage());
    assertTrue(result.isValid());
    // we send all chunks but the last one comes too late
    assertEquals("no message is complete", 0, counterValueNamed(metricRegistry, COMPLETE_MESSAGES));
    assertEquals("received 5 chunks", 5, counterValueNamed(metricRegistry, CHUNK_COUNTER));
    assertEquals("last chunk creates another waiting message", 1, counterValueNamed(metricRegistry, WAITING_MESSAGES));
    assertEquals("4 chunks expired", 4, counterValueNamed(metricRegistry, EXPIRED_CHUNKS));
    assertEquals("one message expired", 1, counterValueNamed(metricRegistry, EXPIRED_MESSAGES));
    assertEquals("no duplicate chunks", 0, counterValueNamed(metricRegistry, DUPLICATE_CHUNKS));
    // reset clock for other tests
    DateTimeUtils.setCurrentMillisSystem();
}
Also used : CodecAggregator(org.graylog2.plugin.inputs.codecs.CodecAggregator) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) InstantMillisProvider(org.graylog2.plugin.InstantMillisProvider) MetricRegistry(com.codahale.metrics.MetricRegistry) DateTime(org.joda.time.DateTime) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) Test(org.junit.Test)

Example 74 with Result

use of org.graylog2.plugin.inputs.Extractor.Result in project graylog2-server by Graylog2.

the class SearchesTest method testCount.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void testCount() throws Exception {
    CountResult result = searches.count("*", AbsoluteRange.create(new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC)));
    assertThat(result.count()).isEqualTo(10L);
}
Also used : CountResult(org.graylog2.indexer.results.CountResult) ZonedDateTime(java.time.ZonedDateTime) DateTime(org.joda.time.DateTime) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 75 with Result

use of org.graylog2.plugin.inputs.Extractor.Result in project graylog2-server by Graylog2.

the class SearchesTest method testTermsAscending.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void testTermsAscending() throws Exception {
    TermsResult result = searches.terms("n", 1, "*", null, AbsoluteRange.create(new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC)), Sorting.Direction.ASC);
    assertThat(result.getTotal()).isEqualTo(10L);
    assertThat(result.getMissing()).isEqualTo(2L);
    assertThat(result.getTerms()).hasSize(1).containsEntry("4", 1L);
}
Also used : TermsResult(org.graylog2.indexer.results.TermsResult) ZonedDateTime(java.time.ZonedDateTime) DateTime(org.joda.time.DateTime) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)73 Message (org.graylog2.plugin.Message)51 Result (org.graylog2.plugin.inputs.Extractor.Result)27 Callable (java.util.concurrent.Callable)26 Stream (org.graylog2.plugin.streams.Stream)20 StreamRule (org.graylog2.plugin.streams.StreamRule)19 DateTime (org.joda.time.DateTime)18 Timed (com.codahale.metrics.annotation.Timed)13 ApiOperation (io.swagger.annotations.ApiOperation)13 AlertCondition (org.graylog2.plugin.alarms.AlertCondition)12 ApiResponses (io.swagger.annotations.ApiResponses)11 Produces (javax.ws.rs.Produces)9 AuditEvent (org.graylog2.audit.jersey.AuditEvent)9 Function (com.google.common.base.Function)8 UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)8 ZonedDateTime (java.time.ZonedDateTime)8 AbstractAlertCondition (org.graylog2.alerts.AbstractAlertCondition)8 Sorting (org.graylog2.indexer.searches.Sorting)8 URI (java.net.URI)7 MessageSummary (org.graylog2.plugin.MessageSummary)7