Search in sources :

Example 21 with EntityDescriptorIds

use of org.graylog2.contentpacks.EntityDescriptorIds 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 22 with EntityDescriptorIds

use of org.graylog2.contentpacks.EntityDescriptorIds 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 23 with EntityDescriptorIds

use of org.graylog2.contentpacks.EntityDescriptorIds 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 24 with EntityDescriptorIds

use of org.graylog2.contentpacks.EntityDescriptorIds 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)

Example 25 with EntityDescriptorIds

use of org.graylog2.contentpacks.EntityDescriptorIds in project graylog2-server by Graylog2.

the class SidecarCollectorFacadeTest method exportEntity.

@Test
@MongoDBFixtures("SidecarCollectorFacadeTest.json")
public void exportEntity() {
    final EntityDescriptor descriptor = EntityDescriptor.create("5b4c920b4b900a0024af0001", ModelTypes.SIDECAR_COLLECTOR_V1);
    final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
    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_V1);
    final EntityV1 entityV1 = (EntityV1) entity;
    final SidecarCollectorEntity collectorEntity = objectMapper.convertValue(entityV1.data(), SidecarCollectorEntity.class);
    assertThat(collectorEntity.name()).isEqualTo(ValueReference.of("filebeat"));
    assertThat(collectorEntity.serviceType()).isEqualTo(ValueReference.of("exec"));
    assertThat(collectorEntity.nodeOperatingSystem()).isEqualTo(ValueReference.of("linux"));
    assertThat(collectorEntity.executablePath()).isEqualTo(ValueReference.of("/usr/lib/graylog-sidecar/filebeat"));
    assertThat(collectorEntity.executeParameters()).isEqualTo(ValueReference.of("-c %s"));
    assertThat(collectorEntity.validationParameters()).isEqualTo(ValueReference.of("test config -c %s"));
    assertThat(collectorEntity.defaultTemplate()).isEqualTo(ValueReference.of(""));
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) SidecarCollectorEntity(org.graylog2.contentpacks.model.entities.SidecarCollectorEntity) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) SidecarCollectorEntity(org.graylog2.contentpacks.model.entities.SidecarCollectorEntity) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Aggregations

EntityDescriptorIds (org.graylog2.contentpacks.EntityDescriptorIds)36 Entity (org.graylog2.contentpacks.model.entities.Entity)35 EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)35 EntityV1 (org.graylog2.contentpacks.model.entities.EntityV1)34 Test (org.junit.Test)33 NativeEntity (org.graylog2.contentpacks.model.entities.NativeEntity)32 MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)23 JsonNode (com.fasterxml.jackson.databind.JsonNode)14 NativeEntityDescriptor (org.graylog2.contentpacks.model.entities.NativeEntityDescriptor)12 VisibleForTesting (com.google.common.annotations.VisibleForTesting)11 ModelId (org.graylog2.contentpacks.model.ModelId)11 LookupTableEntity (org.graylog2.contentpacks.model.entities.LookupTableEntity)8 PipelineEntity (org.graylog2.contentpacks.model.entities.PipelineEntity)8 GrokPatternEntity (org.graylog2.contentpacks.model.entities.GrokPatternEntity)7 LookupCacheEntity (org.graylog2.contentpacks.model.entities.LookupCacheEntity)7 LookupDataAdapterEntity (org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity)7 Constraint (org.graylog2.contentpacks.model.constraints.Constraint)4 PluginVersionConstraint (org.graylog2.contentpacks.model.constraints.PluginVersionConstraint)4 ConverterEntity (org.graylog2.contentpacks.model.entities.ConverterEntity)4 ExtractorEntity (org.graylog2.contentpacks.model.entities.ExtractorEntity)4