Skip to content

Instantly share code, notes, and snippets.

@jblomo
Forked from sritchie/logstash.conf
Last active August 21, 2018 02:44
Show Gist options
  • Save jblomo/2c7cca06a0a6c351f3c6 to your computer and use it in GitHub Desktop.
Save jblomo/2c7cca06a0a6c351f3c6 to your computer and use it in GitHub Desktop.
Heroku Logstash config
input {
# Testing:
# tcp {
# type => "heroku"
# port => 3333
# }
# stdin { type => "stdin"}
tcp {
type => "heroku"
port => 1514
}
}
filter {
if [type] == "heroku" {
grok {
match => {"message" => "^%{POSINT:syslog_octet_size:int} %{SYSLOG5424PRI}%{NONNEGINT:syslog5424_ver} +(?:%{TIMESTAMP_ISO8601:syslog5424_ts}|-) +(?:%{HOSTNAME:syslog5424_host}|-) +(?:%{WORD:syslog5424_app}|-) +(?:%{HOSTNAME:syslog5424_proc}|-) +(?:%{WORD:syslog5424_msgid}|-) +(?:%{SYSLOG5424SD:syslog5424_sd}|-|) +%{GREEDYDATA:syslog5424_msg}" }
add_field => [ "drain_token", "%{syslog5424_host}" ]
add_field => [ "component", "%{syslog5424_app}" ]
add_field => [ "received_at", "%{@timestamp}" ]
add_field => [ "received_from", "%{host}" ]
}
grok {
match => { "syslog5424_proc" => "%{WORD:process}(?:\.%{INT:instance:int})?" }
}
if !("_grokparsefailure" in [tags]) {
date {
match => [ "syslog5424_ts", "ISO8601" ]
}
multiline {
# max syslog packet size
pattern => "^1116 "
stream_identity => "%{host}.%{@type}.%{component}.%{process}.%{instance}."
what => next
}
if "multiline" in [tags] {
mutate {
join => ["syslog5424_msg", ""]
}
}
mutate {
replace => [ "message", "%{syslog5424_msg}" ]
}
if [component] == "heroku" {
kv { add_tag => ["kv", "parsed"] }
}
if [message] =~ "^@cee" {
mutate {
add_tag => "cee"
gsub => ["message", "^@cee:\s*", ""]
}
json {
source => "message"
target => "msg_data"
add_tag => ["json", "parsed"]
}
}
if "parsed" in [tags] {
mutate {
remove_field => ["message"]
}
}
}
else {
# not grok'd!
mutate {
add_field => [ "drain_token", "unknown" ]
add_field => [ "component", "unknown" ]
}
}
}
}
output {
# Testing:
# stdout {
# debug => true
# debug_format => "json"
# }
elasticsearch { embedded => true }
file {
path => "./output-logs/%{drain_token}/%{component}/%{+YYYY-MM-dd}/logstash.log"
}
}
@jblomo
Copy link
Author

jblomo commented Feb 2, 2014

Had an issue with SYSLOG5424LINE: it expects the app to be a WORD, when it could be WORD.INT (which is matched later, so maybe SYSLOG5424LINE was redefined earlier?)

@jblomo
Copy link
Author

jblomo commented Feb 8, 2014

Heroku's syslog may break up log lines into multiple syslog packets. The heuristic used above is that when a syslog packet is exactly 1116 (the max length used by Heroku), assume it will carry over to the next line. It is possible this will cause a problem with lines exactly that length.

@jblomo
Copy link
Author

jblomo commented Feb 8, 2014

JSON lines are indicated with the @Cee prefix (see http://cee.mitre.org/language/1.0-beta1/cls.html), which can be produced with Lograge::Formatters::Cee (https://github.com/roidrage/lograge)

@caseydm
Copy link

caseydm commented Aug 21, 2018

Hi Jim. I am trying to set this up on a cluster set up at Elastic Cloud. What URL should I use for the log drain? Do you think this config still works for Heroku?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment