Search in sources :

Example 21 with NotFoundException

use of org.graylog2.database.NotFoundException in project graylog2-server by Graylog2.

the class StreamAlertResource method sendDummyAlert.

@POST
@Timed
@Path("sendDummyAlert")
@ApiOperation(value = "Send a test mail for a given stream")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Stream not found."), @ApiResponse(code = 400, message = "Invalid ObjectId."), @ApiResponse(code = 400, message = "Stream has no alarm callbacks") })
@NoAuditEvent("only used to test alert emails")
public void sendDummyAlert(@ApiParam(name = "streamId", value = "The stream id the test alert should be sent for.", required = true) @PathParam("streamId") String streamId) throws TransportConfigurationException, EmailException, NotFoundException {
    checkPermission(RestPermissions.STREAMS_EDIT, streamId);
    final Stream stream = streamService.load(streamId);
    final DummyAlertCondition dummyAlertCondition = new DummyAlertCondition(stream, null, Tools.nowUTC(), getSubject().getPrincipal().toString(), Collections.emptyMap(), "Test Alert");
    try {
        AbstractAlertCondition.CheckResult checkResult = dummyAlertCondition.runCheck();
        List<AlarmCallbackConfiguration> callConfigurations = alarmCallbackConfigurationService.getForStream(stream);
        if (callConfigurations.size() == 0) {
            final String message = "Stream has no alarm callbacks, cannot send test alert.";
            LOG.warn(message);
            throw new BadRequestException(message);
        }
        for (AlarmCallbackConfiguration configuration : callConfigurations) {
            AlarmCallback alarmCallback = alarmCallbackFactory.create(configuration);
            alarmCallback.call(stream, checkResult);
        }
    } catch (AlarmCallbackException | ClassNotFoundException | AlarmCallbackConfigurationException e) {
        throw new InternalServerErrorException(e.getMessage(), e);
    }
}
Also used : AlarmCallbackConfigurationException(org.graylog2.plugin.alarms.callbacks.AlarmCallbackConfigurationException) BadRequestException(javax.ws.rs.BadRequestException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) Stream(org.graylog2.plugin.streams.Stream) AlarmCallback(org.graylog2.plugin.alarms.callbacks.AlarmCallback) AbstractAlertCondition(org.graylog2.alerts.AbstractAlertCondition) DummyAlertCondition(org.graylog2.alerts.types.DummyAlertCondition) AlarmCallbackException(org.graylog2.plugin.alarms.callbacks.AlarmCallbackException) 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 22 with NotFoundException

use of org.graylog2.database.NotFoundException in project graylog2-server by Graylog2.

the class StreamAlertResource method list.

@GET
@Timed
@ApiOperation(value = "Get the most recent alarms of this stream.")
@Produces(MediaType.APPLICATION_JSON)
@ApiResponses(value = { @ApiResponse(code = 404, message = "Stream not found."), @ApiResponse(code = 400, message = "Invalid ObjectId.") })
public AlertListSummary list(@ApiParam(name = "streamId", value = "The stream id this new alert condition belongs to.", required = true) @PathParam("streamId") String streamId, @ApiParam(name = "since", value = "Optional parameter to define a lower date boundary. (UNIX timestamp)") @QueryParam("since") @DefaultValue("0") @Min(0) int sinceTs, @ApiParam(name = "limit", value = "Maximum number of alerts to return.") @QueryParam("limit") @DefaultValue("300") @Min(1) int limit) throws NotFoundException {
    checkPermission(RestPermissions.STREAMS_READ, streamId);
    final DateTime since = new DateTime(sinceTs * 1000L, DateTimeZone.UTC);
    final Stream stream = streamService.load(streamId);
    final List<AlertSummary> conditions = toSummaryList(alertService.loadRecentOfStream(stream.getId(), since, limit));
    return AlertListSummary.create(alertService.totalCountForStream(streamId), conditions);
}
Also used : Stream(org.graylog2.plugin.streams.Stream) AlertSummary(org.graylog2.rest.models.streams.alerts.AlertSummary) DateTime(org.joda.time.DateTime) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 23 with NotFoundException

use of org.graylog2.database.NotFoundException in project graylog2-server by Graylog2.

the class StreamAlertResource method listPaginated.

@GET
@Timed
@Path("paginated")
@ApiOperation(value = "Get the alarms of this stream, filtered by specifying limit and offset parameters.")
@Produces(MediaType.APPLICATION_JSON)
@ApiResponses(value = { @ApiResponse(code = 404, message = "Stream not found."), @ApiResponse(code = 400, message = "Invalid ObjectId.") })
public AlertListSummary listPaginated(@ApiParam(name = "streamId", value = "The stream id this new alert condition belongs to.", required = true) @PathParam("streamId") String streamId, @ApiParam(name = "skip", value = "The number of elements to skip (offset).", required = true) @QueryParam("skip") @DefaultValue("0") int skip, @ApiParam(name = "limit", value = "The maximum number of elements to return.", required = true) @QueryParam("limit") @DefaultValue("300") int limit) throws NotFoundException {
    checkPermission(RestPermissions.STREAMS_READ, streamId);
    final Stream stream = streamService.load(streamId);
    final List<AlertSummary> conditions = toSummaryList(alertService.listForStreamId(stream.getId(), skip, limit));
    return AlertListSummary.create(alertService.totalCountForStream(streamId), conditions);
}
Also used : Stream(org.graylog2.plugin.streams.Stream) AlertSummary(org.graylog2.rest.models.streams.alerts.AlertSummary) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 24 with NotFoundException

use of org.graylog2.database.NotFoundException in project graylog2-server by Graylog2.

the class DashboardWidgetsResource method updateDescription.

@Deprecated
@PUT
@Timed
@ApiOperation(value = "Update description of a widget")
@Path("/{widgetId}/description")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Dashboard not found."), @ApiResponse(code = 404, message = "Widget not found.") })
@Produces(MediaType.APPLICATION_JSON)
@AuditEvent(type = AuditEventTypes.DASHBOARD_WIDGET_UPDATE)
public void updateDescription(@ApiParam(name = "dashboardId", required = true) @PathParam("dashboardId") String dashboardId, @ApiParam(name = "widgetId", required = true) @PathParam("widgetId") String widgetId, @ApiParam(name = "JSON body", required = true) @Valid UpdateWidgetRequest uwr) throws ValidationException, NotFoundException {
    checkPermission(RestPermissions.DASHBOARDS_EDIT, dashboardId);
    final Dashboard dashboard = dashboardService.load(dashboardId);
    final DashboardWidget widget = dashboard.getWidget(widgetId);
    if (widget == null) {
        final String msg = "Widget " + widgetId + " on dashboard " + dashboardId + " not found.";
        LOG.error(msg);
        throw new javax.ws.rs.NotFoundException(msg);
    }
    dashboardService.updateWidgetDescription(dashboard, widget, uwr.description());
    LOG.info("Updated description of widget <" + widgetId + "> on dashboard <" + dashboardId + ">. Reason: REST request.");
}
Also used : DashboardWidget(org.graylog2.dashboards.widgets.DashboardWidget) Dashboard(org.graylog2.dashboards.Dashboard) NotFoundException(org.graylog2.database.NotFoundException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 25 with NotFoundException

use of org.graylog2.database.NotFoundException in project graylog2-server by Graylog2.

the class DashboardWidgetsResource method getWidget.

@GET
@Timed
@ApiOperation(value = "Get a widget")
@Path("/{widgetId}")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Dashboard not found."), @ApiResponse(code = 404, message = "Widget not found.") })
@Produces(MediaType.APPLICATION_JSON)
public WidgetSummary getWidget(@ApiParam(name = "dashboardId", required = true) @PathParam("dashboardId") String dashboardId, @ApiParam(name = "widgetId", required = true) @PathParam("widgetId") String widgetId) throws NotFoundException {
    checkPermission(RestPermissions.DASHBOARDS_READ, dashboardId);
    final Dashboard dashboard = dashboardService.load(dashboardId);
    final DashboardWidget widget = dashboard.getWidget(widgetId);
    return WidgetSummary.create(widget.getId(), widget.getDescription(), widget.getType(), widget.getCacheTime(), widget.getCreatorUserId(), widget.getConfig());
}
Also used : DashboardWidget(org.graylog2.dashboards.widgets.DashboardWidget) Dashboard(org.graylog2.dashboards.Dashboard) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

ApiOperation (io.swagger.annotations.ApiOperation)91 Timed (com.codahale.metrics.annotation.Timed)77 Path (javax.ws.rs.Path)75 ApiResponses (io.swagger.annotations.ApiResponses)66 AuditEvent (org.graylog2.audit.jersey.AuditEvent)60 Produces (javax.ws.rs.Produces)44 NotFoundException (org.graylog2.database.NotFoundException)32 GET (javax.ws.rs.GET)30 PUT (javax.ws.rs.PUT)28 BadRequestException (javax.ws.rs.BadRequestException)27 Stream (org.graylog2.plugin.streams.Stream)27 NotFoundException (javax.ws.rs.NotFoundException)26 Consumes (javax.ws.rs.Consumes)21 DELETE (javax.ws.rs.DELETE)21 POST (javax.ws.rs.POST)19 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)15 MessageInput (org.graylog2.plugin.inputs.MessageInput)15 NoAuditEvent (org.graylog2.audit.jersey.NoAuditEvent)11 Input (org.graylog2.inputs.Input)11 ValidationException (org.graylog2.plugin.database.ValidationException)11