Search in sources :

Example 31 with NativeEntity

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

the class InputFacadeTest method createNativeEntity.

@Test
@Ignore("Doesn't work without massive amount of mocks")
public void createNativeEntity() {
    final Map<String, Object> configuration = new HashMap<>();
    configuration.put("override_source", null);
    configuration.put("recv_buffer_size", 262144);
    configuration.put("bind_address", "127.0.0.1");
    configuration.put("port", 5555);
    configuration.put("number_worker_threads", 8);
    final Entity entity = EntityV1.builder().id(ModelId.of("5acc84f84b900a4ff290d9a7")).type(ModelTypes.INPUT_V1).data(objectMapper.convertValue(InputEntity.create(ValueReference.of("Local Raw UDP"), ReferenceMapUtils.toReferenceMap(configuration), Collections.emptyMap(), ValueReference.of("org.graylog2.inputs.raw.udp.RawUDPInput"), ValueReference.of(false), Collections.emptyList()), JsonNode.class)).build();
    final NativeEntity<InputWithExtractors> nativeEntity = facade.createNativeEntity(entity, Collections.emptyMap(), Collections.emptyMap(), "username");
    final InputWithExtractors inputWithExtractors = nativeEntity.entity();
    final Input savedInput = inputWithExtractors.input();
    final String savedId = savedInput.getId();
    assertThat(nativeEntity.descriptor()).isEqualTo(EntityDescriptor.create(savedId, ModelTypes.INPUT_V1));
    assertThat(savedInput.getTitle()).isEqualTo("Local Raw UDP");
    assertThat(savedInput.getType()).isEqualTo("org.graylog2.inputs.raw.udp.RawUDPInput");
    assertThat(savedInput.isGlobal()).isFalse();
    assertThat(savedInput.getContentPack()).isNull();
}
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) RawUDPInput(org.graylog2.inputs.raw.udp.RawUDPInput) Input(org.graylog2.inputs.Input) FakeHttpMessageInput(org.graylog2.inputs.random.FakeHttpMessageInput) MessageInput(org.graylog2.plugin.inputs.MessageInput) HashMap(java.util.HashMap) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 32 with NativeEntity

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

the class DashboardV1FacadeTest method setUp.

@Before
public void setUp() throws IOException {
    objectMapper.registerSubtypes(new NamedType(AggregationConfigDTO.class, AggregationConfigDTO.NAME));
    objectMapper.registerSubtypes(new NamedType(MessageListConfigDTO.class, MessageListConfigDTO.NAME));
    objectMapper.registerSubtypes(new NamedType(LineVisualizationConfigDTO.class, LineVisualizationConfigDTO.NAME));
    objectMapper.registerSubtypes(new NamedType(BarVisualizationConfigDTO.class, BarVisualizationConfigDTO.NAME));
    objectMapper.registerSubtypes(new NamedType(NumberVisualizationConfigDTO.class, NumberVisualizationConfigDTO.NAME));
    objectMapper.registerSubtypes(new NamedType(TimeHistogramConfigDTO.class, TimeHistogramConfigDTO.NAME));
    objectMapper.registerSubtypes(new NamedType(ValueConfigDTO.class, ValueConfigDTO.NAME));
    objectMapper.registerSubtypes(new NamedType(PivotSortConfig.class, PivotSortConfig.Type));
    objectMapper.registerSubtypes(new NamedType(PivotEntity.class, PivotEntity.NAME));
    objectMapper.registerSubtypes(new NamedType(PivotSort.class, PivotSort.Type));
    objectMapper.registerSubtypes(new NamedType(OrFilter.class, OrFilter.NAME));
    objectMapper.registerSubtypes(new NamedType(StreamFilter.class, StreamFilter.NAME));
    objectMapper.registerSubtypes(new NamedType(QueryStringFilter.class, QueryStringFilter.NAME));
    objectMapper.registerSubtypes(new NamedType(AutoIntervalDTO.class, AutoIntervalDTO.type));
    final MongoConnection mongoConnection = mongodb.mongoConnection();
    final MongoJackObjectMapperProvider mapper = new MongoJackObjectMapperProvider(objectMapper);
    searchDbService = new ViewFacadeTest.TestSearchDBService(mongoConnection, mapper);
    viewService = new ViewFacadeTest.TestViewService(mongoConnection, mapper, null);
    viewSummaryService = new ViewFacadeTest.TestViewSummaryService(mongoConnection, mapper);
    userService = mock(UserService.class);
    final UserImpl fakeUser = new UserImpl(mock(PasswordAlgorithmFactory.class), new Permissions(ImmutableSet.of()), ImmutableMap.of("username", "testuser"));
    when(userService.load("testuser")).thenReturn(fakeUser);
    final DashboardWidgetConverter dashboardWidgetConverter = new DashboardWidgetConverter();
    final EntityConverter entityConverter = new EntityConverter(dashboardWidgetConverter);
    facade = new DashboardV1Facade(objectMapper, searchDbService, entityConverter, viewService, viewSummaryService, userService);
    final URL resourceUrl = Resources.getResource(DashboardV1Facade.class, "content-pack-dashboard-v1.json");
    final ContentPack contentPack = objectMapper.readValue(resourceUrl, ContentPack.class);
    assertThat(contentPack).isInstanceOf(ContentPackV1.class);
    final ContentPackV1 contentPackV1 = (ContentPackV1) contentPack;
    final Entity entity = contentPackV1.entities().iterator().next();
    final StreamImpl stream = new StreamImpl(Collections.emptyMap());
    final Map<EntityDescriptor, Object> nativeEntities = new HashMap<>(1);
    nativeEntities.put(EntityDescriptor.create("58b3d55a-51ad-4b3e-865c-85776016a151", ModelTypes.STREAM_V1), stream);
    final NativeEntity<ViewDTO> nativeEntity = facade.createNativeEntity(entity, ImmutableMap.of(), nativeEntities, "testuser");
    assertThat(nativeEntity).isNotNull();
    viewDTO = nativeEntity.entity();
}
Also used : NumberVisualizationConfigDTO(org.graylog.plugins.views.search.views.widgets.aggregation.NumberVisualizationConfigDTO) EntityConverter(org.graylog2.contentpacks.facades.dashboardV1.EntityConverter) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) PivotEntity(org.graylog2.contentpacks.model.entities.PivotEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) HashMap(java.util.HashMap) NamedType(com.fasterxml.jackson.databind.jsontype.NamedType) TimeHistogramConfigDTO(org.graylog.plugins.views.search.views.widgets.aggregation.TimeHistogramConfigDTO) AutoIntervalDTO(org.graylog.plugins.views.search.views.widgets.aggregation.AutoIntervalDTO) PivotSortConfig(org.graylog.plugins.views.search.views.widgets.aggregation.sort.PivotSortConfig) StreamFilter(org.graylog.plugins.views.search.filter.StreamFilter) QueryStringFilter(org.graylog.plugins.views.search.filter.QueryStringFilter) DashboardV1Facade(org.graylog2.contentpacks.facades.dashboardV1.DashboardV1Facade) URL(java.net.URL) AggregationConfigDTO(org.graylog.plugins.views.search.views.widgets.aggregation.AggregationConfigDTO) ViewDTO(org.graylog.plugins.views.search.views.ViewDTO) PasswordAlgorithmFactory(org.graylog2.security.PasswordAlgorithmFactory) MessageListConfigDTO(org.graylog.plugins.views.search.views.widgets.messagelist.MessageListConfigDTO) ContentPackV1(org.graylog2.contentpacks.model.ContentPackV1) UserImpl(org.graylog2.users.UserImpl) Permissions(org.graylog2.shared.security.Permissions) DashboardWidgetConverter(org.graylog2.contentpacks.facades.dashboardV1.DashboardWidgetConverter) BarVisualizationConfigDTO(org.graylog.plugins.views.search.views.widgets.aggregation.BarVisualizationConfigDTO) UserService(org.graylog2.shared.users.UserService) MongoJackObjectMapperProvider(org.graylog2.bindings.providers.MongoJackObjectMapperProvider) ContentPack(org.graylog2.contentpacks.model.ContentPack) OrFilter(org.graylog.plugins.views.search.filter.OrFilter) LineVisualizationConfigDTO(org.graylog.plugins.views.search.views.widgets.aggregation.LineVisualizationConfigDTO) PivotSort(org.graylog.plugins.views.search.searchtypes.pivot.PivotSort) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) StreamImpl(org.graylog2.streams.StreamImpl) ValueConfigDTO(org.graylog.plugins.views.search.views.widgets.aggregation.ValueConfigDTO) MongoConnection(org.graylog2.database.MongoConnection) PivotEntity(org.graylog2.contentpacks.model.entities.PivotEntity) Before(org.junit.Before)

Example 33 with NativeEntity

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

the class LookupDataAdapterFacadeTest method findExistingWithNoExistingEntity.

@Test
@MongoDBFixtures("LookupDataAdapterFacadeTest.json")
public void findExistingWithNoExistingEntity() {
    final Entity entity = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.LOOKUP_ADAPTER_V1).data(objectMapper.convertValue(LookupDataAdapterEntity.create(ValueReference.of("some-name"), ValueReference.of("Some title"), ValueReference.of("Some description"), ReferenceMapUtils.toReferenceMap(Collections.emptyMap())), JsonNode.class)).build();
    final Optional<NativeEntity<DataAdapterDto>> existingEntity = facade.findExisting(entity, Collections.emptyMap());
    assertThat(existingEntity).isEmpty();
}
Also used : NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) LookupDataAdapterEntity(org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 34 with NativeEntity

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

the class LookupDataAdapterFacadeTest method findExisting.

@Test
@MongoDBFixtures("LookupDataAdapterFacadeTest.json")
public void findExisting() {
    final Entity entity = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.LOOKUP_ADAPTER_V1).data(objectMapper.convertValue(LookupDataAdapterEntity.create(ValueReference.of("http-dsv"), ValueReference.of("HTTP DSV"), ValueReference.of("HTTP DSV"), ReferenceMapUtils.toReferenceMap(Collections.emptyMap())), JsonNode.class)).build();
    final NativeEntity<DataAdapterDto> nativeEntity = facade.findExisting(entity, Collections.emptyMap()).orElseThrow(AssertionError::new);
    assertThat(nativeEntity.descriptor().id()).isEqualTo(ModelId.of("5adf24a04b900a0fdb4e52c8"));
    assertThat(nativeEntity.descriptor().type()).isEqualTo(ModelTypes.LOOKUP_ADAPTER_V1);
    assertThat(nativeEntity.entity().name()).isEqualTo("http-dsv");
    assertThat(nativeEntity.entity().title()).isEqualTo("HTTP DSV");
    assertThat(nativeEntity.entity().description()).isEqualTo("HTTP DSV");
}
Also used : NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) LookupDataAdapterEntity(org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity) DataAdapterDto(org.graylog2.lookup.dto.DataAdapterDto) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 35 with NativeEntity

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

the class PipelineRuleFacadeTest method findExisting.

@Test
@MongoDBFixtures("PipelineRuleFacadeTest.json")
public void findExisting() {
    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  debug($message.message);\nend")), JsonNode.class)).build();
    final NativeEntity<RuleDao> existingRule = facade.findExisting(entity, Collections.emptyMap()).orElseThrow(AssertionError::new);
    assertThat(existingRule.descriptor().id()).isEqualTo(ModelId.of("5adf25034b900a0fdb4e5338"));
    assertThat(existingRule.descriptor().type()).isEqualTo(ModelTypes.PIPELINE_RULE_V1);
    assertThat(existingRule.entity().title()).isEqualTo("debug");
    assertThat(existingRule.entity().description()).isEqualTo("Debug");
    assertThat(existingRule.entity().source()).startsWith("rule \"debug\"\n");
}
Also used : RuleDao(org.graylog.plugins.pipelineprocessor.db.RuleDao) 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) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Aggregations

NativeEntity (org.graylog2.contentpacks.model.entities.NativeEntity)30 Entity (org.graylog2.contentpacks.model.entities.Entity)28 Test (org.junit.Test)26 NativeEntityDescriptor (org.graylog2.contentpacks.model.entities.NativeEntityDescriptor)15 MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)14 EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)12 EntityV1 (org.graylog2.contentpacks.model.entities.EntityV1)7 LookupCacheEntity (org.graylog2.contentpacks.model.entities.LookupCacheEntity)7 LookupTableEntity (org.graylog2.contentpacks.model.entities.LookupTableEntity)7 ValueReference (org.graylog2.contentpacks.model.entities.references.ValueReference)7 HashMap (java.util.HashMap)6 LookupDataAdapterEntity (org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity)6 CacheDto (org.graylog2.lookup.dto.CacheDto)6 Map (java.util.Map)5 RuleDao (org.graylog.plugins.pipelineprocessor.db.RuleDao)5 GrokPatternEntity (org.graylog2.contentpacks.model.entities.GrokPatternEntity)5 DataAdapterDto (org.graylog2.lookup.dto.DataAdapterDto)5 Graph (com.google.common.graph.Graph)4 GraphBuilder (com.google.common.graph.GraphBuilder)4 ImmutableGraph (com.google.common.graph.ImmutableGraph)4