Search in sources :

Example 11 with NotificationDto

use of org.graylog.events.notifications.NotificationDto in project graylog2-server by Graylog2.

the class EventNotificationsResource method listNotifications.

@GET
@ApiOperation("List all available notifications")
public PaginatedResponse<NotificationDto> listNotifications(@ApiParam(name = "page") @QueryParam("page") @DefaultValue("1") int page, @ApiParam(name = "per_page") @QueryParam("per_page") @DefaultValue("50") int perPage, @ApiParam(name = "query") @QueryParam("query") @DefaultValue("") String query) {
    final SearchQuery searchQuery = searchQueryParser.parse(query);
    final PaginatedList<NotificationDto> result = dbNotificationService.searchPaginated(searchQuery, notification -> {
        return isPermitted(RestPermissions.EVENT_NOTIFICATIONS_READ, notification.id());
    }, "title", page, perPage);
    return PaginatedResponse.create("notifications", result, query);
}
Also used : SearchQuery(org.graylog2.search.SearchQuery) NotificationDto(org.graylog.events.notifications.NotificationDto) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 12 with NotificationDto

use of org.graylog.events.notifications.NotificationDto in project graylog2-server by Graylog2.

the class EventNotificationsResource method test.

@POST
@Timed
@Path("/{notificationId}/test")
@ApiOperation(value = "Send a test alert for a given event notification")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Event notification not found."), @ApiResponse(code = 500, message = "Error while testing event notification") })
@NoAuditEvent("only used to test event notifications")
public Response test(@ApiParam(name = "notificationId", value = "The event notification id to send a test alert for.", required = true) @PathParam("notificationId") @NotBlank String notificationId) {
    checkPermission(RestPermissions.EVENT_NOTIFICATIONS_EDIT, notificationId);
    final NotificationDto notificationDto = dbNotificationService.get(notificationId).orElseThrow(() -> new NotFoundException("Notification " + notificationId + " doesn't exist"));
    resourceHandler.test(notificationDto, getSubject().getPrincipal().toString());
    return Response.ok().build();
}
Also used : NotificationDto(org.graylog.events.notifications.NotificationDto) NotFoundException(javax.ws.rs.NotFoundException) 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)

Aggregations

NotificationDto (org.graylog.events.notifications.NotificationDto)12 Test (org.junit.Test)5 MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)3 ApiOperation (io.swagger.annotations.ApiOperation)2 NotificationEntity (org.graylog.events.contentpack.entities.NotificationEntity)2 EventDefinitionDto (org.graylog.events.processor.EventDefinitionDto)2 JobDefinitionDto (org.graylog.scheduler.JobDefinitionDto)2 EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)2 EntityV1 (org.graylog2.contentpacks.model.entities.EntityV1)2 NativeEntityDescriptor (org.graylog2.contentpacks.model.entities.NativeEntityDescriptor)2 PasswordAlgorithmFactory (org.graylog2.security.PasswordAlgorithmFactory)2 Permissions (org.graylog2.shared.security.Permissions)2 UserImpl (org.graylog2.users.UserImpl)2 Timed (com.codahale.metrics.annotation.Timed)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ApiResponses (io.swagger.annotations.ApiResponses)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Optional (java.util.Optional)1 GET (javax.ws.rs.GET)1