Search in sources :

Example 96 with EntityDescriptor

use of org.graylog2.contentpacks.model.entities.EntityDescriptor in project graylog2-server by Graylog2.

the class InputFacade method exportEntity.

@Override
public Optional<Entity> exportEntity(EntityDescriptor entityDescriptor, EntityDescriptorIds entityDescriptorIds) {
    final ModelId modelId = entityDescriptor.id();
    try {
        final Input input = inputService.find(modelId.id());
        final InputWithExtractors inputWithExtractors = InputWithExtractors.create(input, inputService.getExtractors(input));
        return Optional.of(exportNativeEntity(inputWithExtractors, entityDescriptorIds));
    } catch (NotFoundException e) {
        return Optional.empty();
    }
}
Also used : Input(org.graylog2.inputs.Input) MessageInput(org.graylog2.plugin.inputs.MessageInput) NotFoundException(org.graylog2.database.NotFoundException) ModelId(org.graylog2.contentpacks.model.ModelId)

Example 97 with EntityDescriptor

use of org.graylog2.contentpacks.model.entities.EntityDescriptor in project graylog2-server by Graylog2.

the class GrokPatternFacade method resolveForInstallationV1.

private Graph<Entity> resolveForInstallationV1(EntityV1 entity, Map<EntityDescriptor, Entity> entities) {
    final MutableGraph<Entity> mutableGraph = GraphBuilder.directed().build();
    mutableGraph.addNode(entity);
    final GrokPatternEntity grokPatternEntity = objectMapper.convertValue(entity.data(), GrokPatternEntity.class);
    final String namedPattern = grokPatternEntity.pattern();
    final Set<String> patterns = GrokPatternService.extractPatternNames(namedPattern);
    patterns.stream().forEach(patternName -> {
        entities.entrySet().stream().filter(x -> x.getValue().type().equals(ModelTypes.GROK_PATTERN_V1)).filter(x -> {
            EntityV1 entityV1 = (EntityV1) x.getValue();
            GrokPatternEntity grokPatternEntity1 = objectMapper.convertValue(entityV1.data(), GrokPatternEntity.class);
            return grokPatternEntity1.name().equals(patternName);
        }).forEach(x -> mutableGraph.putEdge(entity, x.getValue()));
    });
    return ImmutableGraph.copyOf(mutableGraph);
}
Also used : EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) ImmutableGraph(com.google.common.graph.ImmutableGraph) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) LoggerFactory(org.slf4j.LoggerFactory) Entity(org.graylog2.contentpacks.model.entities.Entity) ModelType(org.graylog2.contentpacks.model.ModelType) ValueReference(org.graylog2.contentpacks.model.entities.references.ValueReference) Inject(javax.inject.Inject) EntityExcerpt(org.graylog2.contentpacks.model.entities.EntityExcerpt) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) NotFoundException(org.graylog2.database.NotFoundException) Logger(org.slf4j.Logger) ModelId(org.graylog2.contentpacks.model.ModelId) GrokPatternService(org.graylog2.grok.GrokPatternService) MutableGraph(com.google.common.graph.MutableGraph) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Set(java.util.Set) Collectors(java.util.stream.Collectors) GraphBuilder(com.google.common.graph.GraphBuilder) EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) GrokPattern(org.graylog2.grok.GrokPattern) ValidationException(org.graylog2.plugin.database.ValidationException) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) GrokPatternEntity(org.graylog2.contentpacks.model.entities.GrokPatternEntity) DivergingEntityConfigurationException(org.graylog2.contentpacks.exceptions.DivergingEntityConfigurationException) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) Graph(com.google.common.graph.Graph) ModelTypes(org.graylog2.contentpacks.model.ModelTypes) EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) GrokPatternEntity(org.graylog2.contentpacks.model.entities.GrokPatternEntity) GrokPatternEntity(org.graylog2.contentpacks.model.entities.GrokPatternEntity)

Example 98 with EntityDescriptor

use of org.graylog2.contentpacks.model.entities.EntityDescriptor in project graylog2-server by Graylog2.

the class GrokPatternFacade method resolveNativeEntity.

@Override
public Graph<EntityDescriptor> resolveNativeEntity(EntityDescriptor entityDescriptor) {
    final MutableGraph<EntityDescriptor> mutableGraph = GraphBuilder.directed().build();
    mutableGraph.addNode(entityDescriptor);
    final ModelId modelId = entityDescriptor.id();
    try {
        final GrokPattern grokPattern = grokPatternService.load(modelId.id());
        final String namedPattern = grokPattern.pattern();
        final Set<String> patterns = GrokPatternService.extractPatternNames(namedPattern);
        patterns.stream().forEach(patternName -> {
            grokPatternService.loadByName(patternName).ifPresent(depPattern -> {
                final EntityDescriptor depEntityDescriptor = EntityDescriptor.create(depPattern.id(), ModelTypes.GROK_PATTERN_V1);
                mutableGraph.putEdge(entityDescriptor, depEntityDescriptor);
            });
        });
    } catch (NotFoundException e) {
        LOG.debug("Couldn't find grok pattern {}", entityDescriptor, e);
    }
    return mutableGraph;
}
Also used : EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) GrokPattern(org.graylog2.grok.GrokPattern) NotFoundException(org.graylog2.database.NotFoundException) ModelId(org.graylog2.contentpacks.model.ModelId)

Example 99 with EntityDescriptor

use of org.graylog2.contentpacks.model.entities.EntityDescriptor in project graylog2-server by Graylog2.

the class SidecarCollectorConfigurationFacade method resolveEntityV1.

private Graph<Entity> resolveEntityV1(EntityV1 entity, Map<String, ValueReference> parameters, Map<EntityDescriptor, Entity> entities) {
    final MutableGraph<Entity> mutableGraph = GraphBuilder.directed().build();
    mutableGraph.addNode(entity);
    final SidecarCollectorConfigurationEntity configurationEntity = objectMapper.convertValue(entity.data(), SidecarCollectorConfigurationEntity.class);
    final EntityDescriptor collectorDescriptor = EntityDescriptor.create(configurationEntity.collectorId().asString(parameters), ModelTypes.SIDECAR_COLLECTOR_V1);
    final Entity collectorEntity = entities.get(collectorDescriptor);
    if (collectorEntity != null) {
        mutableGraph.putEdge(entity, collectorEntity);
    }
    return ImmutableGraph.copyOf(mutableGraph);
}
Also used : NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) SidecarCollectorConfigurationEntity(org.graylog2.contentpacks.model.entities.SidecarCollectorConfigurationEntity) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) SidecarCollectorConfigurationEntity(org.graylog2.contentpacks.model.entities.SidecarCollectorConfigurationEntity)

Example 100 with EntityDescriptor

use of org.graylog2.contentpacks.model.entities.EntityDescriptor in project graylog2-server by Graylog2.

the class StreamFacade method resolveNativeEntity.

@Override
public Graph<EntityDescriptor> resolveNativeEntity(EntityDescriptor entityDescriptor) {
    final MutableGraph<EntityDescriptor> mutableGraph = GraphBuilder.directed().build();
    mutableGraph.addNode(entityDescriptor);
    final ModelId modelId = entityDescriptor.id();
    try {
        final Stream stream = streamService.load(modelId.id());
        stream.getOutputs().stream().map(Output::getId).map(ModelId::of).map(id -> EntityDescriptor.create(id, ModelTypes.OUTPUT_V1)).forEach(output -> mutableGraph.putEdge(entityDescriptor, output));
    } catch (NotFoundException e) {
        LOG.debug("Couldn't find stream {}", entityDescriptor, e);
    }
    return ImmutableGraph.copyOf(mutableGraph);
}
Also used : ImmutableGraph(com.google.common.graph.ImmutableGraph) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) LoggerFactory(org.slf4j.LoggerFactory) CreateStreamRuleRequest(org.graylog2.rest.resources.streams.rules.requests.CreateStreamRuleRequest) AlarmCallbackConfiguration(org.graylog2.alarmcallbacks.AlarmCallbackConfiguration) AlertService(org.graylog2.alerts.AlertService) StreamRule(org.graylog2.plugin.streams.StreamRule) ModelType(org.graylog2.contentpacks.model.ModelType) ValueReference(org.graylog2.contentpacks.model.entities.references.ValueReference) StreamRuleService(org.graylog2.streams.StreamRuleService) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) ModelId(org.graylog2.contentpacks.model.ModelId) MutableGraph(com.google.common.graph.MutableGraph) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) StreamAlarmCallbackEntity(org.graylog2.contentpacks.model.entities.StreamAlarmCallbackEntity) Set(java.util.Set) Collectors(java.util.stream.Collectors) GraphBuilder(com.google.common.graph.GraphBuilder) StreamRuleType(org.graylog2.plugin.streams.StreamRuleType) Objects(java.util.Objects) CreateStreamRequest(org.graylog2.rest.resources.streams.requests.CreateStreamRequest) CreateAlarmCallbackRequest(org.graylog2.rest.models.alarmcallbacks.requests.CreateAlarmCallbackRequest) List(java.util.List) IndexSetService(org.graylog2.indexer.indexset.IndexSetService) UserService(org.graylog2.shared.users.UserService) Stream(org.graylog2.plugin.streams.Stream) StreamService(org.graylog2.streams.StreamService) AlertCondition(org.graylog2.plugin.alarms.AlertCondition) CreateConditionRequest(org.graylog2.rest.models.streams.alerts.requests.CreateConditionRequest) Optional(java.util.Optional) ModelTypes(org.graylog2.contentpacks.model.ModelTypes) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) Strings.nullToEmpty(com.google.common.base.Strings.nullToEmpty) Entity(org.graylog2.contentpacks.model.entities.Entity) ContentPackException(org.graylog2.contentpacks.exceptions.ContentPackException) StreamAlertConditionEntity(org.graylog2.contentpacks.model.entities.StreamAlertConditionEntity) Inject(javax.inject.Inject) ReferenceMapUtils(org.graylog2.contentpacks.model.entities.references.ReferenceMapUtils) V20190722150700_LegacyAlertConditionMigration(org.graylog.events.legacy.V20190722150700_LegacyAlertConditionMigration) EntityExcerpt(org.graylog2.contentpacks.model.entities.EntityExcerpt) ConfigurationException(org.graylog2.plugin.configuration.ConfigurationException) NotFoundException(org.graylog2.database.NotFoundException) Logger(org.slf4j.Logger) StreamEntity(org.graylog2.contentpacks.model.entities.StreamEntity) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) StreamRuleEntity(org.graylog2.contentpacks.model.entities.StreamRuleEntity) AlarmCallbackConfigurationService(org.graylog2.alarmcallbacks.AlarmCallbackConfigurationService) EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) Output(org.graylog2.plugin.streams.Output) ValidationException(org.graylog2.plugin.database.ValidationException) ObjectId(org.bson.types.ObjectId) VisibleForTesting(com.google.common.annotations.VisibleForTesting) User(org.graylog2.plugin.database.users.User) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) Collections(java.util.Collections) Graph(com.google.common.graph.Graph) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) NotFoundException(org.graylog2.database.NotFoundException) Stream(org.graylog2.plugin.streams.Stream) ModelId(org.graylog2.contentpacks.model.ModelId)

Aggregations

EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)92 Test (org.junit.Test)63 Entity (org.graylog2.contentpacks.model.entities.Entity)62 NativeEntity (org.graylog2.contentpacks.model.entities.NativeEntity)59 EntityV1 (org.graylog2.contentpacks.model.entities.EntityV1)48 EntityDescriptorIds (org.graylog2.contentpacks.EntityDescriptorIds)44 NativeEntityDescriptor (org.graylog2.contentpacks.model.entities.NativeEntityDescriptor)44 MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)42 ModelId (org.graylog2.contentpacks.model.ModelId)26 ValueReference (org.graylog2.contentpacks.model.entities.references.ValueReference)16 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 LookupTableEntity (org.graylog2.contentpacks.model.entities.LookupTableEntity)15 Map (java.util.Map)14 Graph (com.google.common.graph.Graph)13 GrokPatternEntity (org.graylog2.contentpacks.model.entities.GrokPatternEntity)13 Optional (java.util.Optional)12 Set (java.util.Set)12 Collectors (java.util.stream.Collectors)12 EntityExcerpt (org.graylog2.contentpacks.model.entities.EntityExcerpt)12 NotFoundException (org.graylog2.database.NotFoundException)12