Search in sources :

Example 61 with EntityDescriptor

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

the class InputFacadeTest method resolveForInstallationLookupTable.

@Test
@MongoDBFixtures("InputFacadeTest.json")
public void resolveForInstallationLookupTable() throws NotFoundException {
    when(lookupuptableBuilder.lookupTable("whois")).thenReturn(lookupuptableBuilder);
    when(lookupuptableBuilder.lookupTable("tor-exit-node-list")).thenReturn(lookupuptableBuilder);
    when(lookupuptableBuilder.build()).thenReturn(lookupTable);
    when(lookupTableService.newBuilder()).thenReturn(lookupuptableBuilder);
    when(lookupTableService.hasTable("whois")).thenReturn(true);
    when(lookupTableService.hasTable("tor-exit-node-list")).thenReturn(true);
    final Input input = inputService.find("5ae2eb0a3d27464477f0fd8b");
    final Map<String, Object> lookupTableConfig = new HashedMap(1);
    lookupTableConfig.put("lookup_table_name", "tor-exit-node-list");
    final ConverterEntity converterEntity = ConverterEntity.create(ValueReference.of(Converter.Type.LOOKUP_TABLE.name()), ReferenceMapUtils.toReferenceMap(lookupTableConfig));
    final List<ConverterEntity> converterEntities = new ArrayList<>(1);
    converterEntities.add(converterEntity);
    final InputWithExtractors inputWithExtractors = InputWithExtractors.create(input, inputService.getExtractors(input));
    final LookupTableExtractor extractor = (LookupTableExtractor) inputWithExtractors.extractors().iterator().next();
    final ExtractorEntity extractorEntity = ExtractorEntity.create(ValueReference.of(extractor.getTitle()), ValueReference.of(extractor.getType()), ValueReference.of(extractor.getCursorStrategy()), ValueReference.of(extractor.getTargetField()), ValueReference.of(extractor.getSourceField()), ReferenceMapUtils.toReferenceMap(extractor.getExtractorConfig()), converterEntities, ValueReference.of(extractor.getConditionType()), ValueReference.of(extractor.getConditionValue()), ValueReference.of(extractor.getOrder()));
    List<ExtractorEntity> extractors = new ArrayList<>();
    extractors.add(extractorEntity);
    InputEntity inputEntity = InputEntity.create(ValueReference.of(input.getTitle()), ReferenceMapUtils.toReferenceMap(input.getConfiguration()), Collections.emptyMap(), ValueReference.of(input.getType()), ValueReference.of(input.isGlobal()), extractors);
    final Entity entity = EntityV1.builder().id(ModelId.of(input.getId())).type(ModelTypes.INPUT_V1).data(objectMapper.convertValue(inputEntity, JsonNode.class)).build();
    final LookupTableEntity whoIsEntity = LookupTableEntity.create(ValueReference.of("whois"), ValueReference.of("title"), ValueReference.of("description"), ValueReference.of("cache_name"), ValueReference.of("dataadapter_name"), ValueReference.of("default_single_value"), ValueReference.of("BOOLEAN"), ValueReference.of("default_multi_value"), ValueReference.of("BOOLEAN"));
    final LookupTableEntity torNodeEntity = LookupTableEntity.create(ValueReference.of("tor-exit-node-list"), ValueReference.of("title"), ValueReference.of("description"), ValueReference.of("cache_name"), ValueReference.of("dataadapter_name"), ValueReference.of("default_single_value"), ValueReference.of("BOOLEAN"), ValueReference.of("default_multi_value"), ValueReference.of("BOOLEAN"));
    final Entity expectedWhoIsEntity = EntityV1.builder().id(ModelId.of("dead-beef")).data(objectMapper.convertValue(whoIsEntity, JsonNode.class)).type(ModelTypes.LOOKUP_TABLE_V1).build();
    final Entity expectedTorEntity = EntityV1.builder().id(ModelId.of("dead-feed")).data(objectMapper.convertValue(torNodeEntity, JsonNode.class)).type(ModelTypes.LOOKUP_TABLE_V1).build();
    final EntityDescriptor whoisDescriptor = expectedWhoIsEntity.toEntityDescriptor();
    final EntityDescriptor torDescriptor = expectedTorEntity.toEntityDescriptor();
    final Map<EntityDescriptor, Entity> entityDescriptorEntityMap = new HashMap<>(2);
    entityDescriptorEntityMap.put(whoisDescriptor, expectedWhoIsEntity);
    entityDescriptorEntityMap.put(torDescriptor, expectedTorEntity);
    Graph<Entity> graph = facade.resolveForInstallation(entity, Collections.emptyMap(), entityDescriptorEntityMap);
    assertThat(graph.nodes()).contains(expectedWhoIsEntity);
    assertThat(graph.nodes()).contains(expectedTorEntity);
}
Also used : NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) ConverterEntity(org.graylog2.contentpacks.model.entities.ConverterEntity) InputEntity(org.graylog2.contentpacks.model.entities.InputEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) ExtractorEntity(org.graylog2.contentpacks.model.entities.ExtractorEntity) LookupTableEntity(org.graylog2.contentpacks.model.entities.LookupTableEntity) GrokPatternEntity(org.graylog2.contentpacks.model.entities.GrokPatternEntity) HashMap(java.util.HashMap) LookupTableExtractor(org.graylog2.inputs.extractors.LookupTableExtractor) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) RawUDPInput(org.graylog2.inputs.raw.udp.RawUDPInput) Input(org.graylog2.inputs.Input) FakeHttpMessageInput(org.graylog2.inputs.random.FakeHttpMessageInput) MessageInput(org.graylog2.plugin.inputs.MessageInput) LookupTableEntity(org.graylog2.contentpacks.model.entities.LookupTableEntity) ConverterEntity(org.graylog2.contentpacks.model.entities.ConverterEntity) ExtractorEntity(org.graylog2.contentpacks.model.entities.ExtractorEntity) InputEntity(org.graylog2.contentpacks.model.entities.InputEntity) HashedMap(org.apache.commons.collections.map.HashedMap) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 62 with EntityDescriptor

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

the class InputFacadeTest method resolveForInstallationGrokPattern.

@Test
@MongoDBFixtures("InputFacadeTest.json")
public void resolveForInstallationGrokPattern() throws NotFoundException {
    final Input input = inputService.find("5ae2ebbeef27464477f0fd8b");
    final InputWithExtractors inputWithExtractors = InputWithExtractors.create(input, inputService.getExtractors(input));
    final GrokExtractor grokExtractor = (GrokExtractor) inputWithExtractors.extractors().iterator().next();
    final ExtractorEntity extractorEntity = ExtractorEntity.create(ValueReference.of(grokExtractor.getTitle()), ValueReference.of(grokExtractor.getType()), ValueReference.of(grokExtractor.getCursorStrategy()), ValueReference.of(grokExtractor.getTargetField()), ValueReference.of(grokExtractor.getSourceField()), ReferenceMapUtils.toReferenceMap(grokExtractor.getExtractorConfig()), Collections.emptyList(), ValueReference.of(grokExtractor.getConditionType()), ValueReference.of(grokExtractor.getConditionValue()), ValueReference.of(grokExtractor.getOrder()));
    List<ExtractorEntity> extractorEntities = new ArrayList<>(1);
    extractorEntities.add(extractorEntity);
    InputEntity inputEntity = InputEntity.create(ValueReference.of(input.getTitle()), ReferenceMapUtils.toReferenceMap(input.getConfiguration()), Collections.emptyMap(), ValueReference.of(input.getType()), ValueReference.of(input.isGlobal()), extractorEntities);
    Entity entity = EntityV1.builder().id(ModelId.of(input.getId())).type(ModelTypes.INPUT_V1).data(objectMapper.convertValue(inputEntity, JsonNode.class)).build();
    final GrokPatternEntity grokPatternEntity = GrokPatternEntity.create("GREEDY", ".*");
    final Entity expectedEntity = EntityV1.builder().id(ModelId.of("dead-feed")).data(objectMapper.convertValue(grokPatternEntity, JsonNode.class)).type(ModelTypes.GROK_PATTERN_V1).build();
    final EntityDescriptor entityDescriptor = expectedEntity.toEntityDescriptor();
    final Map<EntityDescriptor, Entity> entities = new HashMap<>(1);
    entities.put(entityDescriptor, expectedEntity);
    Graph<Entity> graph = facade.resolveForInstallation(entity, Collections.emptyMap(), entities);
    assertThat(graph.nodes()).contains(expectedEntity);
}
Also used : NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) ConverterEntity(org.graylog2.contentpacks.model.entities.ConverterEntity) InputEntity(org.graylog2.contentpacks.model.entities.InputEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) ExtractorEntity(org.graylog2.contentpacks.model.entities.ExtractorEntity) LookupTableEntity(org.graylog2.contentpacks.model.entities.LookupTableEntity) GrokPatternEntity(org.graylog2.contentpacks.model.entities.GrokPatternEntity) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) GrokPatternEntity(org.graylog2.contentpacks.model.entities.GrokPatternEntity) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) RawUDPInput(org.graylog2.inputs.raw.udp.RawUDPInput) Input(org.graylog2.inputs.Input) FakeHttpMessageInput(org.graylog2.inputs.random.FakeHttpMessageInput) MessageInput(org.graylog2.plugin.inputs.MessageInput) GrokExtractor(org.graylog2.inputs.extractors.GrokExtractor) ExtractorEntity(org.graylog2.contentpacks.model.entities.ExtractorEntity) InputEntity(org.graylog2.contentpacks.model.entities.InputEntity) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 63 with EntityDescriptor

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

the class InputFacadeTest method resolveNativeEntityLookupTable.

@Test
@MongoDBFixtures("InputFacadeTest.json")
public void resolveNativeEntityLookupTable() throws NotFoundException {
    when(lookupuptableBuilder.lookupTable("whois")).thenReturn(lookupuptableBuilder);
    when(lookupuptableBuilder.lookupTable("tor-exit-node-list")).thenReturn(lookupuptableBuilder);
    when(lookupuptableBuilder.build()).thenReturn(lookupTable);
    when(lookupTableService.newBuilder()).thenReturn(lookupuptableBuilder);
    when(lookupTableService.hasTable("whois")).thenReturn(true);
    when(lookupTableService.hasTable("tor-exit-node-list")).thenReturn(true);
    when(lookupTableWhois.id()).thenReturn("dead-beef");
    when(dbLookupTableService.get("whois")).thenReturn(Optional.of(lookupTableWhois));
    when(lookupTableTor.id()).thenReturn("dead-feed");
    when(dbLookupTableService.get("tor-exit-node-list")).thenReturn(Optional.of(lookupTableTor));
    final Input input = inputService.find("5ae2eb0a3d27464477f0fd8b");
    EntityDescriptor entityDescriptor = EntityDescriptor.create(ModelId.of(input.getId()), ModelTypes.INPUT_V1);
    EntityDescriptor expectedEntitiyDescriptorWhois = EntityDescriptor.create(ModelId.of("dead-beef"), ModelTypes.LOOKUP_TABLE_V1);
    EntityDescriptor expectedEntitiyDescriptorTor = EntityDescriptor.create(ModelId.of("dead-feed"), ModelTypes.LOOKUP_TABLE_V1);
    Graph<EntityDescriptor> graph = facade.resolveNativeEntity(entityDescriptor);
    assertThat(graph.nodes()).contains(expectedEntitiyDescriptorWhois);
    assertThat(graph.nodes()).contains(expectedEntitiyDescriptorTor);
}
Also used : EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) RawUDPInput(org.graylog2.inputs.raw.udp.RawUDPInput) Input(org.graylog2.inputs.Input) FakeHttpMessageInput(org.graylog2.inputs.random.FakeHttpMessageInput) MessageInput(org.graylog2.plugin.inputs.MessageInput) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 64 with EntityDescriptor

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

the class InputFacadeTest method exportNativeEntity.

@Test
public void exportNativeEntity() {
    final ImmutableMap<String, Object> fields = ImmutableMap.of(MessageInput.FIELD_TITLE, "Input Title", MessageInput.FIELD_TYPE, "org.graylog2.inputs.raw.udp.RawUDPInput", MessageInput.FIELD_CONFIGURATION, Collections.emptyMap());
    final InputImpl input = new InputImpl(fields);
    final ImmutableList<Extractor> extractors = ImmutableList.of();
    final InputWithExtractors inputWithExtractors = InputWithExtractors.create(input, extractors);
    final EntityDescriptor descriptor = EntityDescriptor.create(input.getId(), ModelTypes.INPUT_V1);
    final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
    final Entity entity = facade.exportNativeEntity(inputWithExtractors, entityDescriptorIds);
    assertThat(entity).isInstanceOf(EntityV1.class);
    assertThat(entity.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(descriptor).orElse(null)));
    assertThat(entity.type()).isEqualTo(ModelTypes.INPUT_V1);
    final EntityV1 entityV1 = (EntityV1) entity;
    final InputEntity inputEntity = objectMapper.convertValue(entityV1.data(), InputEntity.class);
    assertThat(inputEntity.title()).isEqualTo(ValueReference.of("Input Title"));
    assertThat(inputEntity.type()).isEqualTo(ValueReference.of("org.graylog2.inputs.raw.udp.RawUDPInput"));
    assertThat(inputEntity.configuration()).isEmpty();
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) InputImpl(org.graylog2.inputs.InputImpl) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) ConverterEntity(org.graylog2.contentpacks.model.entities.ConverterEntity) InputEntity(org.graylog2.contentpacks.model.entities.InputEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) ExtractorEntity(org.graylog2.contentpacks.model.entities.ExtractorEntity) LookupTableEntity(org.graylog2.contentpacks.model.entities.LookupTableEntity) GrokPatternEntity(org.graylog2.contentpacks.model.entities.GrokPatternEntity) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) InputEntity(org.graylog2.contentpacks.model.entities.InputEntity) Extractor(org.graylog2.plugin.inputs.Extractor) GrokExtractor(org.graylog2.inputs.extractors.GrokExtractor) LookupTableExtractor(org.graylog2.inputs.extractors.LookupTableExtractor) Test(org.junit.Test)

Example 65 with EntityDescriptor

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

the class InputFacadeTest method resolveEntityDescriptor.

@Test
@MongoDBFixtures("InputFacadeTest.json")
public void resolveEntityDescriptor() {
    final EntityDescriptor descriptor = EntityDescriptor.create("5acc84f84b900a4ff290d9a7", ModelTypes.INPUT_V1);
    final Graph<EntityDescriptor> graph = facade.resolveNativeEntity(descriptor);
    assertThat(graph.nodes()).containsOnly(descriptor);
}
Also used : EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

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