Skip to content

Instantly share code, notes, and snippets.

@renanregis
Created January 15, 2018 12:34
Show Gist options
  • Save renanregis/4aa9951b55ef3f619679b23fb931fb11 to your computer and use it in GitHub Desktop.
Save renanregis/4aa9951b55ef3f619679b23fb931fb11 to your computer and use it in GitHub Desktop.
postgres_nginx
input {
beats {
port => 5044
type => "nginx"
}
jdbc {
jdbc_connection_string => "jdbc:postgresql://postgres:5432/postgres"
jdbc_driver_library => "/usr/share/logstash/jdbc/postgresql-42.1.4.jre6.jar"
jdbc_user => "postgres"
jdbc_password => "postgres"
jdbc_driver_class => "org.postgresql.Driver"
schedule => "* * * * *"
statement => "SELECT * from teste"
type => "postgres"
}
}
filter {
if [fileset][module] == "nginx" {
if [fileset][name] == "access" {
grok {
match => { "message" => ["%{IPORHOST:[nginx][access][remote_ip]} - %{DATA:[nginx][access][user_name]} \[%{HTTPDATE:[nginx][access][time]}\] \"%{WORD:[nginx][access][method]} %{DATA:[nginx][access][url]} HTTP/%{NUMBER:[nginx][access][http_version]}\" %{NUMBER:[nginx][access][response_code]} %{NUMBER:[nginx][access][body_sent][bytes]} \"%{DATA:[nginx][access][referrer]}\" \"%{DATA:[nginx][access][agent]}\""] }
remove_field => "message"
}
mutate {
add_field => { "read_timestamp" => "%{@timestamp}" }
}
date {
match => [ "[nginx][access][time]", "dd/MMM/YYYY:H:m:s Z" ]
remove_field => "[nginx][access][time]"
}
useragent {
source => "[nginx][access][agent]"
target => "[nginx][access][user_agent]"
remove_field => "[nginx][access][agent]"
}
geoip {
source => "[nginx][access][remote_ip]"
target => "[nginx][access][geoip]"
}
}
else if [fileset][name] == "error" {
grok {
match => { "message" => ["%{DATA:[nginx][error][time]} \[%{DATA:[nginx][error][level]}\] %{NUMBER:[nginx][error][pid]}#%{NUMBER:[nginx][error][tid]}: (\*%{NUMBER:[nginx][error][connection_id]} )?%{GREEDYDATA:[nginx][error][message]}"] }
remove_field => "message"
}
mutate {
rename => { "@timestamp" => "read_timestamp" }
}
date {
match => [ "[nginx][error][time]", "YYYY/MM/dd H:m:s" ]
remove_field => "[nginx][error][time]"
}
}
}
}
output {
if [type]=="nginx"{
elasticsearch {
index => "nginx-%{+YYYY.MM.dd}"
document_type => "logs"
manage_template => false
hosts => ["elasticsearch"]
}
}
if [type]=="postgres"{
elasticsearch {
index => "postgres-%{+YYYY.MM.dd}"
manage_template => false
document_type => "teste"
hosts => ["elasticsearch"]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment