Search in sources :

Example 46 with EntityV1

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

the class SidecarCollectorConfigurationFacadeTest method exportEntity.

@Test
@MongoDBFixtures("SidecarCollectorConfigurationFacadeTest.json")
public void exportEntity() {
    final EntityDescriptor descriptor = EntityDescriptor.create("5b17e1a53f3ab8204eea1051", ModelTypes.SIDECAR_COLLECTOR_CONFIGURATION_V1);
    final EntityDescriptor collectorDescriptor = EntityDescriptor.create("5b4c920b4b900a0024af0001", ModelTypes.SIDECAR_COLLECTOR_V1);
    final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor, collectorDescriptor);
    final Entity entity = facade.exportEntity(descriptor, entityDescriptorIds).orElseThrow(AssertionError::new);
    assertThat(entity).isInstanceOf(EntityV1.class);
    assertThat(entity.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(descriptor).orElse(null)));
    assertThat(entity.type()).isEqualTo(ModelTypes.SIDECAR_COLLECTOR_CONFIGURATION_V1);
    final EntityV1 entityV1 = (EntityV1) entity;
    final SidecarCollectorConfigurationEntity configEntity = objectMapper.convertValue(entityV1.data(), SidecarCollectorConfigurationEntity.class);
    assertThat(configEntity.title()).isEqualTo(ValueReference.of("filebeat config"));
    assertThat(configEntity.collectorId()).isEqualTo(ValueReference.of(entityDescriptorIds.get(collectorDescriptor).orElse(null)));
    assertThat(configEntity.color().asString(Collections.emptyMap())).isEqualTo("#ffffff");
    assertThat(configEntity.template().asString(Collections.emptyMap())).isEqualTo("empty template");
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) Entity(org.graylog2.contentpacks.model.entities.Entity) SidecarCollectorConfigurationEntity(org.graylog2.contentpacks.model.entities.SidecarCollectorConfigurationEntity) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) SidecarCollectorConfigurationEntity(org.graylog2.contentpacks.model.entities.SidecarCollectorConfigurationEntity) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 47 with EntityV1

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

the class StreamCatalogTest method encode.

@Test
public void encode() {
    final ImmutableMap<String, Object> streamFields = ImmutableMap.of(StreamImpl.FIELD_TITLE, "Stream Title", StreamImpl.FIELD_DESCRIPTION, "Stream Description", StreamImpl.FIELD_DISABLED, false);
    final ImmutableMap<String, Object> streamRuleFields = ImmutableMap.<String, Object>builder().put("_id", "1234567890").put(StreamRuleImpl.FIELD_TYPE, StreamRuleType.EXACT.getValue()).put(StreamRuleImpl.FIELD_DESCRIPTION, "description").put(StreamRuleImpl.FIELD_FIELD, "field").put(StreamRuleImpl.FIELD_VALUE, "value").put(StreamRuleImpl.FIELD_INVERTED, false).put(StreamRuleImpl.FIELD_STREAM_ID, "1234567890").build();
    final ImmutableList<StreamRule> streamRules = ImmutableList.of(new StreamRuleMock(streamRuleFields));
    final ImmutableSet<Output> outputs = ImmutableSet.of();
    final ObjectId streamId = new ObjectId();
    final StreamImpl stream = new StreamImpl(streamId, streamFields, streamRules, outputs, null);
    final EntityDescriptor descriptor = EntityDescriptor.create(stream.getId(), ModelTypes.STREAM_V1);
    final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
    final Entity entity = facade.exportNativeEntity(stream, entityDescriptorIds);
    assertThat(entity).isInstanceOf(EntityV1.class);
    assertThat(entity.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(descriptor).orElse(null)));
    assertThat(entity.type()).isEqualTo(ModelTypes.STREAM_V1);
    final EntityV1 entityV1 = (EntityV1) entity;
    final StreamEntity streamEntity = objectMapper.convertValue(entityV1.data(), StreamEntity.class);
    assertThat(streamEntity.title()).isEqualTo(ValueReference.of("Stream Title"));
    assertThat(streamEntity.description()).isEqualTo(ValueReference.of("Stream Description"));
    assertThat(streamEntity.disabled()).isEqualTo(ValueReference.of(false));
    assertThat(streamEntity.streamRules()).hasSize(1);
}
Also used : Entity(org.graylog2.contentpacks.model.entities.Entity) StreamEntity(org.graylog2.contentpacks.model.entities.StreamEntity) ObjectId(org.bson.types.ObjectId) StreamRule(org.graylog2.plugin.streams.StreamRule) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) StreamEntity(org.graylog2.contentpacks.model.entities.StreamEntity) StreamRuleMock(org.graylog2.streams.matchers.StreamRuleMock) EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) StreamImpl(org.graylog2.streams.StreamImpl) Output(org.graylog2.plugin.streams.Output) Test(org.junit.Test)

Example 48 with EntityV1

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

the class StreamCatalogTest method collectEntity.

@Test
@MongoDBFixtures("StreamCatalogTest.json")
public void collectEntity() {
    final EntityDescriptor descriptor = EntityDescriptor.create("5adf23894b900a0fdb4e517d", ModelTypes.STREAM_V1);
    final EntityDescriptor outputDescriptor = EntityDescriptor.create("5adf239e4b900a0fdb4e5197", ModelTypes.OUTPUT_V1);
    final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor, outputDescriptor);
    final Optional<Entity> collectedEntity = facade.exportEntity(descriptor, entityDescriptorIds);
    assertThat(collectedEntity).isPresent().containsInstanceOf(EntityV1.class);
    final EntityV1 entity = (EntityV1) collectedEntity.orElseThrow(AssertionError::new);
    assertThat(entity.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(descriptor).orElse(null)));
    assertThat(entity.type()).isEqualTo(ModelTypes.STREAM_V1);
    final StreamEntity streamEntity = objectMapper.convertValue(entity.data(), StreamEntity.class);
    assertThat(streamEntity.title()).isEqualTo(ValueReference.of("Test"));
    assertThat(streamEntity.description()).isEqualTo(ValueReference.of("Description"));
    assertThat(streamEntity.matchingType()).isEqualTo(ValueReference.of(Stream.MatchingType.AND));
    assertThat(streamEntity.streamRules()).hasSize(7);
    assertThat(streamEntity.outputs()).containsExactly(ValueReference.of(entityDescriptorIds.get(outputDescriptor).orElse(null)));
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) Entity(org.graylog2.contentpacks.model.entities.Entity) StreamEntity(org.graylog2.contentpacks.model.entities.StreamEntity) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) StreamEntity(org.graylog2.contentpacks.model.entities.StreamEntity) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 49 with EntityV1

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

the class PipelineRuleFacadeTest method findExistingWithDifferentSource.

@Test
@MongoDBFixtures("PipelineRuleFacadeTest.json")
public void findExistingWithDifferentSource() {
    final Entity entity = EntityV1.builder().id(ModelId.of("debug")).type(ModelTypes.PIPELINE_RULE_V1).data(objectMapper.convertValue(PipelineRuleEntity.create(ValueReference.of("debug"), ValueReference.of("Debug"), ValueReference.of("rule \"debug\"\nwhen\n  true\nthen\n\nend")), JsonNode.class)).build();
    assertThatThrownBy(() -> facade.findExisting(entity, Collections.emptyMap())).isInstanceOf(DivergingEntityConfigurationException.class).hasMessage("Different pipeline rule sources for pipeline rule with name \"debug\"");
}
Also used : NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) PipelineEntity(org.graylog2.contentpacks.model.entities.PipelineEntity) PipelineRuleEntity(org.graylog2.contentpacks.model.entities.PipelineRuleEntity) DivergingEntityConfigurationException(org.graylog2.contentpacks.exceptions.DivergingEntityConfigurationException) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 50 with EntityV1

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

the class PipelineRuleFacadeTest method exportEntity.

@Test
public void exportEntity() {
    final RuleDao pipelineRule = RuleDao.builder().id("id").title("title").description("description").source("rule \"debug\"\nwhen\n  true\nthen\n  debug($message.message);\nend").build();
    final EntityDescriptor descriptor = EntityDescriptor.create("id", ModelTypes.PIPELINE_RULE_V1);
    final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
    final Entity entity = facade.exportNativeEntity(pipelineRule, entityDescriptorIds);
    assertThat(entity).isInstanceOf(EntityV1.class);
    assertThat(entity.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(descriptor).orElse(null)));
    assertThat(entity.type()).isEqualTo(ModelTypes.PIPELINE_RULE_V1);
    final EntityV1 entityV1 = (EntityV1) entity;
    final PipelineRuleEntity ruleEntity = objectMapper.convertValue(entityV1.data(), PipelineRuleEntity.class);
    assertThat(ruleEntity.title()).isEqualTo(ValueReference.of("title"));
    assertThat(ruleEntity.description()).isEqualTo(ValueReference.of("description"));
    assertThat(ruleEntity.source().asString(Collections.emptyMap())).startsWith("rule \"debug\"\n");
}
Also used : RuleDao(org.graylog.plugins.pipelineprocessor.db.RuleDao) EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) PipelineEntity(org.graylog2.contentpacks.model.entities.PipelineEntity) PipelineRuleEntity(org.graylog2.contentpacks.model.entities.PipelineRuleEntity) PipelineRuleEntity(org.graylog2.contentpacks.model.entities.PipelineRuleEntity) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) Test(org.junit.Test)

Aggregations

Entity (org.graylog2.contentpacks.model.entities.Entity)82 NativeEntity (org.graylog2.contentpacks.model.entities.NativeEntity)78 Test (org.junit.Test)71 EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)56 EntityV1 (org.graylog2.contentpacks.model.entities.EntityV1)48 MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)45 EntityDescriptorIds (org.graylog2.contentpacks.EntityDescriptorIds)40 NativeEntityDescriptor (org.graylog2.contentpacks.model.entities.NativeEntityDescriptor)33 JsonNode (com.fasterxml.jackson.databind.JsonNode)25 GrokPatternEntity (org.graylog2.contentpacks.model.entities.GrokPatternEntity)21 LookupTableEntity (org.graylog2.contentpacks.model.entities.LookupTableEntity)21 LookupCacheEntity (org.graylog2.contentpacks.model.entities.LookupCacheEntity)17 LookupDataAdapterEntity (org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity)17 VisibleForTesting (com.google.common.annotations.VisibleForTesting)16 PipelineEntity (org.graylog2.contentpacks.model.entities.PipelineEntity)16 ValueReference (org.graylog2.contentpacks.model.entities.references.ValueReference)16 ModelId (org.graylog2.contentpacks.model.ModelId)14 HashMap (java.util.HashMap)12 InputEntity (org.graylog2.contentpacks.model.entities.InputEntity)11 Map (java.util.Map)10