Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

METRON-1893 Syslog RFC-3164 parser #1279

Closed
wants to merge 6 commits into from

Conversation

ottobackwards
Copy link
Contributor

This PR adds a new parser for Syslog RFC-3164

This PR also moves from simple-syslog-5424 to simple-syslog, which has both RFC parsers in it. So the Syslog5424Parser is updated as well.

The parsers are refactored to a common base since they share interfaces.

Testing, throw some 3164 logs at it.

Pull Request Checklist

Thank you for submitting a contribution to Apache Metron.
Please refer to our Development Guidelines for the complete guide to follow for contributions.
Please refer also to our Build Verification Guidelines for complete smoke testing guides.

In order to streamline the review of the contribution we ask you follow these guidelines and ask you to double check the following:

For all changes:

  • Is there a JIRA ticket associated with this PR? If not one needs to be created at Metron Jira.
  • Does your PR title start with METRON-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
  • Has your PR been rebased against the latest commit within the target branch (typically master)?

For code changes:

  • [-] Have you included steps to reproduce the behavior or problem that is being changed or addressed?

  • [-] Have you included steps or a guide to how the change may be verified and tested manually?

  • Have you ensured that the full suite of tests and checks have been executed in the root metron folder via:

    mvn -q clean integration-test install && dev-utilities/build-utils/verify_licenses.sh 
    
  • Have you written or updated unit tests and or integration tests to verify your changes?

  • If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under ASF 2.0?

  • [-] Have you verified the basic functionality of the build by building and running locally with Vagrant full-dev environment or the equivalent?

For documentation related changes:

  • [-] Have you ensured that format looks appropriate for the output in which it is rendered by building and verifying the site-book? If not then run the following commands and the verify changes via site-book/target/site/index.html:

    cd site-book
    mvn site
    

Note:

Please ensure that once the PR is submitted, you check travis-ci for build issues and submit an update to your PR as soon as possible.
It is also recommended that travis-ci is set up for your personal repository such that your branches are built there before submitting a pull request.


Copyright 2018 simple-syslog-5424 authors.

(ASLv2) simple-syslog-5424
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/5424/3164/?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch, fixed. Thanks!

…s may further process the embedded syslog fields/message
@nickwallen
Copy link
Contributor

The actual parsing here is done by an external dependency at https://github.com/palindromicity/simple-syslog, right? And you are the sole author of that library?

My only concern is that we need to look at all external dependencies with a critical eye to ensure there is a community backing those. A community that can provide continued support with bug and security patches.

This is the same approach we have taken when reviewing our web dependencies recently. We've tried to avoid dependencies that don't have that community backing. Its difficult to make the case to accept simple-syslog as a dependency, when we have turned down other similar single author web dependencies.

And this is a difficult point for me to make being that the sole author of simple-syslog is none other than @ottobackwards who is such an active and important contributor to Metron.

I am open to a healthy discussion on this. I could certainly be wrong on this, but I just want to make sure that we are applying the same standards across the project and ensure that the project can outlive any individual contributor.

Other than that, I really like what you've done with this parser @ottobackwards .

For reference, I am referring to the discussion that started on #1219 and spilled over to the mailing list.

@ottobackwards
Copy link
Contributor Author

ottobackwards commented Dec 14, 2018

Well, I guess I have to recuse my self from this discussion. I will only say these two things:

  • I contribute to more than one project, and having things that apply to more than on in my own organization allows for those things to shared. simple-syslog-5424 ( which has been rolled into the newer simple-syslog ) Provides the Syslog-5424 support for Apache Nifi as well as Metron.

  • This has already been accepted in master, this is the second pr to depend on syslog-* from my org.

@ottobackwards
Copy link
Contributor Author

So given that, you should move this discussion off this PR and to list because it involves a revert on master and removal of already accepted functionality

@mmiklavc
Copy link
Contributor

Adding my 2 cents here, but also happy to add these thoughts to a discuss thread if others want it. I think it definitely makes sense to qualify and justify the libraries we pull into Metron. To that end, we also do depend on many libraries that don't have a big community backing. In all cases I'm aware of, those libraries aren't the choice between "existing huge community-backed project and @ottobackwards personal OSS project." They're typically the only solution, or one of only a handful of a niche set of solutions for a particular problem. I think the main discussion point on #1219 was that there were other available solutions that solved the problem well without requiring the need for a custom fork. AFA the original PR that introduced the dependency, #1175, the only suggestion I would make going forward from a community perspective is to include a simple reason why a dependency has been added, ie "adding this bc there isn't a library that accomplishes this, it's used on multiple projects, etc." Basically, what Otto already described.

TL;DR - I think it's reasonable to request minimal justification for new libraries, and it's something to keep in mind in future PRs. Seems to me this dep is justified as I'm unaware of other alternatives that solve this problem. I am also very much in favor of enabling community members to contribute to, and cross pollinate with, other projects as Otto has done here.

Move the syslog parsers into the common module since like the grok parser
they can be exended to be used by other parsers who have syslog wrapped messages
@ottobackwards
Copy link
Contributor Author

Now that the parser split pr has landed, I have had to deconflict and refactor this. I have moved the syslog parsers into the parsing-common module, as they are designed to be the base of other parsers, similar to grok and the others. They parse the wrapper not the message.

For example, I could ( and may ) re-write the CEF, ASA and other processors on top of the syslog processors.

@nickwallen
Copy link
Contributor

On the dependency topic...

I am good with depending on simple-syslog assuming there are no other alternatives. I just want to be sure we're applying the same standards across the project when we look at dependencies.

I do agree that we should provide some minimal justification for new dependencies as @mmiklavc suggested. Going forward, if I introduce a new dependency, I will probably include something like... "Heads up. There is a new dependency X. I looked at these 3 alternatives with these pros and cons. I chose X because...".

And just to be clear, I am not saying that anything wrong was done on #1175. This is a good contribution to the project.

Copy link
Contributor

@nickwallen nickwallen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks good. I just have one question around how we are logically thinking about separating the parser projects. I just want to make sure I have in my head how we plan on doing that. It is a minor detail.

I was able to run this up in Stellar to play with it. Instructions below just for future reference by others. The only annoyance is that SHELL_EDIT does not work when you run Stellar this way. I am not sure why.

  1. Build Metron.

    mvn clean install -DskipTests=true -T2C
    
  2. Run Stellar directly on your development machine.

    java -cp "metron-stellar/stellar-common/target/stellar-common-0.7.0-uber.jar:metron-platform/metron-parsing/metron-parsers-common/target/metron-parsers-common-0.7.0-uber.jar:metron-platform/metron-common/target/metron-common-0.7.0.jar:metron-platform/metron-management/target/metron-management-0.7.0.jar"   org.apache.metron.stellar.common.shell.cli.StellarShell
    
  3. Create a message to parse.

    [Stellar]>>> msg := " <167>Jan  5 08:52:35 10.22.8.216 %ASA-7-609001: Built local-host inside:10.22.8.205"
     <167>Jan  5 08:52:35 10.22.8.216 %ASA-7-609001: Built local-host inside:10.22.8.205
    
  4. Initialize the parser.

    [Stellar]>>> conf := "{ \"parserClassName\":\"org.apache.metron.parsers.syslog.Syslog3164Parser\" }"
    { "parserClassName":"org.apache.metron.parsers.syslog.Syslog3164Parser" }
    
    [Stellar]>>> p := PARSER_INIT("syslog", conf)
    Parser{0 successful, 0 error(s)}
    
  5. Parse the message.

    [Stellar]>>> PARSER_PARSE(p, msg)
    [
      {
        "exception": "com.github.palindromicity.syslog.dsl.ParseException: Syntax error @ 1:1 no viable alternative at input '<'",
        "failed_sensor_type": "syslog",
        "stack": "com.github.palindromicity.syslog.dsl.ParseException: Syntax error @ 1:1 no viable alternative at input '<'\n\tat com.github.palindromicity.syslog.dsl.DefaultErrorListener.syntaxError(DefaultErrorListener.java:33)\n\tat org.antlr.v4.runtime.ProxyErrorListener.syntaxError(ProxyErrorListener.java:65)\n\tat org.antlr.v4.runtime.Parser.notifyErrorListeners(Parser.java:558)\n\tat org.antlr.v4.runtime.DefaultErrorStrategy.reportNoViableAlternative(DefaultErrorStrategy.java:310)\n\tat org.antlr.v4.runtime.DefaultErrorStrategy.reportError(DefaultErrorStrategy.java:147)\n\tat com.github.palindromicity.syslog.dsl.generated.Rfc3164Parser.timestamp(Rfc3164Parser.java:728)\n\tat com.github.palindromicity.syslog.dsl.generated.Rfc3164Parser.header(Rfc3164Parser.java:362)\n\tat com.github.palindromicity.syslog.dsl.generated.Rfc3164Parser.syslog_msg(Rfc3164Parser.java:267)\n\tat com.github.palindromicity.syslog.Rfc3164SyslogParser.parseLine(Rfc3164SyslogParser.java:57)\n\tat com.github.palindromicity.syslog.AbstractSyslogParser.lambda$parseLines$0(AbstractSyslogParser.java:144)\n\tat java.util.ArrayList.forEach(ArrayList.java:1249)\n\tat com.github.palindromicity.syslog.AbstractSyslogParser.parseLines(AbstractSyslogParser.java:142)\n\tat org.apache.metron.parsers.syslog.BaseSyslogParser.parseOptionalResult(BaseSyslogParser.java:102)\n\tat org.apache.metron.parsers.ParserRunnerImpl.execute(ParserRunnerImpl.java:144)\n\tat org.apache.metron.management.StellarParserRunner.lambda$doParse$3(StellarParserRunner.java:81)\n\tat java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)\n\tat java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)\n\tat java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)\n\tat java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1374)\n\tat java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)\n\tat java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)\n\tat java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)\n\tat java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)\n\tat java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)\n\tat org.apache.metron.management.StellarParserRunner.doParse(StellarParserRunner.java:82)\n\tat org.apache.metron.management.StellarParserRunner.parse(StellarParserRunner.java:66)\n\tat org.apache.metron.management.ParserFunctions$ParseFunction.apply(ParserFunctions.java:141)\n\tat org.apache.metron.stellar.common.StellarCompiler.lambda$exitTransformationFunc$13(StellarCompiler.java:664)\n\tat org.apache.metron.stellar.common.StellarCompiler$Expression.apply(StellarCompiler.java:259)\n\tat org.apache.metron.stellar.common.BaseStellarProcessor.parse(BaseStellarProcessor.java:151)\n\tat org.apache.metron.stellar.common.shell.DefaultStellarShellExecutor.executeStellar(DefaultStellarShellExecutor.java:407)\n\tat org.apache.metron.stellar.common.shell.DefaultStellarShellExecutor.execute(DefaultStellarShellExecutor.java:257)\n\tat org.apache.metron.stellar.common.shell.cli.StellarShell.execute(StellarShell.java:359)\n\tat org.jboss.aesh.console.AeshProcess.run(AeshProcess.java:53)\n\tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)\n\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)\n\tat java.lang.Thread.run(Thread.java:745)\nCaused by: org.antlr.v4.runtime.NoViableAltException\n\tat com.github.palindromicity.syslog.dsl.generated.Rfc3164Parser.timestamp(Rfc3164Parser.java:723)\n\t... 31 more\n",
        "hostname": "HW12402.local",
        "raw_message": " <167>Jan  5 08:52:35 10.22.8.216 %ASA-7-609001: Built local-host inside:10.22.8.205",
        "error_hash": "0ff645b6623aa4908abad04561588992be9d0882245279b34f3cfffe444346a3",
        "error_type": "parser_error",
        "guid": "69df49b0-4ee2-4fb8-a6ec-cad110761f15",
        "message": "Syntax error @ 1:1 no viable alternative at input '<'",
        "source.type": "error",
        "timestamp": 1545403638590
      }
    ]
    
  6. We got an error, but the error output looks good.

    [Stellar]>>> p
    Parser{0 successful, 1 error(s)}
    
  7. It was probably the leading whitespace I accidentally embedded in the message.

    [Stellar]>>> msg := "<167>Jan  5 08:52:35 10.22.8.216 %ASA-7-609001: Built local-host inside:10.22.8.205"
    <167>Jan  5 08:52:35 10.22.8.216 %ASA-7-609001: Built local-host inside:10.22.8.205
    
    [Stellar]>>> PARSER_PARSE(p, msg)
    [
      {
        "syslog.header.hostName": "10.22.8.216",
        "original_string": "<167>Jan  5 08:52:35 10.22.8.216 %ASA-7-609001: Built local-host inside:10.22.8.205",
        "syslog.header.facility": "20",
        "guid": "f9201e92-4c35-4391-95a4-e1d0cd54cdd7",
        "syslog.header.timestamp": "Jan  5 08:52:35",
        "syslog.message": "%ASA-7-609001: Built local-host inside:10.22.8.205",
        "syslog.header.pri": "167",
        "syslog.header.severity": "7",
        "timestamp": "Jan  5 08:52:35",
        "source.type": "syslog"
      }
    ]
    
  8. Yep, that was the problem.

    [Stellar]>>> p
    Parser{1 successful, 1 error(s)}
    

/**
* Parser for RFC 3164 messages.
*/
public class Syslog3164Parser extends BaseSyslogParser implements Serializable {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How are we reasoning about what goes in metron-parsers-common versus metron-parsers? Maybe this is a conversation that has already been had, but seems like this would go in metron-parsers because this is an individual parser.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expect the syslog parsers to be a common base for other processors, which are 'wrapped' in syslog. like the asa and cef. As such, the syslog capability is a base parser functionality imo.

@nickwallen
Copy link
Contributor

nickwallen commented Dec 21, 2018

Actually, I just noticed that the timestamp that was appended to the 'good' message in my example above is not epoch millis. Should that be epoch millis?

[Stellar]>>> PARSER_PARSE(p, msg)
[
  {
    "syslog.header.hostName": "10.22.8.216",
    "original_string": "<167>Jan  5 08:52:35 10.22.8.216 %ASA-7-609001: Built local-host inside:10.22.8.205",
    "syslog.header.facility": "20",
    "guid": "f9201e92-4c35-4391-95a4-e1d0cd54cdd7",
    "syslog.header.timestamp": "Jan  5 08:52:35",
    "syslog.message": "%ASA-7-609001: Built local-host inside:10.22.8.205",
    "syslog.header.pri": "167",
    "syslog.header.severity": "7",
    "timestamp": "Jan  5 08:52:35",
    "source.type": "syslog"
  }
]

@ottobackwards
Copy link
Contributor Author

So with regards to the timestamp. Simple-Syslog doesn't convert the time stamp, that is left to the caller, and that is something that I didn't handle.

I will update the parsers to work like the ASA parser.
And let you know when it is read.

@nickwallen
Copy link
Contributor

+1 Looks great.

@ottobackwards
Copy link
Contributor Author

thanks for the reviews

@asfgit asfgit closed this in 0dc9fc8 Dec 24, 2018
JonZeolla pushed a commit to JonZeolla/metron that referenced this pull request Jan 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants