Search in sources :

Example 26 with NotFoundException

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

the class DashboardsResource method update.

@PUT
@Timed
@ApiOperation(value = "Update the settings of a dashboard.")
@Produces(MediaType.APPLICATION_JSON)
@Path("/{dashboardId}")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Dashboard not found.") })
@AuditEvent(type = AuditEventTypes.DASHBOARD_UPDATE)
public void update(@ApiParam(name = "dashboardId", required = true) @PathParam("dashboardId") String dashboardId, @ApiParam(name = "JSON body", required = true) UpdateDashboardRequest cr) throws ValidationException, NotFoundException {
    checkPermission(RestPermissions.DASHBOARDS_EDIT, dashboardId);
    final Dashboard dashboard = dashboardService.load(dashboardId);
    if (cr.title() != null) {
        dashboard.setTitle(cr.title());
    }
    if (cr.description() != null) {
        dashboard.setDescription(cr.description());
    }
    // Validations are happening here.
    dashboardService.save(dashboard);
}
Also used : Dashboard(org.graylog2.dashboards.Dashboard) 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 27 with NotFoundException

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

the class StreamAlarmCallbackResource method delete.

@DELETE
@Path("/{alarmCallbackId}")
@Timed
@ApiOperation(value = "Delete an alarm callback")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Alarm callback not found."), @ApiResponse(code = 400, message = "Invalid ObjectId.") })
@AuditEvent(type = AuditEventTypes.ALARM_CALLBACK_DELETE)
public void delete(@ApiParam(name = "streamid", value = "The stream id this alarm callback belongs to.", required = true) @PathParam("streamid") String streamid, @ApiParam(name = "alarmCallbackId", required = true) @PathParam("alarmCallbackId") String alarmCallbackId) throws NotFoundException {
    checkPermission(RestPermissions.STREAMS_EDIT, streamid);
    final Stream stream = streamService.load(streamid);
    final AlarmCallbackConfiguration result = alarmCallbackConfigurationService.load(alarmCallbackId);
    if (result == null || !result.getStreamId().equals(stream.getId())) {
        throw new javax.ws.rs.NotFoundException("Couldn't find alarm callback " + alarmCallbackId + " in for steam " + streamid);
    }
    if (alarmCallbackConfigurationService.destroy(result) == 0) {
        final String msg = "Couldn't remove alarm callback with ID " + result.getId();
        LOG.error(msg);
        throw new InternalServerErrorException(msg);
    }
}
Also used : NotFoundException(org.graylog2.database.NotFoundException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) Stream(org.graylog2.plugin.streams.Stream) AlarmCallbackConfiguration(org.graylog2.alarmcallbacks.AlarmCallbackConfiguration) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) ApiResponses(io.swagger.annotations.ApiResponses)

Example 28 with NotFoundException

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

the class StreamAlarmCallbackResource method update.

@PUT
@Path("/{alarmCallbackId}")
@Timed
@ApiOperation(value = "Update an alarm callback")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@AuditEvent(type = AuditEventTypes.ALARM_CALLBACK_UPDATE)
public void update(@ApiParam(name = "streamid", value = "The stream id this alarm callback belongs to.", required = true) @PathParam("streamid") String streamid, @ApiParam(name = "alarmCallbackId", required = true) @PathParam("alarmCallbackId") String alarmCallbackId, @ApiParam(name = "JSON body", required = true) CreateAlarmCallbackRequest alarmCallbackRequest) throws NotFoundException {
    checkPermission(RestPermissions.STREAMS_EDIT, streamid);
    final AlarmCallbackConfiguration callbackConfiguration = alarmCallbackConfigurationService.load(alarmCallbackId);
    if (callbackConfiguration == null) {
        throw new NotFoundException("Unable to find alarm callback configuration " + alarmCallbackId);
    }
    final Map<String, Object> configuration = convertConfigurationValues(alarmCallbackRequest);
    final AlarmCallbackConfiguration updatedConfig = ((AlarmCallbackConfigurationImpl) callbackConfiguration).toBuilder().setTitle(alarmCallbackRequest.title()).setConfiguration(configuration).build();
    try {
        alarmCallbackFactory.create(updatedConfig).checkConfiguration();
        alarmCallbackConfigurationService.save(updatedConfig);
    } catch (ValidationException | AlarmCallbackConfigurationException | ConfigurationException e) {
        LOG.error("Invalid alarm callback configuration.", e);
        throw new BadRequestException(e.getMessage(), e);
    } catch (ClassNotFoundException e) {
        LOG.error("Invalid alarm callback type.", e);
        throw new BadRequestException("Invalid alarm callback type.", e);
    }
}
Also used : ValidationException(org.graylog2.plugin.database.ValidationException) AlarmCallbackConfigurationException(org.graylog2.plugin.alarms.callbacks.AlarmCallbackConfigurationException) ConfigurationException(org.graylog2.plugin.configuration.ConfigurationException) NotFoundException(org.graylog2.database.NotFoundException) BadRequestException(javax.ws.rs.BadRequestException) AlarmCallbackConfiguration(org.graylog2.alarmcallbacks.AlarmCallbackConfiguration) AlarmCallbackConfigurationException(org.graylog2.plugin.alarms.callbacks.AlarmCallbackConfigurationException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) 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)

Example 29 with NotFoundException

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

the class AlertResource method listPaginated.

@GET
@Timed
@Path("paginated")
@ApiOperation(value = "Get alarms of all streams, filtered by specifying limit and offset parameters.")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid ObjectId.") })
public AlertListSummary listPaginated(@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, @ApiParam(name = "state", value = "Alert state (resolved/unresolved)", required = false) @QueryParam("state") String state) throws NotFoundException {
    final List<String> allowedStreamIds = getAllowedStreamIds();
    AlertState alertState;
    try {
        alertState = AlertState.fromString(state);
    } catch (IllegalArgumentException e) {
        alertState = AlertState.ANY;
    }
    final Stream<Alert> alertsStream = alertService.listForStreamIds(allowedStreamIds, alertState, skip, limit).stream();
    final List<AlertSummary> alerts = getAlertSummaries(alertsStream);
    return AlertListSummary.create(alertService.totalCountForStreams(allowedStreamIds, alertState), alerts);
}
Also used : Alert(org.graylog2.alerts.Alert) AlertSummary(org.graylog2.rest.models.streams.alerts.AlertSummary) AlertState(org.graylog2.alerts.Alert.AlertState) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 30 with NotFoundException

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

the class AlertResource method listRecent.

@GET
@Timed
@ApiOperation(value = "Get the most recent alarms of all streams.")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid ObjectId.") })
public AlertListSummary listRecent(@ApiParam(name = "since", value = "Optional parameter to define a lower date boundary. (UNIX timestamp)", required = false) @QueryParam("since") @DefaultValue("0") @Min(0) int sinceTs, @ApiParam(name = "limit", value = "Maximum number of alerts to return.", required = false) @QueryParam("limit") @DefaultValue("300") @Min(1) int limit) throws NotFoundException {
    final DateTime since = new DateTime(sinceTs * 1000L, DateTimeZone.UTC);
    final List<AlertSummary> alerts = getAlertSummaries(alertService.loadRecentOfStreams(getAllowedStreamIds(), since, limit).stream());
    return AlertListSummary.create(alerts.size(), alerts);
}
Also used : AlertSummary(org.graylog2.rest.models.streams.alerts.AlertSummary) DateTime(org.joda.time.DateTime) 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