Search in sources :

Example 6 with Activity

use of org.graylog2.shared.system.activities.Activity in project graylog2-server by Graylog2.

the class ExtractorsResource method create.

@POST
@Timed
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Add an extractor to an input", response = ExtractorCreated.class)
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such input on this node."), @ApiResponse(code = 400, message = "No such extractor type."), @ApiResponse(code = 400, message = "Field the extractor should write on is reserved."), @ApiResponse(code = 400, message = "Missing or invalid configuration.") })
@AuditEvent(type = AuditEventTypes.EXTRACTOR_CREATE)
public Response create(@ApiParam(name = "inputId", required = true) @PathParam("inputId") String inputId, @ApiParam(name = "JSON body", required = true) @Valid @NotNull CreateExtractorRequest cer) throws NotFoundException {
    checkPermission(RestPermissions.INPUTS_EDIT, inputId);
    final Input mongoInput = inputService.find(inputId);
    final String id = new com.eaio.uuid.UUID().toString();
    final Extractor extractor = buildExtractorFromRequest(cer, id);
    try {
        inputService.addExtractor(mongoInput, extractor);
    } catch (ValidationException e) {
        final String msg = "Extractor persist validation failed.";
        LOG.error(msg, e);
        throw new BadRequestException(msg, e);
    }
    final String msg = "Added extractor <" + id + "> of type [" + cer.extractorType() + "] to input <" + inputId + ">.";
    LOG.info(msg);
    activityWriter.write(new Activity(msg, ExtractorsResource.class));
    final ExtractorCreated result = ExtractorCreated.create(id);
    final URI extractorUri = getUriBuilderToSelf().path(ExtractorsResource.class).path("{inputId}").build(mongoInput.getId());
    return Response.created(extractorUri).entity(result).build();
}
Also used : ExtractorCreated(org.graylog2.rest.models.system.inputs.extractors.responses.ExtractorCreated) Input(org.graylog2.inputs.Input) MessageInput(org.graylog2.plugin.inputs.MessageInput) ValidationException(org.graylog2.plugin.database.ValidationException) BadRequestException(javax.ws.rs.BadRequestException) Activity(org.graylog2.shared.system.activities.Activity) Extractor(org.graylog2.plugin.inputs.Extractor) 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)

Example 7 with Activity

use of org.graylog2.shared.system.activities.Activity in project graylog2-server by Graylog2.

the class DeflectorResource method cycle.

@POST
@Timed
@ApiOperation(value = "Cycle deflector to new/next index in index set")
@RequiresPermissions(RestPermissions.DEFLECTOR_CYCLE)
@Path("/{indexSetId}/cycle")
@RestrictToMaster
@AuditEvent(type = AuditEventTypes.ES_WRITE_INDEX_UPDATE_JOB_START)
public void cycle(@ApiParam(name = "indexSetId") @PathParam("indexSetId") String indexSetId) {
    final IndexSet indexSet = getIndexSet(indexSetRegistry, indexSetId);
    checkCycle(indexSet);
    final String msg = "Cycling deflector for index set <" + indexSetId + ">. Reason: REST request.";
    LOG.info(msg);
    activityWriter.write(new Activity(msg, DeflectorResource.class));
    indexSet.cycle();
}
Also used : Activity(org.graylog2.shared.system.activities.Activity) IndexSet(org.graylog2.indexer.IndexSet) Path(javax.ws.rs.Path) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) RestrictToMaster(org.graylog2.shared.security.RestrictToMaster)

Example 8 with Activity

use of org.graylog2.shared.system.activities.Activity in project graylog2-server by Graylog2.

the class ServerBootstrap method startCommand.

@Override
protected void startCommand() {
    final AuditEventSender auditEventSender = injector.getInstance(AuditEventSender.class);
    final NodeId nodeId = injector.getInstance(NodeId.class);
    final String systemInformation = Tools.getSystemInformation();
    final Map<String, Object> auditEventContext = ImmutableMap.of("version", version.toString(), "java", systemInformation, "node_id", nodeId.toString());
    auditEventSender.success(AuditActor.system(nodeId), NODE_STARTUP_INITIATE, auditEventContext);
    final OS os = OS.getOs();
    LOG.info("Graylog {} {} starting up", commandName, version);
    LOG.info("JRE: {}", systemInformation);
    LOG.info("Deployment: {}", configuration.getInstallationSource());
    LOG.info("OS: {}", os.getPlatformName());
    LOG.info("Arch: {}", os.getArch());
    final ServerStatus serverStatus = injector.getInstance(ServerStatus.class);
    serverStatus.initialize();
    startNodeRegistration(injector);
    final ActivityWriter activityWriter;
    final ServiceManager serviceManager;
    try {
        activityWriter = injector.getInstance(ActivityWriter.class);
        serviceManager = injector.getInstance(ServiceManager.class);
    } catch (ProvisionException e) {
        LOG.error("Guice error", e);
        annotateProvisionException(e);
        auditEventSender.failure(AuditActor.system(nodeId), NODE_STARTUP_INITIATE, auditEventContext);
        System.exit(-1);
        return;
    } catch (Exception e) {
        LOG.error("Unexpected exception", e);
        auditEventSender.failure(AuditActor.system(nodeId), NODE_STARTUP_INITIATE, auditEventContext);
        System.exit(-1);
        return;
    }
    Runtime.getRuntime().addShutdownHook(new Thread(injector.getInstance(shutdownHook())));
    // propagate default size to input plugins
    MessageInput.setDefaultRecvBufferSize(configuration.getUdpRecvBufferSizes());
    // Start services.
    final ServiceManagerListener serviceManagerListener = injector.getInstance(ServiceManagerListener.class);
    serviceManager.addListener(serviceManagerListener);
    try {
        serviceManager.startAsync().awaitHealthy();
    } catch (Exception e) {
        try {
            serviceManager.stopAsync().awaitStopped(configuration.getShutdownTimeout(), TimeUnit.MILLISECONDS);
        } catch (TimeoutException timeoutException) {
            LOG.error("Unable to shutdown properly on time. {}", serviceManager.servicesByState());
        }
        LOG.error("Graylog startup failed. Exiting. Exception was:", e);
        auditEventSender.failure(AuditActor.system(nodeId), NODE_STARTUP_INITIATE, auditEventContext);
        System.exit(-1);
    }
    LOG.info("Services started, startup times in ms: {}", serviceManager.startupTimes());
    activityWriter.write(new Activity("Started up.", Main.class));
    LOG.info("Graylog " + commandName + " up and running.");
    auditEventSender.success(AuditActor.system(nodeId), NODE_STARTUP_COMPLETE, auditEventContext);
    // Block forever.
    try {
        Thread.currentThread().join();
    } catch (InterruptedException e) {
        return;
    }
}
Also used : OS(org.jsoftbiz.utils.OS) Activity(org.graylog2.shared.system.activities.Activity) TimeoutException(java.util.concurrent.TimeoutException) ProvisionException(com.google.inject.ProvisionException) ProvisionException(com.google.inject.ProvisionException) AuditEventSender(org.graylog2.audit.AuditEventSender) ServiceManager(com.google.common.util.concurrent.ServiceManager) ServerStatus(org.graylog2.plugin.ServerStatus) NodeId(org.graylog2.plugin.system.NodeId) ServiceManagerListener(org.graylog2.shared.initializers.ServiceManagerListener) ActivityWriter(org.graylog2.shared.system.activities.ActivityWriter) TimeoutException(java.util.concurrent.TimeoutException)

Example 9 with Activity

use of org.graylog2.shared.system.activities.Activity in project graylog2-server by Graylog2.

the class RebuildIndexRangesJob method info.

protected void info(String what) {
    LOG.info(what);
    activityWriter.write(new Activity(what, RebuildIndexRangesJob.class));
}
Also used : Activity(org.graylog2.shared.system.activities.Activity)

Example 10 with Activity

use of org.graylog2.shared.system.activities.Activity in project graylog2-server by Graylog2.

the class SetIndexReadOnlyJob method execute.

@Override
public void execute() {
    final Optional<IndexSet> indexSet = indexSetRegistry.getForIndex(index);
    if (!indexSet.isPresent()) {
        log.error("Couldn't find index set for index <{}>", index);
        return;
    }
    log.info("Flushing old index <{}>.", index);
    indices.flush(index);
    log.info("Setting old index <{}> to read-only.", index);
    indices.setReadOnly(index);
    activityWriter.write(new Activity("Flushed and set <" + index + "> to read-only.", SetIndexReadOnlyJob.class));
    if (!indexSet.get().getConfig().indexOptimizationDisabled()) {
        try {
            systemJobManager.submit(optimizeIndexJobFactory.create(index, indexSet.get().getConfig().indexOptimizationMaxNumSegments()));
        } catch (SystemJobConcurrencyException e) {
            // The concurrency limit is very high. This should never happen.
            log.error("Cannot optimize index <" + index + ">.", e);
        }
    }
}
Also used : SystemJobConcurrencyException(org.graylog2.system.jobs.SystemJobConcurrencyException) Activity(org.graylog2.shared.system.activities.Activity)

Aggregations

Activity (org.graylog2.shared.system.activities.Activity)23 Timed (com.codahale.metrics.annotation.Timed)9 ApiOperation (io.swagger.annotations.ApiOperation)9 AuditEvent (org.graylog2.audit.jersey.AuditEvent)9 ApiResponses (io.swagger.annotations.ApiResponses)7 Path (javax.ws.rs.Path)7 Produces (javax.ws.rs.Produces)7 MessageInput (org.graylog2.plugin.inputs.MessageInput)6 Input (org.graylog2.inputs.Input)5 Consumes (javax.ws.rs.Consumes)4 DELETE (javax.ws.rs.DELETE)4 POST (javax.ws.rs.POST)4 IndexSet (org.graylog2.indexer.IndexSet)4 Notification (org.graylog2.notifications.Notification)4 BadRequestException (javax.ws.rs.BadRequestException)3 NotFoundException (org.graylog2.database.NotFoundException)3 Extractor (org.graylog2.plugin.inputs.Extractor)3 ActivityWriter (org.graylog2.shared.system.activities.ActivityWriter)3 URI (java.net.URI)2 LinkedHashSet (java.util.LinkedHashSet)2