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);
}
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);
}
}
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);
}
}
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);
}
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);
}
Aggregations