use of org.graylog.plugins.sidecar.rest.models.CollectorActions in project graylog2-server by Graylog2.
the class ActionService method fromRequest.
public CollectorActions fromRequest(String sidecarId, List<CollectorAction> actions) {
CollectorActions collectorActions = findActionBySidecar(sidecarId, false);
if (collectorActions == null) {
return CollectorActions.create(sidecarId, DateTime.now(DateTimeZone.UTC), actions);
}
List<CollectorAction> updatedActions = new ArrayList<>();
for (final CollectorAction action : actions) {
for (final CollectorAction existingsAction : collectorActions.action()) {
if (!existingsAction.collectorId().equals(action.collectorId())) {
updatedActions.add(existingsAction);
}
}
updatedActions.add(action);
}
return CollectorActions.create(collectorActions.id(), sidecarId, DateTime.now(DateTimeZone.UTC), updatedActions);
}
use of org.graylog.plugins.sidecar.rest.models.CollectorActions in project graylog2-server by Graylog2.
the class SidecarResource method register.
@PUT
@Timed
@Path("/{sidecarId}")
@ApiOperation(value = "Create/update a Sidecar registration", notes = "This is a stateless method which upserts a Sidecar registration")
@ApiResponses(value = { @ApiResponse(code = 400, message = "The supplied request is not valid.") })
@RequiresPermissions(SidecarRestPermissions.SIDECARS_UPDATE)
@NoAuditEvent("this is only a ping from Sidecars, and would overflow the audit log")
public Response register(@ApiParam(name = "sidecarId", value = "The id this Sidecar is registering as.", required = true) @PathParam("sidecarId") @NotEmpty String sidecarId, @ApiParam(name = "JSON body", required = true) @Valid @NotNull RegistrationRequest request, @HeaderParam(value = "X-Graylog-Sidecar-Version") @NotEmpty String sidecarVersion) {
final Sidecar newSidecar;
final Sidecar oldSidecar = sidecarService.findByNodeId(sidecarId);
List<ConfigurationAssignment> assignments = null;
if (oldSidecar != null) {
assignments = oldSidecar.assignments();
newSidecar = oldSidecar.toBuilder().nodeName(request.nodeName()).nodeDetails(request.nodeDetails()).sidecarVersion(sidecarVersion).lastSeen(DateTime.now(DateTimeZone.UTC)).build();
} else {
newSidecar = sidecarService.fromRequest(sidecarId, request, sidecarVersion);
}
sidecarService.save(newSidecar);
final CollectorActions collectorActions = actionService.findActionBySidecar(sidecarId, true);
List<CollectorAction> collectorAction = null;
if (collectorActions != null) {
collectorAction = collectorActions.action();
}
RegistrationResponse sidecarRegistrationResponse = RegistrationResponse.create(SidecarRegistrationConfiguration.create(this.sidecarConfiguration.sidecarUpdateInterval().toStandardDuration().getStandardSeconds(), this.sidecarConfiguration.sidecarSendStatus()), this.sidecarConfiguration.sidecarConfigurationOverride(), collectorAction, assignments);
return Response.accepted(sidecarRegistrationResponse).build();
}
use of org.graylog.plugins.sidecar.rest.models.CollectorActions in project graylog2-server by Graylog2.
the class ActionResource method setAction.
@PUT
@Timed
@Path("/{sidecarId}")
@RequiresPermissions(SidecarRestPermissions.SIDECARS_UPDATE)
@ApiOperation(value = "Set a collector action")
@ApiResponses(value = { @ApiResponse(code = 400, message = "The supplied action is not valid.") })
@AuditEvent(type = SidecarAuditEventTypes.ACTION_UPDATE)
public Response setAction(@ApiParam(name = "sidecarId", value = "The id this Sidecar is registering as.", required = true) @PathParam("sidecarId") @NotEmpty String sidecarId, @ApiParam(name = "JSON body", required = true) @Valid @NotNull List<CollectorAction> request) {
final CollectorActions collectorActions = actionService.fromRequest(sidecarId, request);
actionService.saveAction(collectorActions);
return Response.accepted().build();
}
use of org.graylog.plugins.sidecar.rest.models.CollectorActions 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