Skip to content

Instantly share code, notes, and snippets.

@lathspell
Created November 9, 2014 03:04
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 lathspell/c8ce4e406ea828cd70a3 to your computer and use it in GitHub Desktop.
Save lathspell/c8ce4e406ea828cd70a3 to your computer and use it in GitHub Desktop.
Logstash configuration (playing around)
#
# Resources:
# - Logstash manual at http://logstash.net/
# - Grok Pattern Debugger at http://grokdebug.herokuapp.com/
# - Other patterns at /opt/logstash/pattern/
#
input {
syslog {
type => syslog
host => "localhost"
port => 5000
}
file {
type => "apache_access"
exclude => ["*.gz","*.zip","*.tgz"]
path => [ "/var/log/apache2/access.log" ]
sincedb_path => "/dev/null"
}
file {
type => "apache_error"
exclude => ["*.gz","*.zip","*.tgz"]
path => [ "/var/log/rsyslog2/error.log" ]
sincedb_path => "/dev/null"
}
file {
type => "dpkg_log"
path => [ "/var/log/dpkg.log" ]
sincedb_path => "/dev/null"
}
}
filter {
if [type] == "syslog" {
if [program] =~ /^postfix\// {
# Using postfix.conf from https://gist.github.com/poolski/9911628
# Parse generic Postfix Syslog line
grok {
patterns_dir => ["/etc/logstash/patterns"]
match => [ "program", "^%{COMPID}" ]
add_field => [ "_parsed", "postfix_compid" ]
}
# Parse Postfix components using hand crafted patterns
grok {
patterns_dir => ["/etc/logstash/patterns"]
match => { "message" => "^%{PF}" }
add_field => [ "_parsed", "postfix_pf" ]
}
# Parse Postfix using default Key-Value match
if ! ("postfix_pf" in [_parsed]) {
grok {
patterns_dir => ["/etc/logstash/patterns"]
match => { "message" => "^%{QUEUEID:qid}:" }
add_field => [ "_parsed", "postfix_qid" ]
}
kv {
source => "message"
trim => "<>\[\],"
add_field => [ "_parsed", "postfix_kv" ]
}
}
}
} else if [type] == "apache_access" {
grok {
match => { "message" => "%{COMBINEDAPACHELOG}" }
}
date {
match => [ "timestamp" , "dd/MMM/yyyy:HH:mm:ss Z" ]
}
} else if [type] == "apache_error" {
grok {
match => { "message" => "%{COMBINEDAPACHELOG}" }
}
date {
match => [ "timestamp" , "dd/MMM/yyyy:HH:mm:ss Z" ]
}
} else if [type] == "dpkg_log" {
grok {
patterns_dir => ["/etc/logstash/patterns"]
match => { "message" => "^%{DPKG_LOG}$" }
add_field => [ "_parsed", "dpkg_log" ]
}
}
}
output {
stdout {
codec => "rubydebug"
}
elasticsearch {
embedded => true
}
}
# vim: syntax=logstash ts=4 sw=4 expandtab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment