Skip to content

Instantly share code, notes, and snippets.

@martinseener
Last active December 15, 2015 20:19
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 martinseener/5318215 to your computer and use it in GitHub Desktop.
Save martinseener/5318215 to your computer and use it in GitHub Desktop.
Grok Apache2 Custom-Pattern (streamlined Custom-Log to comply Error Log and enhanced Custom Log by adding more information)
filter {
grok {
pattern => ['(?:%{SYSLOGTIMESTAMP:timestamp}|%{TIMESTAMP_ISO8601:timestamp8601}) (?:%{SYSLOGHOST:logsource}) (?:%{SYSLOGPROG}): (?<messagebody>\[%{DAY} %{MONTH} %{MONTHDAY} %{HOUR}:%{MINUTE}:%{SECOND} %{YEAR}\] \[%{LOGLEVEL:severity}\] \[client %{IP:a2_client_ip}\] (?:Request: \"%{GREEDYDATA:a2_request}\" %{INT:a2_http_code} (?:%{GREEDYDATA:a2_sent_bytes}|%{INT:a2_sent_bytes}) %{INT:a2_response_time} %{GREEDYDATA:a2_referer}\" \"%{GREEDYDATA:a2_user_agent}\" \"%{GREEDYDATA:a2_ssl_protocol}\" \"%{GREEDYDATA:a2_ssl_cipher}\"|Request: \"%{GREEDYDATA:a2_request}\" %{INT:a2_http_code} (?:%{GREEDYDATA:a2_sent_bytes}|%{INT:a2_sent_bytes}) %{INT:a2_response_time} \"%{GREEDYDATA:a2_referer}\" \"%{GREEDYDATA:a2_user_agent}\")|%{GREEDYDATA})']
type => "apache2"
}
}
# Apache 2 Logformat for customlog with SSL/TLS Logging (last part "rsysloghostnames" can be changed to anything else)
LogFormat "[%{%a %b %d %H:%M:%S %Y}t] [info] [client %h] Request: \"%m http(s)://%{Host}i%U%q %H\" %>s %b %D \"%{Referer}i\" \"%{User-Agent}i\" \"%{SSL_PROTOCOL}x\" \"%{SSL_CIPHER}x\"" rsysloghostnamesssl
# Example central Syslog Entry for Pattern
2013-04-09T11:33:35+02:00 apachehost9 a2_ruby_vhost1: [Tue Apr 09 11:33:35 2013] [info] [client 10.10.200.12] Request: "GET http(s)://ruby-app.example.com/subdir/?id=1 HTTP/1.1" 200 2524 808 "http://ruby-app.example.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:20.0) Gecko/20100101 Firefox/20.0" "TLSv1" "RC4-SHA"
@martinseener
Copy link
Author

Updated to also log SSL Protocol and used SSL Cipher

@martinseener
Copy link
Author

Further enhanced Grok Pattern to support more types of log messages and now separates the messagebody from the header

@martinseener
Copy link
Author

in Revision 8 i streamlined the loglevel from a2_loglevel to the central severity field (easier to search!)

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