Refine search
@GET @Path("/{id}") @RequiresPermissions(SidecarRestPermissions.CONFIGURATIONS_READ) @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "Show configuration details") public Configuration getConfigurations(@ApiParam(name = "id", required = true) @PathParam("id") String id) { final Configuration configuration = this.configurationService.find(id); if (configuration == null) { throw new NotFoundException("Could not find Configuration <" + id + ">."); } return configuration; }
@PUT @Timed @Path("/configurations") @ApiOperation(value = "Assign configurations to sidecars") @RequiresPermissions(SidecarRestPermissions.SIDECARS_UPDATE) @AuditEvent(type = SidecarAuditEventTypes.SIDECAR_UPDATE) public Response assignConfiguration(@ApiParam(name = "JSON body", required = true) @Valid @NotNull NodeConfigurationRequest request) throws NotFoundException { List<String> nodeIdList = request.nodes().stream() .filter(distinctByKey(NodeConfiguration::nodeId)) .map(NodeConfiguration::nodeId) .collect(Collectors.toList()); for (String nodeId : nodeIdList) { List<ConfigurationAssignment> nodeRelations = request.nodes().stream() .filter(a -> a.nodeId().equals(nodeId)) .flatMap(a -> a.assignments().stream()) .collect(Collectors.toList()); try { Sidecar sidecar = sidecarService.assignConfiguration(nodeId, nodeRelations); sidecarService.save(sidecar); } catch (org.graylog2.database.NotFoundException e) { throw new NotFoundException(e.getMessage()); } } return Response.accepted().build(); }
private RetentionStrategyDescription getRetentionStrategyDescription(@ApiParam(name = "strategy", value = "The name of the retention strategy", required = true) @PathParam("strategy") @NotEmpty String strategyName) { final Provider<RetentionStrategy> provider = retentionStrategies.get(strategyName); if (provider == null) { throw new NotFoundException("Couldn't find retention strategy for given type " + strategyName); } final RetentionStrategy retentionStrategy = provider.get(); final RetentionStrategyConfig defaultConfig = retentionStrategy.defaultConfiguration(); final SchemaFactoryWrapper visitor = new SchemaFactoryWrapper(); try { objectMapper.acceptJsonFormatVisitor(objectMapper.constructType(retentionStrategy.configurationClass()), visitor); } catch (JsonMappingException e) { throw new InternalServerErrorException("Couldn't generate JSON schema for retention strategy " + strategyName, e); } return RetentionStrategyDescription.create(strategyName, defaultConfig, visitor.finalSchema()); } }
@GET @Path("/{id}") @RequiresPermissions(SidecarRestPermissions.COLLECTORS_READ) @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "Show collector details") public Collector getCollector(@ApiParam(name = "id", required = true) @PathParam("id") String id) { final Collector collector = this.collectorService.find(id); if (collector == null) { throw new NotFoundException("Cound not find collector <" + id + ">."); } return collector; }
@POST @Path("/parse") @Timed @Consumes(MediaType.APPLICATION_JSON) @ApiOperation(value = "Parse a raw message") @ApiResponses(value = { @ApiResponse(code = 404, message = "Specified codec does not exist."), @ApiResponse(code = 400, message = "Could not decode message.") }) @NoAuditEvent("only used to parse a test message") public ResultMessage parse(@ApiParam(name = "JSON body", required = true) MessageParseRequest request) { Codec codec; try { final Configuration configuration = new Configuration(request.configuration()); codec = codecFactory.create(request.codec(), configuration); } catch (IllegalArgumentException e) { throw new NotFoundException(e); } final ResolvableInetSocketAddress remoteAddress = ResolvableInetSocketAddress.wrap(new InetSocketAddress(request.remoteAddress(), 1234)); final RawMessage rawMessage = new RawMessage(0, new UUID(), Tools.nowUTC(), remoteAddress, request.message().getBytes(StandardCharsets.UTF_8)); final Message message = decodeMessage(codec, remoteAddress, rawMessage); return ResultMessage.createFromMessage(message); }
@AuditEvent(type = AuditEventTypes.STATIC_FIELD_CREATE) public Response create(@ApiParam(name = "inputId", required = true) @PathParam("inputId") String inputId, @ApiParam(name = "JSON body", required = true) @Valid @NotNull CreateStaticFieldRequest csfr) throws NotFoundException, ValidationException { final String msg = "Input <" + inputId + "> not found."; LOG.error(msg); throw new javax.ws.rs.NotFoundException(msg);
@DELETE @Path("{username}") @RequiresPermissions(USERS_EDIT) @ApiOperation("Removes a user account.") @ApiResponses({@ApiResponse(code = 400, message = "When attempting to remove a read only user (e.g. built-in or LDAP user).")}) @AuditEvent(type = AuditEventTypes.USER_DELETE) public void deleteUser(@ApiParam(name = "username", value = "The name of the user to delete.", required = true) @PathParam("username") String username) { if (userService.delete(username) == 0) { throw new NotFoundException("Couldn't find user " + username); } }
@ApiResponse(code = 500, message = "Memory appender is broken.") }) @Path("/messages/recent") @Produces(MediaType.APPLICATION_JSON) @RequiresPermissions(RestPermissions.LOGGERSMESSAGES_READ) final Appender appender = getAppender(MEMORY_APPENDER_NAME); if (appender == null) { throw new NotFoundException("Memory appender is disabled. Please refer to the example log4j.xml file.");
@Path("assets/plugin/{plugin}/{filename}") @GET public Response get(@Context Request request, @PathParam("plugin") String pluginName, @PathParam("filename") String filename) { final Plugin plugin = getPluginForName(pluginName) .orElseThrow(() -> new NotFoundException("Couldn't find plugin " + pluginName)); try { final URL resourceUrl = getResourceUri(true, filename, plugin.metadata().getClass()); return getResponse(request, filename, resourceUrl, true); } catch (URISyntaxException | IOException e) { throw new NotFoundException("Couldn't find " + filename + " in plugin " + pluginName, e); } }
@GET @Path("{id}/stats") @Timed @ApiOperation(value = "Get index set statistics") @ApiResponses(value = { @ApiResponse(code = 403, message = "Unauthorized"), @ApiResponse(code = 404, message = "Index set not found"), }) public IndexSetStats indexSetStatistics(@ApiParam(name = "id", required = true) @PathParam("id") String id) { checkPermission(RestPermissions.INDEXSETS_READ, id); return indexSetRegistry.get(id) .map(indexSetStatsCreator::getForIndexSet) .orElseThrow(() -> new NotFoundException("Couldn't load index set with ID <" + id + ">")); }
@GET @Timed @Path("/{index}") @ApiOperation(value = "Get information of an index and its shards.") @Produces(MediaType.APPLICATION_JSON) public IndexInfo single(@ApiParam(name = "index") @PathParam("index") String index) { checkPermission(RestPermissions.INDICES_READ, index); if (!indexSetRegistry.isManagedIndex(index)) { final String msg = "Index [" + index + "] doesn't look like an index managed by Graylog."; LOG.info(msg); throw new NotFoundException(msg); } return indices.getIndexStats(index) .map(this::toIndexInfo) .orElseThrow(() -> new NotFoundException("Index [" + index + "] not found.")); }
@GET @Path("caches/{idOrName}") @ApiOperation(value = "List the given cache") public CacheApi getCache(@ApiParam(name = "idOrName") @PathParam("idOrName") @NotEmpty String idOrName) { Optional<CacheDto> cacheDto = dbCacheService.get(idOrName); if (cacheDto.isPresent()) { checkPermission(RestPermissions.LOOKUP_TABLES_READ, cacheDto.get().id()); return CacheApi.fromDto(cacheDto.get()); } throw new NotFoundException(); }
@GET @Path("adapters/{idOrName}") @ApiOperation(value = "List the given data adapter") public DataAdapterApi getAdapter(@ApiParam(name = "idOrName") @PathParam("idOrName") @NotEmpty String idOrName) { Optional<DataAdapterDto> dataAdapterDto = dbDataAdapterService.get(idOrName); if (dataAdapterDto.isPresent()) { checkPermission(RestPermissions.LOOKUP_TABLES_READ, dataAdapterDto.get().id()); return DataAdapterApi.fromDto(dataAdapterDto.get()); } throw new NotFoundException(); }
@GET @Path("/{route: .*}") public Response asset(@PathParam("route") String route) throws IOException { // Directory traversal should not be possible but just to make sure.. if (route.contains("..")) { throw new BadRequestException("Not allowed to access parent directory"); } final URL resource = classLoader.getResource("swagger/" + route); if (null != resource) { try { final byte[] resourceBytes = Resources.toByteArray(resource); return Response.ok(resourceBytes, mimeTypes.getContentType(route)) .header("Content-Length", resourceBytes.length) .build(); } catch (IOException e) { throw new NotFoundException("Couldn't load " + resource, e); } } else { throw new NotFoundException("Couldn't find " + route); } } }
@GET @Timed @Path("/{metricName}") @ApiOperation(value = "Get a single metric") @ApiResponses(value = { @ApiResponse(code = 404, message = "No such metric") }) @Produces(MediaType.APPLICATION_JSON) public Metric singleMetric(@ApiParam(name = "metricName", required = true) @PathParam("metricName") String metricName) { checkPermission(RestPermissions.METRICS_READ, metricName); final Metric metric = metricRegistry.getMetrics().get(metricName); if (metric == null) { final String msg = "I do not have a metric called [" + metricName + "]."; LOG.debug(msg); throw new NotFoundException(msg); } return metric; }
@GET @Path("/{inputId}") @Timed @ApiOperation(value = "Get input state for specified input id on this node") @ApiResponses(value = { @ApiResponse(code = 404, message = "No such input on this node."), }) public InputStateSummary get(@ApiParam(name = "inputId", required = true) @PathParam("inputId") String inputId) { checkPermission(RestPermissions.INPUTS_READ, inputId); final IOState<MessageInput> inputState = this.inputRegistry.getInputState(inputId); if (inputState == null) { throw new NotFoundException("No input state for input id <" + inputId + "> on this node."); } return getInputStateSummary(inputState); }
@GET @Path("adapters/{name}/query") @ApiOperation(value = "Query a lookup table") @ApiResponses({ @ApiResponse(code = 404, message = "If the adapter cannot be found (if it failed or doesn't exist at all)") }) @RequiresPermissions(RestPermissions.LOOKUP_TABLES_READ) public LookupResult performAdapterLookup(@ApiParam(name = "name") @PathParam("name") @NotEmpty String name, @ApiParam(name = "key") @QueryParam("key") @NotEmpty String key) { final Collection<LookupDataAdapter> dataAdapters = lookupTableService.getDataAdapters(singleton(name)); if (!dataAdapters.isEmpty()) { return Iterables.getOnlyElement(dataAdapters).get(key); } else { throw new NotFoundException("Unable to find data adapter " + name); } }
@Path("process/{id}") @Produces(MediaType.SERVER_SENT_EVENTS) @GET public void getProgress(@PathParam("id") int id, @DefaultValue("false") @QueryParam("testSource") boolean testSource, @Context SseEventSink eventSink) { final Process process = processes.get(id); if (process != null) { if (testSource) { process.release(); } process.getBroadcaster().register(eventSink); } else { throw new NotFoundException(); } }
@GET @Path("{id}") @Timed @ApiOperation(value = "Get index set") @ApiResponses(value = { @ApiResponse(code = 403, message = "Unauthorized"), @ApiResponse(code = 404, message = "Index set not found"), }) public IndexSetSummary get(@ApiParam(name = "id", required = true) @PathParam("id") String id) { checkPermission(RestPermissions.INDEXSETS_READ, id); final IndexSetConfig defaultIndexSet = indexSetService.getDefault(); return indexSetService.get(id) .map(config -> IndexSetSummary.fromIndexSetConfig(config, config.equals(defaultIndexSet))) .orElseThrow(() -> new NotFoundException("Couldn't load index set with ID <" + id + ">")); }
@GET @Path("{indexSetId}") @Timed @ApiOperation("Get index template for the given index set") public IndexTemplateResponse get(@ApiParam(name = "indexSetId") @PathParam("indexSetId") @NotBlank String indexSetId) { checkPermission(RestPermissions.INDEXSETS_READ, indexSetId); final IndexSet indexSet = indexSetRegistry.get(indexSetId) .orElseThrow(() -> new NotFoundException("Index set " + indexSetId + " not found")); return createResponse(indexSet); }