use of org.graylog.plugins.sidecar.rest.models.Collector in project graylog2-server by Graylog2.
the class V20180212165000_AddDefaultCollectors method ensureCollector.
@Nullable
private String ensureCollector(String collectorName, String serviceType, String nodeOperatingSystem, String executablePath, String executeParameters, String validationCommand, String defaultTemplate) {
Collector collector = null;
try {
collector = collectorService.findByNameAndOs(collectorName, nodeOperatingSystem);
if (collector == null) {
final String msg = "Couldn't find collector '{} on {}' fixing it.";
LOG.error(msg, collectorName, nodeOperatingSystem);
throw new IllegalArgumentException();
}
} catch (IllegalArgumentException ignored) {
LOG.info("{} collector on {} is missing, adding it.", collectorName, nodeOperatingSystem);
final Collector newCollector;
newCollector = Collector.create(null, collectorName, serviceType, nodeOperatingSystem, executablePath, executeParameters, validationCommand, defaultTemplate);
try {
return collectorService.save(newCollector).id();
} catch (Exception e) {
LOG.error("Can't save collector " + collectorName + ", please restart Graylog to fix this.", e);
}
}
if (collector == null) {
LOG.error("Unable to access fixed " + collectorName + " collector, please restart Graylog to fix this.");
return null;
}
return collector.id();
}
use of org.graylog.plugins.sidecar.rest.models.Collector in project graylog2-server by Graylog2.
the class CollectorResource method listSummary.
@GET
@Path("/summary")
@RequiresPermissions(SidecarRestPermissions.COLLECTORS_READ)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "List a summary of all collectors")
public CollectorSummaryResponse listSummary(@ApiParam(name = "page") @QueryParam("page") @DefaultValue("1") int page, @ApiParam(name = "per_page") @QueryParam("per_page") @DefaultValue("50") int perPage, @ApiParam(name = "query") @QueryParam("query") @DefaultValue("") String query, @ApiParam(name = "sort", value = "The field to sort the result on", required = true, allowableValues = "name,id,collector_id") @DefaultValue(Collector.FIELD_NAME) @QueryParam("sort") String sort, @ApiParam(name = "order", value = "The sort direction", allowableValues = "asc, desc") @DefaultValue("asc") @QueryParam("order") String order) {
final SearchQuery searchQuery = searchQueryParser.parse(query);
final PaginatedList<Collector> collectors = this.collectorService.findPaginated(searchQuery, page, perPage, sort, order);
final long total = this.collectorService.count();
final List<CollectorSummary> summaries = collectors.stream().map(CollectorSummary::create).collect(Collectors.toList());
return CollectorSummaryResponse.create(query, collectors.pagination(), total, sort, order, summaries);
}
use of org.graylog.plugins.sidecar.rest.models.Collector in project graylog2-server by Graylog2.
the class CollectorResource method updateCollector.
@PUT
@Path("/{id}")
@RequiresPermissions(SidecarRestPermissions.COLLECTORS_UPDATE)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update a collector")
@AuditEvent(type = SidecarAuditEventTypes.COLLECTOR_UPDATE)
public Response updateCollector(@ApiParam(name = "id", required = true) @PathParam("id") String id, @ApiParam(name = "JSON body", required = true) @Valid @NotNull Collector request) throws BadRequestException {
Collector collector = collectorService.fromRequest(id, request);
final ValidationResult validationResult = validate(collector);
if (validationResult.failed()) {
return Response.status(Response.Status.BAD_REQUEST).entity(validationResult).build();
}
etagService.invalidateAll();
return Response.ok().entity(collectorService.save(collector)).build();
}
use of org.graylog.plugins.sidecar.rest.models.Collector in project graylog2-server by Graylog2.
the class CollectorResource method listCollectors.
@GET
@Timed
@RequiresPermissions(SidecarRestPermissions.COLLECTORS_READ)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "List all collectors")
public Response listCollectors(@Context HttpHeaders httpHeaders) {
String ifNoneMatch = httpHeaders.getHeaderString("If-None-Match");
Boolean etagCached = false;
Response.ResponseBuilder builder = Response.noContent();
// check if client is up to date with a known valid etag
if (ifNoneMatch != null) {
EntityTag etag = new EntityTag(ifNoneMatch.replaceAll("\"", ""));
if (etagService.isPresent(etag.toString())) {
etagCached = true;
builder = Response.notModified();
builder.tag(etag);
}
}
// fetch collector list from database if client is outdated
if (!etagCached) {
final List<Collector> result = this.collectorService.all();
CollectorListResponse collectorListResponse = CollectorListResponse.create(result.size(), result);
// add new etag to cache
String etagString = collectorsToEtag(collectorListResponse);
EntityTag collectorsEtag = new EntityTag(etagString);
builder = Response.ok(collectorListResponse);
builder.tag(collectorsEtag);
etagService.put(collectorsEtag.toString());
}
// set cache control
CacheControl cacheControl = new CacheControl();
cacheControl.setNoTransform(true);
cacheControl.setPrivate(true);
builder.cacheControl(cacheControl);
return builder.build();
}
use of org.graylog.plugins.sidecar.rest.models.Collector in project graylog2-server by Graylog2.
the class AdministrationResource method setAction.
@PUT
@Timed
@Path("/action")
@RequiresPermissions(SidecarRestPermissions.SIDECARS_UPDATE)
@ApiOperation(value = "Set collector actions in bulk")
@ApiResponses(value = { @ApiResponse(code = 400, message = "The supplied action is not valid.") })
@AuditEvent(type = SidecarAuditEventTypes.ACTION_UPDATE)
public Response setAction(@ApiParam(name = "JSON body", required = true) @Valid @NotNull BulkActionsRequest request) {
for (BulkActionRequest bulkActionRequest : request.collectors()) {
final List<CollectorAction> actions = bulkActionRequest.collectorIds().stream().map(collectorId -> CollectorAction.create(collectorId, request.action())).collect(Collectors.toList());
final CollectorActions collectorActions = actionService.fromRequest(bulkActionRequest.sidecarId(), actions);
actionService.saveAction(collectorActions);
}
return Response.accepted().build();
}
Aggregations