Search in sources :

Example 6 with AlarmCallback

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);
}
Also used : Stream(org.graylog2.plugin.streams.Stream) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) MongoDBServiceTest(org.graylog2.database.MongoDBServiceTest) Test(org.junit.Test)

Example 7 with 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);
}
Also used : AlarmCallback(org.graylog2.plugin.alarms.callbacks.AlarmCallback) Test(org.junit.Test)

Example 8 with 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();
}
Also used : OkHttpClient(okhttp3.OkHttpClient) MockWebServer(okhttp3.mockwebserver.MockWebServer) ObjectMapperProvider(org.graylog2.shared.bindings.providers.ObjectMapperProvider) Before(org.junit.Before)

Example 9 with AlarmCallback

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();
}
Also used : InternalServerErrorException(javax.ws.rs.InternalServerErrorException) Stream(org.graylog2.plugin.streams.Stream) EmailAlarmCallback(org.graylog2.alarmcallbacks.EmailAlarmCallback) AlarmCallback(org.graylog2.plugin.alarms.callbacks.AlarmCallback) AbstractAlertCondition(org.graylog2.alerts.AbstractAlertCondition) DummyAlertCondition(org.graylog2.alerts.types.DummyAlertCondition) TransportConfigurationException(org.graylog2.plugin.alarms.transports.TransportConfigurationException) NotFoundException(org.graylog2.database.NotFoundException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) EmailException(org.apache.commons.mail.EmailException) AlarmCallbackConfiguration(org.graylog2.alarmcallbacks.AlarmCallbackConfiguration) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent)

Example 10 with AlarmCallback

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);
}
Also used : AlarmCallback(org.graylog2.plugin.alarms.callbacks.AlarmCallback) Test(org.junit.Test)

Aggregations

AlarmCallback (org.graylog2.plugin.alarms.callbacks.AlarmCallback)10 AlarmCallbackConfiguration (org.graylog2.alarmcallbacks.AlarmCallbackConfiguration)6 Stream (org.graylog2.plugin.streams.Stream)6 Test (org.junit.Test)6 Timed (com.codahale.metrics.annotation.Timed)4 ApiOperation (io.swagger.annotations.ApiOperation)4 Path (javax.ws.rs.Path)4 ApiResponses (io.swagger.annotations.ApiResponses)3 POST (javax.ws.rs.POST)3 EmailAlarmCallback (org.graylog2.alarmcallbacks.EmailAlarmCallback)3 NoAuditEvent (org.graylog2.audit.jersey.NoAuditEvent)3 AlertCondition (org.graylog2.plugin.alarms.AlertCondition)3 BadRequestException (javax.ws.rs.BadRequestException)2 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)2 ObjectId (org.bson.types.ObjectId)2 AbstractAlertCondition (org.graylog2.alerts.AbstractAlertCondition)2 DummyAlertCondition (org.graylog2.alerts.types.DummyAlertCondition)2 ImmutableList (com.google.common.collect.ImmutableList)1 UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)1 BasicDBObject (com.mongodb.BasicDBObject)1