Comment utiliser Elasticsearch, Logstash et Kibana pour gérer les logs Apache d’OVH PARTIE 3

Comment utiliser Elasticsearch, Logstash et Kibana pour gérer les logs Apache d’OVH PARTIE 3

Les différentes étapes sont expliquées pour une installation sur Mac OS 10.x

 

Fichier CONF Logstash pour créer le lien entre les Logs Apache téléchargés et Elsaticsearch

 

Créez un fichier apache_log.conf comme suit en adaptant les chemins aux fichiers :

input {
file {
type => "apache_access"
path => "/Users/monuser/logs/apache/access/*.log"
start_position => beginning
}
file {
type => "apache_error"
path => "/Users/monuser/logs/apache//error/*.log"
start_position => beginning
}
}
filter {
if [type] in [ "apache" , "apache_access" , "apache-access" ] {
grok {
match => [
"message" , "%{COMBINEDAPACHELOG}+%{GREEDYDATA:extra_fields}",
"message" , "%{COMMONAPACHELOG}+%{GREEDYDATA:extra_fields}"
]
overwrite => [ "message" ]
}
mutate {
convert => ["response", "integer"]
convert => ["bytes", "integer"]
convert => ["responsetime", "float"]
}
geoip {
source => "clientip"
target => "geoip"
add_tag => [ "apache-geoip" ]
}
date {
match => [ "timestamp" , "dd/MMM/YYYY:HH:mm:ss Z" ]
remove_field => [ "timestamp" ]
}
useragent {
source => "agent"
}
}
if [type] in ["apache_error","apache-error"] {
grok {
match => ["message", "[%{WORD:dayname} %{WORD:month} %{DATA:day} %{DATA:hour}:%{DATA:minute}:%{DATA:second} %{YEAR:year}] [%{NOTSPACE:loglevel}] (?:[client %{IPORHOST:clientip}] ){0,1}%{GREEDYDATA:message}"]
overwrite => [ "message" ]
}
mutate
{
add_field =>
{
"time_stamp" => "%{day}/%{month}/%{year}:%{hour}:%{minute}:%{second}"
}
}
date {
match => ["time_stamp", "dd/MMM/YYYY:HH:mm:ss"]
remove_field => [ "time_stamp","day","dayname","month","hour","minute","second","year"]
}
}
}
output {
elasticsearch {
index => "apache-log-%{+YYYY.MM.dd}"
}
}

 

On lance Logstash :

$ logstash -f chemin_fichier_conf/apache_log.conf

 

Configuration d’un nouvel index Elsaticsearch dans Kibana

Lancez votre navigteur et taper l’adresse suivante :

http://localhost:5601

Cliquez alors sur Management, puis sur Index Patterns et sur + Create Index Pattern

Vous devez avoir un message du genre « Your index pattern can match any of your » avec un nombre supérieur à 0 si tout à fonctionner. Vous devez avoir une liste d’indices du genre :

apache-log-2017.12.31
apache-log-2018.01.01
......

Dans la zone Index pattern saisissez alors apache-log-* et cliquez sur Next Step

En Time Filter field name sélectionnez @Timestamp et cliquez sur Create index pattern