Skip to content

Instantly share code, notes, and snippets.

@Faldrian
Last active August 24, 2017 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Faldrian/8752242b880926ae7296013dadcb78ed to your computer and use it in GitHub Desktop.
Save Faldrian/8752242b880926ae7296013dadcb78ed to your computer and use it in GitHub Desktop.
Ein paar Handgriffe um mal eben ein Logfile zu sezieren.

Ziel

Man hat eine Logdatei (oder mehrere?), die man mal eben durchsuchen und auswerten möchte.

Aufruf

docker run -p 5601:5601 -p 9200:9200 -p 5044:5044 -v lokaleslogfile:/tmp/dockerlogfile.log -v lokaleconfig:/etc/logstash/conf.d/03-file-input.conf -it --name elk sebp/elk

  • lokaleslogfile: Vollständiger Dateipfad zur zu untersuchenden Datei
  • lokaleconfig: Pfad zur Logstash-Config (Beispiel siehe unten)

Unter localhost:5601 kann man dann Kibana aufrufen. Doku zum Docker-Paket: https://elk-docker.readthedocs.io/

Logstash-Config

In der folgenden Datei muss man noch die GROK-Zeile so anpassen, dass die passenden Felder extrahiert werden - nach Geschmack. Doku zu GROK-Patterns: https://github.com/logstash-plugins/logstash-patterns-core/tree/master/patterns Grok-Debugger um die Pattern zu testen: https://grokdebug.herokuapp.com/

input {
  file {
    path => "/tmp/dockerlogfile.log"
    start_position => "beginning"
  }
}

filter {
  grok {
    match => { "message" => "%{TIMESTAMP_ISO8601:timestamp} %{WORD:level} \[%{JAVACLASS:class}\] Dataset %{DATA:dataset}\: %{GREEDYDATA:errormsg}" }
  }
  date {
    match => [ "timestamp" , "yyyy-MM-dd:HH:mm:ss.SSS" ]
  }
}

output {
  elasticsearch { hosts => localhost }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment