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);
}
}
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;
}
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();
}
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();
}
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();
}
Aggregations