Search in sources :

Example 16 with Pipeline

use of org.graylog.plugins.pipelineprocessor.ast.Pipeline in project graylog2-server by Graylog2.

the class PipelineFacade method delete.

@Override
public void delete(PipelineDao nativeEntity) {
    final Set<PipelineConnections> pipelineConnections = connectionsService.loadByPipelineId(nativeEntity.id());
    for (PipelineConnections connections : pipelineConnections) {
        final Set<String> pipelineIds = connections.pipelineIds().stream().filter(pipelineId -> !pipelineId.equals(nativeEntity.id())).collect(Collectors.toSet());
        if (pipelineIds.isEmpty()) {
            LOG.trace("Removing pipeline connections for stream {}", connections.streamId());
            connectionsService.delete(connections.streamId());
        } else {
            final PipelineConnections newConnections = connections.toBuilder().pipelineIds(pipelineIds).build();
            LOG.trace("Saving updated pipeline connections: {}", newConnections);
            connectionsService.save(newConnections);
        }
    }
    pipelineService.delete(nativeEntity.id());
}
Also used : PipelineConnections(org.graylog.plugins.pipelineprocessor.rest.PipelineConnections) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) RuleDao(org.graylog.plugins.pipelineprocessor.db.RuleDao) RuleService(org.graylog.plugins.pipelineprocessor.db.RuleService) ImmutableGraph(com.google.common.graph.ImmutableGraph) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Tools(org.graylog2.plugin.Tools) LoggerFactory(org.slf4j.LoggerFactory) Entity(org.graylog2.contentpacks.model.entities.Entity) Stage(org.graylog.plugins.pipelineprocessor.ast.Stage) ModelType(org.graylog2.contentpacks.model.ModelType) ValueReference(org.graylog2.contentpacks.model.entities.references.ValueReference) Inject(javax.inject.Inject) PipelineService(org.graylog.plugins.pipelineprocessor.db.PipelineService) EntityExcerpt(org.graylog2.contentpacks.model.entities.EntityExcerpt) PipelineEntity(org.graylog2.contentpacks.model.entities.PipelineEntity) PipelineStreamConnectionsService(org.graylog.plugins.pipelineprocessor.db.PipelineStreamConnectionsService) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) JsonNode(com.fasterxml.jackson.databind.JsonNode) PipelineRuleParser(org.graylog.plugins.pipelineprocessor.parser.PipelineRuleParser) NotFoundException(org.graylog2.database.NotFoundException) Pipeline(org.graylog.plugins.pipelineprocessor.ast.Pipeline) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) ModelId(org.graylog2.contentpacks.model.ModelId) MutableGraph(com.google.common.graph.MutableGraph) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DateTime(org.joda.time.DateTime) MissingNativeEntityException(org.graylog2.contentpacks.exceptions.MissingNativeEntityException) Set(java.util.Set) PipelineDao(org.graylog.plugins.pipelineprocessor.db.PipelineDao) Collectors(java.util.stream.Collectors) GraphBuilder(com.google.common.graph.GraphBuilder) EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) Objects(java.util.Objects) Stream(org.graylog2.plugin.streams.Stream) StreamService(org.graylog2.streams.StreamService) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) Collections(java.util.Collections) Graph(com.google.common.graph.Graph) ModelTypes(org.graylog2.contentpacks.model.ModelTypes) PipelineConnections(org.graylog.plugins.pipelineprocessor.rest.PipelineConnections)

Example 17 with Pipeline

use of org.graylog.plugins.pipelineprocessor.ast.Pipeline in project graylog2-server by Graylog2.

the class PipelineRuleParserTest method pipelineDeclaration.

@Test
public void pipelineDeclaration() throws Exception {
    final List<Pipeline> pipelines = parser.parsePipelines(ruleForTest());
    assertEquals(1, pipelines.size());
    final Pipeline pipeline = Iterables.getOnlyElement(pipelines);
    assertEquals("cisco", pipeline.name());
    assertEquals(2, pipeline.stages().size());
    final Stage stage1 = pipeline.stages().first();
    final Stage stage2 = pipeline.stages().last();
    assertEquals(Stage.Match.ALL, stage1.match());
    assertEquals(1, stage1.stage());
    assertArrayEquals(new Object[] { "check_ip_whitelist", "cisco_device" }, stage1.ruleReferences().toArray());
    assertEquals(Stage.Match.EITHER, stage2.match());
    assertEquals(2, stage2.stage());
    assertArrayEquals(new Object[] { "parse_cisco_time", "extract_src_dest", "normalize_src_dest", "lookup_ips", "resolve_ips" }, stage2.ruleReferences().toArray());
}
Also used : Stage(org.graylog.plugins.pipelineprocessor.ast.Stage) Pipeline(org.graylog.plugins.pipelineprocessor.ast.Pipeline) BaseParserTest(org.graylog.plugins.pipelineprocessor.BaseParserTest) Test(org.junit.Test)

Example 18 with Pipeline

use of org.graylog.plugins.pipelineprocessor.ast.Pipeline in project graylog2-server by Graylog2.

the class StageIteratorTest method singlePipelineNoStage.

@Test
public void singlePipelineNoStage() {
    final ImmutableSet<Pipeline> input = ImmutableSet.of(Pipeline.builder().name("hallo").stages(of(Stage.builder().stage(0).match(Stage.Match.ALL).ruleReferences(Collections.emptyList()).build())).build());
    final StageIterator iterator = new StageIterator(input);
    assertTrue(iterator.hasNext());
    final List<Stage> nextStages = iterator.next();
    assertEquals(1, nextStages.size());
    final Stage stage = Iterables.getOnlyElement(nextStages);
    assertEquals(0, stage.ruleReferences().size());
}
Also used : Stage(org.graylog.plugins.pipelineprocessor.ast.Stage) Pipeline(org.graylog.plugins.pipelineprocessor.ast.Pipeline) Test(org.junit.Test)

Aggregations

Pipeline (org.graylog.plugins.pipelineprocessor.ast.Pipeline)18 Stage (org.graylog.plugins.pipelineprocessor.ast.Stage)8 PipelineDao (org.graylog.plugins.pipelineprocessor.db.PipelineDao)6 Test (org.junit.Test)6 PipelineService (org.graylog.plugins.pipelineprocessor.db.PipelineService)5 RuleDao (org.graylog.plugins.pipelineprocessor.db.RuleDao)5 ParseException (org.graylog.plugins.pipelineprocessor.parser.ParseException)5 EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)5 Collection (java.util.Collection)4 Collectors (java.util.stream.Collectors)4 Inject (javax.inject.Inject)4 PipelineStreamConnectionsService (org.graylog.plugins.pipelineprocessor.db.PipelineStreamConnectionsService)4 PipelineRuleParser (org.graylog.plugins.pipelineprocessor.parser.PipelineRuleParser)4 PipelineConnections (org.graylog.plugins.pipelineprocessor.rest.PipelineConnections)4 DateTime (org.joda.time.DateTime)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 Graph (com.google.common.graph.Graph)3