Skip to content

Instantly share code, notes, and snippets.

@clodio
Created May 29, 2015 13:42
Show Gist options
  • Save clodio/aad4e52c3d5de88b102f to your computer and use it in GitHub Desktop.
Save clodio/aad4e52c3d5de88b102f to your computer and use it in GitHub Desktop.
kibana_logstah_elasticserch geolocation from custom field
input {
file {
path => "/tmp/access_log"
start_position => "beginning"
#echo '98.83.179.51 - - [18/May/2011:19:35:08 -0700] "GET /css/main.css HTTP/1.1" 290 566 "http://www.safesand.com/information.htm" "Mozilla/5.0 (Windows NT 6.0; WOW64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1"1837' >>/tmp/access_log
}
}
filter {
if [path] =~ "access" {
mutate { replace => { "type" => "apache_access" } }
grok {
match => { "message" => "%{COMBINEDAPACHELOG}%{WORD:mob_regate}" }
}
}
date {
match => [ "timestamp" , "dd/MMM/yyyy:HH:mm:ss Z" ]
}
#récupere le nom du site et les données de géolocalisation à partir du code regate (mob_regate)
if [mob_regate] {
#need install translate plugin : bin/plugin install logstash-filter-translate
translate {
field => mob_regate
destination => site_information
exact => true
refresh_interval => 3600
dictionary_path => "/home/clodio/logstash-1.5.0/conf/site_information.yaml"
#dictionary => [ "566", [4.7204615, 45.3155245,"bourges PDC1" ],
# "1189",[2.3247297, 48.8202482,"loir PDC2" ],
# "1837",[2.055075, 48.788135,"félines PDC2" ] ]
}
# si les informations du site ont été trouvées, les données sont copiées dans le champs site et geoip (de type geo_point)
if [site_information] {
mutate {
add_field => [ "site", "%{site_information[2]}" ]
add_field => [ "[geoip][location]", "%{site_information[0]}" ]
add_field => [ "[geoip][location]", "%{site_information[1]}" ]
remove_field => "site_information"
}
mutate {
convert => [ "[geoip][location]", "float" ]
}
}
}
}
output {
elasticsearch {
host => localhost
template => "/home/clodio/logstash-1.5.0/conf/mapping.conf"
}
stdout { codec => rubydebug }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment