Search in sources :

Example 96 with Result

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

the class HTTPAlarmCallback method call.

@Override
public void call(final Stream stream, final AlertCondition.CheckResult result) throws AlarmCallbackException {
    final Map<String, Object> event = Maps.newHashMap();
    event.put("stream", stream);
    event.put("check_result", result);
    final byte[] body;
    try {
        body = objectMapper.writeValueAsBytes(event);
    } catch (JsonProcessingException e) {
        throw new AlarmCallbackException("Unable to serialize alarm", e);
    }
    final String url = configuration.getString(CK_URL);
    final HttpUrl httpUrl = HttpUrl.parse(url);
    if (httpUrl == null) {
        throw new AlarmCallbackException("Malformed URL: " + url);
    }
    final Request request = new Request.Builder().url(httpUrl).post(RequestBody.create(CONTENT_TYPE, body)).build();
    try (final Response r = httpClient.newCall(request).execute()) {
        if (!r.isSuccessful()) {
            throw new AlarmCallbackException("Expected successful HTTP response [2xx] but got [" + r.code() + "].");
        }
    } catch (IOException e) {
        throw new AlarmCallbackException(e.getMessage(), e);
    }
}
Also used : Response(okhttp3.Response) ConfigurationRequest(org.graylog2.plugin.configuration.ConfigurationRequest) Request(okhttp3.Request) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) AlarmCallbackException(org.graylog2.plugin.alarms.callbacks.AlarmCallbackException) HttpUrl(okhttp3.HttpUrl)

Example 97 with Result

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

the class InputStatesResource method stop.

@DELETE
@Path("/{inputId}")
@Timed
@ApiOperation(value = "Stop specified input on this node")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such input on this node.") })
@AuditEvent(type = AuditEventTypes.MESSAGE_INPUT_STOP)
public InputDeleted stop(@ApiParam(name = "inputId", required = true) @PathParam("inputId") String inputId) throws org.graylog2.database.NotFoundException {
    inputService.find(inputId);
    final InputDeleted result = InputDeleted.create(inputId);
    this.serverEventBus.post(result);
    return result;
}
Also used : InputDeleted(org.graylog2.rest.models.system.inputs.responses.InputDeleted) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) ApiResponses(io.swagger.annotations.ApiResponses)

Example 98 with Result

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

the class MongoIndexSetRegistryTest method indexSetsCacheShouldReturnCachedList.

@Test
public void indexSetsCacheShouldReturnCachedList() {
    final IndexSetConfig indexSetConfig = mock(IndexSetConfig.class);
    final List<IndexSetConfig> indexSetConfigs = Collections.singletonList(indexSetConfig);
    when(indexSetService.findAll()).thenReturn(indexSetConfigs);
    final List<IndexSetConfig> result = this.indexSetsCache.get();
    assertThat(result).isNotNull().hasSize(1).containsExactly(indexSetConfig);
    final List<IndexSetConfig> cachedResult = this.indexSetsCache.get();
    assertThat(cachedResult).isNotNull().hasSize(1).containsExactly(indexSetConfig);
    verify(indexSetService, times(1)).findAll();
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) Test(org.junit.Test)

Example 99 with Result

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

the class MongoIndexSetRegistryTest method indexSetsCacheShouldBeInvalidatedForIndexSetDeletion.

@Test
public void indexSetsCacheShouldBeInvalidatedForIndexSetDeletion() {
    final IndexSetConfig indexSetConfig = mock(IndexSetConfig.class);
    final List<IndexSetConfig> indexSetConfigs = Collections.singletonList(indexSetConfig);
    when(indexSetService.findAll()).thenReturn(indexSetConfigs);
    final List<IndexSetConfig> result = this.indexSetsCache.get();
    assertThat(result).isNotNull().hasSize(1).containsExactly(indexSetConfig);
    this.indexSetsCache.handleIndexSetDeletion(mock(IndexSetDeletedEvent.class));
    final IndexSetConfig newIndexSetConfig = mock(IndexSetConfig.class);
    final List<IndexSetConfig> newIndexSetConfigs = Collections.singletonList(newIndexSetConfig);
    when(indexSetService.findAll()).thenReturn(newIndexSetConfigs);
    final List<IndexSetConfig> newResult = this.indexSetsCache.get();
    assertThat(newResult).isNotNull().hasSize(1).containsExactly(newIndexSetConfig);
    verify(indexSetService, times(2)).findAll();
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) IndexSetDeletedEvent(org.graylog2.indexer.indexset.events.IndexSetDeletedEvent) Test(org.junit.Test)

Example 100 with Result

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

the class MongoIndexSetRegistryTest method indexSetsCacheShouldReturnNewListAfterInvalidate.

@Test
public void indexSetsCacheShouldReturnNewListAfterInvalidate() {
    final IndexSetConfig indexSetConfig = mock(IndexSetConfig.class);
    final List<IndexSetConfig> indexSetConfigs = Collections.singletonList(indexSetConfig);
    when(indexSetService.findAll()).thenReturn(indexSetConfigs);
    final List<IndexSetConfig> result = this.indexSetsCache.get();
    assertThat(result).isNotNull().hasSize(1).containsExactly(indexSetConfig);
    this.indexSetsCache.invalidate();
    final IndexSetConfig newIndexSetConfig = mock(IndexSetConfig.class);
    final List<IndexSetConfig> newIndexSetConfigs = Collections.singletonList(newIndexSetConfig);
    when(indexSetService.findAll()).thenReturn(newIndexSetConfigs);
    final List<IndexSetConfig> newResult = this.indexSetsCache.get();
    assertThat(newResult).isNotNull().hasSize(1).containsExactly(newIndexSetConfig);
    verify(indexSetService, times(2)).findAll();
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) 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