Search in sources :

Example 1 with Version

use of org.graylog2.plugin.Version in project graylog2-server by Graylog2.

the class CmdLineTool method loadPlugins.

protected Set<Plugin> loadPlugins(String pluginPath, ChainingClassLoader chainingClassLoader) {
    final File pluginDir = new File(pluginPath);
    final Set<Plugin> plugins = new HashSet<>();
    final PluginLoader pluginLoader = new PluginLoader(pluginDir, chainingClassLoader);
    for (Plugin plugin : pluginLoader.loadPlugins()) {
        final PluginMetaData metadata = plugin.metadata();
        if (capabilities().containsAll(metadata.getRequiredCapabilities())) {
            if (version.sameOrHigher(metadata.getRequiredVersion())) {
                LOG.info("Loaded plugin: {}", plugin);
                plugins.add(plugin);
            } else {
                LOG.error("Plugin \"" + metadata.getName() + "\" requires version " + metadata.getRequiredVersion() + " - not loading!");
            }
        } else {
            LOG.debug("Skipping plugin \"{}\" because some capabilities are missing ({}).", metadata.getName(), Sets.difference(plugin.metadata().getRequiredCapabilities(), capabilities()));
        }
    }
    return plugins;
}
Also used : PluginMetaData(org.graylog2.plugin.PluginMetaData) File(java.io.File) PluginLoader(org.graylog2.shared.plugins.PluginLoader) HashSet(java.util.HashSet) Plugin(org.graylog2.plugin.Plugin)

Example 2 with Version

use of org.graylog2.plugin.Version 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();
}
Also used : CollectorActions(org.graylog.plugins.sidecar.rest.models.CollectorActions) ConfigurationAssignment(org.graylog.plugins.sidecar.rest.requests.ConfigurationAssignment) CollectorAction(org.graylog.plugins.sidecar.rest.models.CollectorAction) RegistrationResponse(org.graylog.plugins.sidecar.rest.responses.RegistrationResponse) Sidecar(org.graylog.plugins.sidecar.rest.models.Sidecar) Path(javax.ws.rs.Path) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent)

Example 3 with Version

use of org.graylog2.plugin.Version in project graylog2-server by Graylog2.

the class ContentPackPersistenceService method filterMissingResourcesAndInsert.

public Optional<ContentPack> filterMissingResourcesAndInsert(final ContentPack pack) {
    ContentPackV1 cpv1 = (ContentPackV1) pack;
    final Set<String> allStreams = streamService.loadAll().stream().map(stream -> stream.getTitle()).collect(Collectors.toSet());
    final Map<String, String> streamsInContentPack = new HashMap<>();
    cpv1.entities().stream().filter(entity -> "stream".equals(entity.type().name()) && "1".equals(entity.type().version())).map(entity -> new Tuple2<String, JsonNode>(entity.id().id(), ((EntityV1) entity).data().findValue("title"))).forEach(tuple2 -> {
        JsonNode title = tuple2.v2().findValue("@value");
        streamsInContentPack.put(tuple2.v1(), title.textValue());
    });
    cpv1.entities().stream().filter(entity -> "dashboard".equals(entity.type().name()) && "2".equals(entity.type().version())).map(entity -> ((EntityV1) entity).data().findValue("search")).map(node -> node.findValue("queries")).map(node -> node.findValue("search_types")).forEach(node -> {
        final ObjectNode parent = (ObjectNode) node.findParent("streams");
        final ArrayNode streams = (ArrayNode) node.findValue("streams");
        if (streams != null) {
            final ArrayNode filtered = streams.deepCopy();
            filtered.removeAll();
            streams.forEach(stream -> {
                final String sid = stream.textValue();
                final String stitle = streamsInContentPack.get(sid);
                if (allStreams.contains(stitle))
                    filtered.add(stream);
            });
            parent.replace("streams", filtered);
        }
    });
    return this.insert(cpv1);
}
Also used : DuplicateKeyException(com.mongodb.DuplicateKeyException) Identified(org.graylog2.contentpacks.model.Identified) ContentPack(org.graylog2.contentpacks.model.ContentPack) ContentPackV1(org.graylog2.contentpacks.model.ContentPackV1) LoggerFactory(org.slf4j.LoggerFactory) ImmutableCollection(com.google.common.collect.ImmutableCollection) HashMap(java.util.HashMap) Singleton(javax.inject.Singleton) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Revisioned(org.graylog2.contentpacks.model.Revisioned) WriteResult(org.mongojack.WriteResult) Inject(javax.inject.Inject) HashSet(java.util.HashSet) Tuple2(org.jooq.lambda.tuple.Tuple2) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) NotFoundException(org.graylog2.database.NotFoundException) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) ModelId(org.graylog2.contentpacks.model.ModelId) DBCursor(org.mongojack.DBCursor) BasicDBObject(com.mongodb.BasicDBObject) MongoJackObjectMapperProvider(org.graylog2.bindings.providers.MongoJackObjectMapperProvider) JacksonDBCollection(org.mongojack.JacksonDBCollection) Set(java.util.Set) DBQuery(org.mongojack.DBQuery) Collectors(java.util.stream.Collectors) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) StreamService(org.graylog2.streams.StreamService) ObjectId(org.bson.types.ObjectId) Optional(java.util.Optional) MongoConnection(org.graylog2.database.MongoConnection) Comparator(java.util.Comparator) Collections(java.util.Collections) EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HashMap(java.util.HashMap) Tuple2(org.jooq.lambda.tuple.Tuple2) ContentPackV1(org.graylog2.contentpacks.model.ContentPackV1) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 4 with Version

use of org.graylog2.plugin.Version in project graylog2-server by Graylog2.

the class V20170607164210_MigrateReopenedIndicesToAliases method getReopenedIndices.

private Set<String> getReopenedIndices(final Collection<String> indices) {
    final SearchVersion elasticsearchVersion = node.getVersion().orElseThrow(() -> new ElasticsearchException("Unable to retrieve Elasticsearch version."));
    final JsonNode clusterStateJson = clusterState.getForIndices(indices);
    final JsonNode indicesJson = clusterStateJson.path("metadata").path("indices");
    final ImmutableSet.Builder<String> reopenedIndices = ImmutableSet.builder();
    if (indicesJson.isMissingNode()) {
        LOG.error("Retrieved cluster state is invalid (no metadata.indices key).");
        LOG.debug("Received cluster state was: {}", clusterStateJson.toString());
        return Collections.emptySet();
    }
    for (Iterator<Map.Entry<String, JsonNode>> it = indicesJson.fields(); it.hasNext(); ) {
        final Map.Entry<String, JsonNode> entry = it.next();
        final String indexName = entry.getKey();
        final JsonNode value = entry.getValue();
        final JsonNode indexSettings = value.path("settings");
        if (indexSettings.isMissingNode()) {
            LOG.error("Unable to retrieve index settings from metadata for index {} - skipping.", indexName);
            LOG.debug("Index metadata was: {}", value.toString());
            continue;
        }
        if (checkForReopened(indexSettings, elasticsearchVersion)) {
            LOG.debug("Adding {} to list of indices to be migrated.", indexName);
            reopenedIndices.add(indexName);
        }
    }
    return reopenedIndices.build();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) JsonNode(com.fasterxml.jackson.databind.JsonNode) ElasticsearchException(org.graylog2.indexer.ElasticsearchException) SearchVersion(org.graylog2.storage.SearchVersion) Map(java.util.Map)

Example 5 with Version

use of org.graylog2.plugin.Version in project graylog2-server by Graylog2.

the class VersionCheckThread method doRun.

@Override
public void doRun() {
    final Request request = new Request.Builder().addHeader(HttpHeaders.USER_AGENT, USER_AGENT).get().url(versionCheckUri.toString()).build();
    try (final Response response = httpClient.newCall(request).execute()) {
        if (response.isSuccessful()) {
            final VersionCheckResponse versionCheckResponse = objectMapper.readValue(response.body().byteStream(), VersionCheckResponse.class);
            final VersionResponse version = versionCheckResponse.version;
            final com.github.zafarkhaja.semver.Version reportedVersion = com.github.zafarkhaja.semver.Version.forIntegers(version.major, version.minor, version.patch);
            LOG.debug("Version check reports current version: " + versionCheckResponse);
            if (reportedVersion.greaterThan(ServerVersion.VERSION.getVersion())) {
                LOG.debug("Reported version is higher than ours ({}). Writing notification.", ServerVersion.VERSION);
                Notification notification = notificationService.buildNow().addSeverity(Notification.Severity.NORMAL).addType(Notification.Type.OUTDATED_VERSION).addDetail("current_version", versionCheckResponse.toString());
                notificationService.publishIfFirst(notification);
            } else {
                LOG.debug("Reported version is not higher than ours ({}).", ServerVersion.VERSION);
                notificationService.fixed(Notification.Type.OUTDATED_VERSION);
            }
        } else {
            LOG.error("Version check unsuccessful (response code {}).", response.code());
        }
    } catch (IOException e) {
        LOG.error("Couldn't perform version check", e);
    }
}
Also used : VersionResponse(org.graylog2.versioncheck.VersionResponse) VersionCheckResponse(org.graylog2.versioncheck.VersionCheckResponse) Response(okhttp3.Response) VersionCheckResponse(org.graylog2.versioncheck.VersionCheckResponse) VersionResponse(org.graylog2.versioncheck.VersionResponse) Request(okhttp3.Request) IOException(java.io.IOException) Notification(org.graylog2.notifications.Notification)

Aggregations

Test (org.junit.Test)29 RawMessage (org.graylog2.plugin.journal.RawMessage)28 Message (org.graylog2.plugin.Message)15 SearchVersion (org.graylog2.storage.SearchVersion)13 JsonNode (com.fasterxml.jackson.databind.JsonNode)7 IOException (java.io.IOException)5 Inject (javax.inject.Inject)5 DateTime (org.joda.time.DateTime)5 ZonedDateTime (java.time.ZonedDateTime)4 Map (java.util.Map)4 Optional (java.util.Optional)4 Constraint (org.graylog2.contentpacks.model.constraints.Constraint)4 GraylogVersionConstraint (org.graylog2.contentpacks.model.constraints.GraylogVersionConstraint)4 PluginVersionConstraint (org.graylog2.contentpacks.model.constraints.PluginVersionConstraint)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 ApiOperation (io.swagger.annotations.ApiOperation)3 URI (java.net.URI)3 HashSet (java.util.HashSet)3