use of org.graylog2.plugin.alarms.callbacks.AlarmCallback in project graylog2-server by Graylog2.
the class AlarmCallbackConfigurationServiceImplTest method testGetForStreamSingleDocument.
@Test
@UsingDataSet(locations = "alarmCallbackConfigurationsSingleDocument.json", loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void testGetForStreamSingleDocument() throws Exception {
final Stream stream = mock(StreamImpl.class);
final String streamId = "5400deadbeefdeadbeefaffe";
when(stream.getId()).thenReturn(streamId);
final List<AlarmCallbackConfiguration> configs = alarmCallbackConfigurationService.getForStream(stream);
final AlarmCallbackConfiguration alarmCallback = configs.get(0);
assertNotNull("Returned list should not be null", configs);
assertEquals("Returned list should contain a single document", 1, configs.size());
assertNotNull("Returned Alarm Callback should not be null", alarmCallback);
}
use of org.graylog2.plugin.alarms.callbacks.AlarmCallback in project graylog2-server by Graylog2.
the class AlarmCallbackFactoryTest method testCreateByClass.
@Test
public void testCreateByClass() throws Exception {
AlarmCallback alarmCallback = alarmCallbackFactory.create(DummyAlarmCallback.class);
assertTrue(alarmCallback instanceof DummyAlarmCallback);
assertEquals(dummyAlarmCallback, alarmCallback);
}
use of org.graylog2.plugin.alarms.callbacks.AlarmCallback in project graylog2-server by Graylog2.
the class HTTPAlarmCallbackTest method setUp.
@Before
public void setUp() throws Exception {
httpClient = new OkHttpClient();
objectMapper = new ObjectMapperProvider().get();
alarmCallback = new HTTPAlarmCallback(httpClient, objectMapper);
server = new MockWebServer();
}
use of org.graylog2.plugin.alarms.callbacks.AlarmCallback in project graylog2-server by Graylog2.
the class AlarmCallbacksResource method test.
@POST
@Timed
@Path("/{alarmCallbackId}/test")
@ApiOperation(value = "Send a test alert for a given alarm callback")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Alarm callback not found."), @ApiResponse(code = 400, message = "Invalid ObjectId."), @ApiResponse(code = 500, message = "Error while testing alarm callback") })
@NoAuditEvent("only used to test alert notifications")
public Response test(@ApiParam(name = "alarmCallbackId", value = "The alarm callback id to send a test alert for.", required = true) @PathParam("alarmCallbackId") String alarmCallbackId) throws TransportConfigurationException, EmailException, NotFoundException {
final AlarmCallbackConfiguration alarmCallbackConfiguration = alarmCallbackConfigurationService.load(alarmCallbackId);
final String streamId = alarmCallbackConfiguration.getStreamId();
checkPermission(RestPermissions.STREAMS_EDIT, streamId);
final Stream stream = streamService.load(streamId);
final DummyAlertCondition testAlertCondition = new DummyAlertCondition(stream, null, Tools.nowUTC(), getSubject().getPrincipal().toString(), Collections.emptyMap(), "Test Alert");
try {
AbstractAlertCondition.CheckResult checkResult = testAlertCondition.runCheck();
AlarmCallback alarmCallback = alarmCallbackFactory.create(alarmCallbackConfiguration);
alarmCallback.call(stream, checkResult);
} catch (Exception e) {
throw new InternalServerErrorException(e.getMessage(), e);
}
return Response.ok().build();
}
use of org.graylog2.plugin.alarms.callbacks.AlarmCallback in project graylog2-server by Graylog2.
the class AlarmCallbackFactoryTest method testCreateByClassName.
@Test
public void testCreateByClassName() throws Exception {
String className = DummyAlarmCallback.class.getCanonicalName();
AlarmCallback alarmCallback = alarmCallbackFactory.create(className);
assertNotNull(alarmCallback);
assertTrue(alarmCallback instanceof DummyAlarmCallback);
assertEquals(dummyAlarmCallback, alarmCallback);
}
Aggregations