Created
June 2, 2014 15:39
-
-
Save gerardorochin/36d2b1be8b65ca0c7373 to your computer and use it in GitHub Desktop.
php error logging into logstash + elasticsearch and trace errors on single line and root path hidden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
input { | |
file { | |
type => "php-error" | |
path => "/var/www/error_log" | |
sincedb_path => "/opt/logstash/sincedb-access" | |
} | |
} | |
filter { | |
mutate { | |
gsub => [ | |
"message", "/var/www", "", | |
"message", "/var/www", "", | |
"path", "/var/www", "" | |
] | |
} | |
if [type] == "php-error" { | |
grok { | |
match => [ "message", "\[%{MONTHDAY:day}-%{MONTH:month}-%{YEAR:year} %{TIME:time} %{WORD:zone}/%{WORD:country}\] PHP %{DATA:level}\: %{GREEDYDATA:error}" ] | |
add_field => { "timestamp" => "%{day}-%{month}-%{year} %{time} %{zone}/%{country}" } | |
add_tag => [ "%{level}" ] | |
remove_field => [ "day", "month", "year", "time", "zone", "country" ] | |
} | |
multiline { | |
pattern => "(Stack trace:)|(^#.+)|(^\"\")|( thrown+)|(^\s)" | |
what => "previous" | |
} | |
date { | |
timezone => "America/Mexico_City" | |
match => [ "timestamp" , "yyyy-MM-dd HH:mm:ss", "dd-MMM-yyyy HH:mm:ss ZZZ" ] | |
target => "@timestamp" | |
remove_field => "timestamp" | |
} | |
} | |
mutate { | |
uppercase => [ "level" ] | |
lowercase => [ "tags" ] | |
gsub => [ | |
"tags", " ", "_", | |
"level", " ", "_" | |
] | |
} | |
} | |
output { | |
stdout { | |
codec => rubydebug | |
} | |
elasticsearch { | |
host => "localhost" | |
} | |
} |
Thank you
So our logs have a different date format - instead of Region/CIty we get the timezone (UTC).
The following works for us:
match => [ "message", "\[%{MONTHDAY:day}-%{MONTH:month}-%{YEAR:year} %{TIME:time} %{WORD:zone}\] PHP %{DATA:level}\: %{GREEDYDATA:error}" ]
add_field => { "timestamp" => "%{day}-%{month}-%{year} %{time} %{zone}" }
Any reason why the "message", "/var/www", "", line is listed twice within mutate?
For security reasons, hide your path
Since Logstash has now deprecated the multiline
filter, I've written something similar using the multiline
input codec: https://gist.github.com/kamermans/f53aa58bbd14a3fff9541b76064efa1a
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Single line
Multiline with trace error