metron-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cestella <...@git.apache.org>
Subject [GitHub] incubator-metron pull request #438: METRON-686 Record Rule Set that Fired Du...
Date Fri, 10 Feb 2017 14:16:57 GMT
Github user cestella commented on a diff in the pull request:

    https://github.com/apache/incubator-metron/pull/438#discussion_r100542070
  
    --- Diff: metron-platform/metron-enrichment/src/main/java/org/apache/metron/threatintel/triage/ThreatTriageProcessor.java
---
    @@ -52,15 +74,36 @@ public ThreatTriageProcessor( SensorEnrichmentConfig config
     
       @Nullable
       @Override
    -  public Double apply(@Nullable Map input) {
    -    List<Number> scores = new ArrayList<>();
    +  public ThreatScore apply(@Nullable Map input) {
    +
    +    ThreatScore threatScore = new ThreatScore();
         StellarPredicateProcessor predicateProcessor = new StellarPredicateProcessor();
    +    StellarProcessor processor = new StellarProcessor();
         VariableResolver resolver = new MapVariableResolver(input, sensorConfig.getConfiguration(),
threatIntelConfig.getConfig());
    +
    +    // attempt to apply each rule to the threat
         for(RiskLevelRule rule : threatTriageConfig.getRiskLevelRules()) {
           if(predicateProcessor.parse(rule.getRule(), resolver, functionResolver, context))
{
    -        scores.add(rule.getScore());
    +
    +        // add the rule's score to the overall threat score
    +        String reason = execute(rule.getReason(), processor, resolver, String.class);
    +        RuleScore score = new RuleScore(rule, reason);
    +        threatScore.addRuleScore(score);
           }
         }
    -    return threatTriageConfig.getAggregator().aggregate(scores, threatTriageConfig.getAggregationConfig());
    +
    +    // calculate the aggregate threat score
    +    Aggregators aggregators = threatTriageConfig.getAggregator();
    +    List<Number> allScores = threatScore.getRuleScores().stream().map(score ->
score.getRule().getScore()).collect(Collectors.toList());
    +    Double aggregateScore = aggregators.aggregate(allScores, threatTriageConfig.getAggregationConfig());
    +
    +    // return the overall threat score
    +    threatScore.setScore(aggregateScore);
    +    return threatScore;
    +  }
    +
    +  private <T> T execute(String expression, StellarProcessor processor, VariableResolver
resolver, Class<T> clazz) {
    +    Object result = processor.parse(expression, resolver, functionResolver, context);
    --- End diff --
    
    Ok, so, yes, I have an opinion about that.  Sadly, with the current implementation of
Stellar, we cannot cache the parse tree and then apply it after the fact.  It's just an artifact
of how we do the parsing: we actually execute the statement as we parse rather than constructing
an AST that can then be evaluated later given a message.
    
    I think this would be a GREAT modification to Stellar and one that I had on my mental
backlog for some time.  In fact, I took the opportunity as part of the profiler window DSL
to do it the right way (parse to an object that can then be cached and evaluated on multiple
sets of inputs without reparse).
    
    tl;dr: We can't do it now easily, BUT we should for multiple reasons:
    * code clarity - decoupling the stellar language from the generated parser code
    * performance - saving lexing and parsing


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message