Skip to content

Commit

Permalink
Handle the cases when there are no stream rules during creation
Browse files Browse the repository at this point in the history
  • Loading branch information
c8y3 committed Nov 6, 2024
1 parent 1baed73 commit bfa398e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,31 +117,45 @@ private TriggeringConditions createTriggeringConditionsFromStream(AlertRuleStrea
List<FieldRule> fieldRulesWithList = this.streamPipelineService.extractPipelineFieldRules(streamConfiguration.getFieldRules());

TriggeringConditions.Builder builder = TriggeringConditions.builder().filteringStreamIdentifier(filteringStreamIdentifier);
Stream.MatchingType matchingType = streamConfiguration.getMatchingType();
builder.matchingType(matchingType);
if (fieldRulesWithList.isEmpty()) {
return builder.outputStreamIdentifier(filteringStreamIdentifier).build();
String outputStreamIdentifier;
if (filteringStreamIdentifier == null) {
outputStreamIdentifier = Stream.DEFAULT_STREAM_ID;
} else {
outputStreamIdentifier = filteringStreamIdentifier;
}
return builder.outputStreamIdentifier(outputStreamIdentifier).build();
}

for (FieldRule fieldRule: fieldRulesWithList) {
this.alertListUtilsService.incrementUsage(fieldRule.getValue());
}

Stream.MatchingType matchingType = streamConfiguration.getMatchingType();
builder.matchingType(matchingType);
if (matchingType.equals(Stream.MatchingType.AND) && this.fieldRulesUtilities.hasStreamRules(streamConfiguration.getFieldRules())) {
PipelineDao graylogPipeline = this.streamPipelineService.createPipeline(title, matchingType, filteringStreamIdentifier);
if (!this.fieldRulesUtilities.hasStreamRules(streamConfiguration.getFieldRules())) {
PipelineDao graylogPipeline = this.streamPipelineService.createPipeline(title, matchingType, Stream.DEFAULT_STREAM_ID);
Stream outputStream = this.streamPipelineService.createStream(matchingType, title + " output", userName);
RuleDao pipelineRule = this.streamPipelineService.createPipelineRule(title, fieldRulesWithList, matchingType, outputStream.getId());
Pipeline pipeline = Pipeline.builder()
.identifier(graylogPipeline.id()).ruleIdentifier(pipelineRule.id()).fieldRules(fieldRulesWithList)
.build();
return builder.outputStreamIdentifier(outputStream.getId()).pipeline(pipeline).build();
} else {
} else if (matchingType.equals(Stream.MatchingType.OR)) {
PipelineDao graylogPipeline = this.streamPipelineService.createPipeline(title, matchingType, Stream.DEFAULT_STREAM_ID);
RuleDao pipelineRule = this.streamPipelineService.createPipelineRule(title, fieldRulesWithList, matchingType, filteringStreamIdentifier);
Pipeline pipeline = Pipeline.builder()
.identifier(graylogPipeline.id()).ruleIdentifier(pipelineRule.id()).fieldRules(fieldRulesWithList)
.build();
return builder.outputStreamIdentifier(filteringStreamIdentifier).pipeline(pipeline).build();
} else {
PipelineDao graylogPipeline = this.streamPipelineService.createPipeline(title, matchingType, filteringStreamIdentifier);
Stream outputStream = this.streamPipelineService.createStream(matchingType, title + " output", userName);
RuleDao pipelineRule = this.streamPipelineService.createPipelineRule(title, fieldRulesWithList, matchingType, outputStream.getId());
Pipeline pipeline = Pipeline.builder()
.identifier(graylogPipeline.id()).ruleIdentifier(pipelineRule.id()).fieldRules(fieldRulesWithList)
.build();
return builder.outputStreamIdentifier(outputStream.getId()).pipeline(pipeline).build();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
* The output stream is the stream on which the event feeds.
*
* There are 4 possible constructions:
* - no stream, no list conditions: filteringStream == null, outputStream == DEFAULT_STREAM
* - no stream conditions, no list conditions: filteringStream == null, outputStream == DEFAULT_STREAM
* - stream conditions only: pipeline == null, filteringStream == outputStream
* - list conditions only: pipeline -> outputStream, filteringStream == null
* - both stream and list conditions:
* If the conditions matching type is OR (at least one): pipeline -> outputString == filteringStream
* If the conditions matching type is OR (at least one): pipeline -> outputStream == filteringStream
* If the conditions matching type is AND (all): filteringStream -> pipeline -> outputStream
*/
@AutoValue
Expand Down

0 comments on commit bfa398e

Please sign in to comment.