Last active
August 1, 2020 00:48
-
-
Save sakalajuraj/6339942 to your computer and use it in GitHub Desktop.
Logstash filter for squid log
This file contains hidden or 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
# Content of the file /etc/logstash/conf.d/squid.conf | |
# Squid logs MAC address of the source host | |
# Logs are sending by syslog-ng raw without standard log headers | |
input { | |
tcp { | |
host => "xxx.xxx.xxx.xxx" | |
port => xxxx | |
type => SQUID | |
tags => [SQUID] | |
} | |
} | |
filter { | |
if [type] == "SQUID" { | |
grok { | |
match => [ "message", "%{NUMBER:timestamp}\s+%{NUMBER:request_msec:float} %{IPORHOST:src_ip} %{COMMONMAC:src_mac} %{WORD}/%{NUMBER:response_status:int} %{NUMBER:response_size:int} %{WORD:http_method} (%{URIPROTO:http_proto}://)?%{IPORHOST2:dst_host}(?::%{POSINT:port})?(?:%{NOTSPACE:uri_param})? %{USERNAME:user} %{WORD}/(%{IPORHOST:dst_ip}|-) %{GREEDYDATA:content_type}" ] | |
} | |
date { | |
match => [ "timestamp", "UNIX" ] | |
remove_field => [ "timestamp" ] | |
} | |
if [dst_ip] { | |
geoip { | |
source => "dst_ip" | |
target => "dst_geoip" | |
database => "/opt/logstash/vendor/geoip/GeoLiteCity.dat" | |
fields => [ "country_code2", "country_name" ] | |
} | |
} | |
} | |
} | |
output { | |
if [type] == "SQUID" { | |
elasticsearch { | |
flush_size => 1000 | |
protocol => "transport" | |
host => "xxx.xxx.xxx.xxx" | |
cluster => "xxxxx" | |
index => "logstash-squid-%{+YYYY.MM.dd}" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Should be
%{IPORHOST}
Try this instead:
%{NUMBER:timestamp}%{SPACE}%{NUMBER:request_msec:float} %{IPORHOST:src_ip} %{WORD}/%{NUMBER:response_status:int} %{NUMBER:response_size} %{WORD:http_method} (%{URIPROTO:http_proto}://)?%{IPORHOST:dst_host}(?::%{POSINT:port})?(?:%{NOTSPACE:uri_param})? %{USERNAME:user} %{WORD}/(%{IPORHOST:dst_ip}|-)%{GREEDYDATA:content_type}