Coder Social home page Coder Social logo

fail2ban-grok-log-pattern's Introduction

Fail2ban GROK Log Pattern

This is just a Fail2ban log GROK pattern to extract useful infor from fail2ban logs.

todo aka please help

I don't completely understand the fail2ban log format and you'll see two variables that are (imo) absolute rubbish. Pull requests welcome.

Updated on 3/20/19

Can now be used as a filter.conf file that you can put into an already in development .conf file, or as a seperate filter file depending on your conf.d architecture.

fail2ban-grok-log-pattern's People

Contributors

incredincomp avatar kurobeats avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

fail2ban-grok-log-pattern's Issues

Better pattern

Hi,

I used your pattern as starting point. Because fail2ban in v0.10+ can handle IPv6 you might change the pattern. Furthermore on "service" (the name of the triggered fail2ban jail) might contain "-" or other chars, the grok pattern "WORD" might not work then.

OLD version:
"pattern" : "%{TIMESTAMP_ISO8601:timestamp},%{INT:fail2ban_digit} fail2ban.%{WORD:fail2ban_action} *\[%{INT:fail2ban_digit2}\]: %{LOGLEVEL:level} *\[%{WORD:service}\] %{WORD:ban_status} %{IPV4:clientip}"

NEW version:
"pattern" : "%{TIMESTAMP_ISO8601:timestamp},%{INT:fail2ban_digit} fail2ban.%{WORD:fail2ban_action} *\[%{INT:fail2ban_digit2}\]: %{LOGLEVEL:level} *\[%{GREEDYDATA:service}\] %{WORD:ban_status} %{IP:clientip}"

You want it even better? In logstash I'm namespacing the output, to have a cleaner access (e.g. in Kibana Discover tab), here's my very own, namespaced pattern:
%{TIMESTAMP_ISO8601:[f2b][timestamp]},%{INT:[f2b][fail2ban_digit]} fail2ban.%{WORD:[f2b][fail2ban_action]} *\[%{INT:[f2b][fail2ban_digit2]}\]: %{LOGLEVEL:[f2b][loglevel]} *\[%{GREEDYDATA:[f2b][service]}\] %{WORD:[f2b][ban_status]} %{IP:[f2b][clientip]}

The output will then be:

{
"[f2b][timestamp]": "2018-01-01 12:00:00",
"[f2b][service]": "my-own-jail",
"[f2b][clientip]": "1.2.3.4",
"[f2b][fail2ban_action]": "actions",
"[f2b][ban_status]": "Ban",
"[f2b][fail2ban_digit]": "123",
"[f2b][fail2ban_digit2]": "4567",
"[f2b][loglevel]": "NOTICE"
}

Regarding your "To Do/Help Wanted"

The first "random" number (,INT) is actually part of the timestamp. It is ISO8601 timestamp format's representation of the fraction of the second. So it is not a separate field.

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.