Giter Club home page Giter Club logo

Comments (6)

zhenjl avatar zhenjl commented on July 19, 2024

Thanks @alexzorin! This message helped identify a couple scanner bugs I had to fix.

I do have a nugget for you tho. Assuming you just want to consume all the tokens to the end of the string, you can do something like

%msgtime% H = ( %srchost% ) [ %srcipv4% ] : %srcport% F = < %srcemail% > %action% RCPT < %dstemail% > : %reason-%

Notice the %reason-% field, basically the "-" tells the parser to consume the rest of the tokens and put them in the %reason% field. So "sender verify failed" will be put into %reason% in this case.

I haven't written much about it yet as I am still trying to test out a few meta characters to see how to make it easier for parsing.

Try it and let me know if it works for you.

Thanks for your help!

[edit: the - only works with Field types, and not Token types, at least not at this time. I should fix that]

from sequence.

alexzorin avatar alexzorin commented on July 19, 2024

Oh, very cool, thanks

from sequence.

alexzorin avatar alexzorin commented on July 19, 2024

Given your thoughts from the blog post about performance characteristics of regex parsers etc I think its doubtful, but do you think it would be within the realm of possibility in your scanner to do greedy consumption in the middle of a log string? Such as

# for messages ending in 'blah blah'
%time% %string-% blah blah

from sequence.

zhenjl avatar zhenjl commented on July 19, 2024

Certainly possible, though I don't think scanner is the place to do it. I try to keep the scanner purely for simple tokenization. However, we can do something in the parser.

In fact, if you have the following message and rule:

jan 14 10:15:56 testserver sudo: this is a weird log blah blah
%msgtime% %apphost% %appname% : %reason+% blah blah

Notice the "+" in the %reason% token, it tells the parser to continue adding %reason% fields until it hits the first "blah". The output is not exactly what I want yet:

%msgtime% "jan 14 10:15:56"
%apphost% "testserver"
%appname% "sudo"
%literal% ":"
%reason% "this"
%reason% "is"
%reason% "a"
%reason% "weird"
%reason% "log"
%literal% "blah"
%literal% "blah"

What I really want is to concatenate the 5 %reason% tokens into one...so stay tuned.

from sequence.

zhenjl avatar zhenjl commented on July 19, 2024

@alexzorin , I updated the parser to allow *, + and - as meta commands.

  • * means consume 0 or more tokens
  • + means consume 1 or more tokens
  • - means consume the rest of the tokens

All three will merge the multiple tokens recognized.

So your rule can be written as as any of the following:

"%msgtime% h = ( %srchost% ) [ %srcip% ] : %srcport% f = < %srcemail% > %action% rcpt < %dstemail% > : %reason:-%",
"%msgtime% h = ( %srchost% ) [ %srcip% ] : %srcport% f = < %srcemail% > %action% rcpt < %dstemail% > : %reason:+%",
"%msgtime% h = ( %srchost% ) [ %srcip% ] : %srcport% f = < %srcemail% > %action% rcpt < %dstemail% > : %reason:*%",

Let me know if you can test it out.

thx

Jian

from sequence.

alexzorin avatar alexzorin commented on July 19, 2024

Thanks, I'll try it out on my exim rules

from sequence.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.