Search in sources :

Example 61 with NotFoundException

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

the class ExtractorFilter method loadExtractors.

private void loadExtractors(final String inputId) {
    LOG.debug("Re-loading extractors for input <{}>", inputId);
    try {
        final Input input = inputService.find(inputId);
        final List<Extractor> sortedExtractors = inputService.getExtractors(input).stream().sorted((e1, e2) -> e1.getOrder().intValue() - e2.getOrder().intValue()).collect(Collectors.toList());
        extractors.put(inputId, ImmutableList.copyOf(sortedExtractors));
    } catch (NotFoundException e) {
        LOG.warn("Unable to load input <{}>: {}", inputId, e.getMessage());
    }
}
Also used : Extractor(org.graylog2.plugin.inputs.Extractor) InputCreated(org.graylog2.rest.models.system.inputs.responses.InputCreated) Logger(org.slf4j.Logger) InputUpdated(org.graylog2.rest.models.system.inputs.responses.InputUpdated) InputService(org.graylog2.inputs.InputService) LoggerFactory(org.slf4j.LoggerFactory) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Collectors(java.util.stream.Collectors) ConcurrentMap(java.util.concurrent.ConcurrentMap) EventBus(com.google.common.eventbus.EventBus) Inject(javax.inject.Inject) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) InputDeleted(org.graylog2.rest.models.system.inputs.responses.InputDeleted) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Input(org.graylog2.inputs.Input) Subscribe(com.google.common.eventbus.Subscribe) Named(javax.inject.Named) Message(org.graylog2.plugin.Message) Collections(java.util.Collections) NotFoundException(org.graylog2.database.NotFoundException) MessageFilter(org.graylog2.plugin.filters.MessageFilter) Input(org.graylog2.inputs.Input) NotFoundException(org.graylog2.database.NotFoundException) Extractor(org.graylog2.plugin.inputs.Extractor)

Example 62 with NotFoundException

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

the class AlarmCallbackHistoryResource method getForAlert.

@GET
@Timed
@ApiOperation(value = "Get a list of all alarm callbacks for this stream")
@Produces(MediaType.APPLICATION_JSON)
public AlarmCallbackHistoryListSummary getForAlert(@ApiParam(name = "streamid", value = "The id of the stream whose alarm callbacks history we want.", required = true) @PathParam("streamid") String streamid, @ApiParam(name = "alertId", value = "The id of the alert whose callback history we want.", required = true) @PathParam("alertId") String alertId) throws NotFoundException {
    checkPermission(RestPermissions.STREAMS_READ, streamid);
    final List<AlarmCallbackHistory> historyList = this.alarmCallbackHistoryService.getForAlertId(alertId);
    final List<AlarmCallbackHistorySummary> historySummaryList = Lists.newArrayListWithCapacity(historyList.size());
    for (AlarmCallbackHistory alarmCallbackHistory : historyList) {
        historySummaryList.add(AlarmCallbackHistorySummary.create(alarmCallbackHistory.id(), alarmCallbackHistory.alarmcallbackConfiguration(), alarmCallbackHistory.alertId(), alarmCallbackHistory.alertConditionId(), alarmCallbackHistory.result(), alarmCallbackHistory.createdAt()));
    }
    return AlarmCallbackHistoryListSummary.create(historySummaryList);
}
Also used : AlarmCallbackHistory(org.graylog2.alarmcallbacks.AlarmCallbackHistory) AlarmCallbackHistorySummary(org.graylog2.rest.models.alarmcallbacks.AlarmCallbackHistorySummary) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 63 with NotFoundException

use of org.graylog2.database.NotFoundException 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 64 with NotFoundException

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

the class DashboardWidgetsResource method widgetValue.

@GET
@Timed
@ApiOperation(value = "Get a single widget value.")
@Path("/{widgetId}/value")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Dashboard not found."), @ApiResponse(code = 404, message = "Widget not found."), @ApiResponse(code = 504, message = "Computation failed on indexer side.") })
@Produces(MediaType.APPLICATION_JSON)
public Map<String, Object> widgetValue(@ApiParam(name = "dashboardId", required = true) @PathParam("dashboardId") String dashboardId, @ApiParam(name = "widgetId", required = true) @PathParam("widgetId") String widgetId) throws NotFoundException, InvalidWidgetConfigurationException {
    checkPermission(RestPermissions.DASHBOARDS_READ, 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);
    }
    return widgetResultCache.getComputationResultForDashboardWidget(widget).asMap();
}
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) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 65 with NotFoundException

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

the class DashboardWidgetsResource method addWidget.

@POST
@Timed
@ApiOperation(value = "Add a widget to a dashboard")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiResponses(value = { @ApiResponse(code = 404, message = "Dashboard not found."), @ApiResponse(code = 400, message = "Validation error."), @ApiResponse(code = 400, message = "No such widget type.") })
@AuditEvent(type = AuditEventTypes.DASHBOARD_WIDGET_CREATE)
public Response addWidget(@ApiParam(name = "dashboardId", required = true) @PathParam("dashboardId") String dashboardId, @ApiParam(name = "JSON body", required = true) AddWidgetRequest awr) throws ValidationException, NotFoundException {
    checkPermission(RestPermissions.DASHBOARDS_EDIT, dashboardId);
    // Bind to streams for reader users and check stream permission.
    if (awr.config().containsKey("stream_id")) {
        checkPermission(RestPermissions.STREAMS_READ, (String) awr.config().get("stream_id"));
    } else {
        checkPermission(RestPermissions.SEARCHES_ABSOLUTE);
        checkPermission(RestPermissions.SEARCHES_RELATIVE);
        checkPermission(RestPermissions.SEARCHES_KEYWORD);
    }
    final DashboardWidget widget;
    try {
        widget = dashboardWidgetCreator.fromRequest(awr, getCurrentUser().getName());
        final Dashboard dashboard = dashboardService.load(dashboardId);
        dashboardService.addWidget(dashboard, widget);
    } catch (DashboardWidget.NoSuchWidgetTypeException e2) {
        LOG.debug("No such widget type.", e2);
        throw new BadRequestException("No such widget type.", e2);
    } catch (InvalidRangeParametersException e3) {
        LOG.debug("Invalid timerange parameters provided.", e3);
        throw new BadRequestException("Invalid timerange parameters provided.", e3);
    } catch (InvalidWidgetConfigurationException e4) {
        LOG.debug("Invalid widget configuration.", e4);
        throw new BadRequestException("Invalid widget configuration.", e4);
    }
    final Map<String, String> result = ImmutableMap.of("widget_id", widget.getId());
    final URI widgetUri = getUriBuilderToSelf().path(DashboardWidgetsResource.class, "getWidget").build(dashboardId, widget.getId());
    return Response.created(widgetUri).entity(result).build();
}
Also used : InvalidRangeParametersException(org.graylog2.plugin.indexer.searches.timeranges.InvalidRangeParametersException) DashboardWidget(org.graylog2.dashboards.widgets.DashboardWidget) Dashboard(org.graylog2.dashboards.Dashboard) BadRequestException(javax.ws.rs.BadRequestException) InvalidWidgetConfigurationException(org.graylog2.dashboards.widgets.InvalidWidgetConfigurationException) URI(java.net.URI) POST(javax.ws.rs.POST) 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) 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