Hey,
I listen several files in a directory thanks to Filebeat and then I parse those who interest me. For exemple :
This file doesn't interest me because its "CODE RETOUR" value is 0 (last line) :
INFO;0000;000002;* LOG D'EXECUTION *
INFO;0000;000003;* /data/EDT/batchs/files/logs/WKF998MT-20180618-20180618-1302.log *
INFO;0000;000004;* 2018-06-18 13:03:09:420 *
INFO;0000;000005;* WKF998MT - calcul des statistiques *
INFO;0000;000008; le champ "FETCH_SIZE_VALUE" n'existe pas dans le fichier de propriétes du batch. utilisati
INFO;0000;000009; on de la valeur par défaut.
INFO;0000;000010;
INFO;0000;000011; Version de l'application : 13.13.200 (build : 149df21, date : 01-06-2018 17:02:30)
INFO;0000;000012; Version de l'architecture : 4.143.500 (build : 879ab1c, date : 30-04-2018 09:42:03)
INFO;0000;000013; Version du framework : 4.143.500 (build : 879ab1c, date : 30-04-2018 09:42:03)
INFO;0000;000014; Version EDK : 4.131.500 (build : 1561e01, date : 02-05-2018 14:58:47)
INFO;0000;000015; Version ecore : 4.140.500 (build : 3eef259, date : 03-05-2018 15:49:45)
INFO;0000;000016; Utilisateur Oracle : HERMES_USER
INFO;0000;000017; info BDD : 13.13.200 / UEM / METZ
INFO;0000;000574; Calcul des statistiques de campagnes :
INFO;0000;000575; Exécution OK
INFO;0000;000576; Temps d'exécution: 0h 0' 0" 15ms ms
INFO;0000;000580; TEMPS D'EXECUTION : 0h 0' 15" 255ms
INFO;0000;000582;CODE RETOUR : 0
This file interest me because its "CODE RETOUR" value is different of 0 :
INFO;0000;000003;* /data/EDT/batchs/files/logs/MNS014MT-20180612-20180613-0105.log *
INFO;0000;000005;* MNS014MT - Prélèvement et validation d'échéancier suite à saisie de RIB *
INFO;0000;000019; info BDD : 13.13.100 / UEM / METZ
MNOR;3011;000036; Erreur de traitement d'un élément
MNOR;3012;000037; Erreur lors de la mise en transaction
MNOR;4009;000038; aucune ligne de compte à mettre en transaction (compte:625316)
INFO;0000;000096;CODE RETOUR : -4
But how to drop file which contains "CODE RETOUR :0" ?
I'm currently able to parse my files and to drop lines which not interest me but i'm still unable to handle with those that contain "CODE RETOUR: 0" value.
I need to find a way to read the file, save the "CODE RETOUR" value in a variable and then add this new variable to every lines and then with filter drop all lines which CODE_RETOUR == "0"
..
My pipeline :
input
{
beats
{
port => 5044
}
}
filter
{
grok
{
match => { "message" => [ "%{WORD:TYPE};%{DATA:ID1};%{NUMBER:ID2};%{GREEDYDATA:DESCRIPTION}" ] }
}
if ([DESCRIPTION] =~ "CODE")
{
grok
{
match => { "DESCRIPTION" => [ "%{NUMBER:CODE_RETOUR}" ] }
}
}
if ([ID2] == "000003")
{
grok
{
match => { "DESCRIPTION" => [ "%{WORD:NOM_BATCH}-%{BASE16NUM:DATE_BATCH}" ] }
}
ruby { code => "@@save_the_date = event.get('DATE_BATCH')" }
ruby { code => "@@save_the_name = event.get('NOM_BATCH')" }
}
else
{
ruby { code => "event.set('DATE_BATCH', @@save_the_date)" }
ruby { code => "event.set('NOM_BATCH', @@save_the_name)" }
}
if ([TYPE] == "INFO")
{
if ([ID2] != "000003" and [ID2] != "000005")
{
if ([DESCRIPTION] !~ "info BDD" and [DESCRIPTION] !~ "CODE RETOUR")
{
drop { }
}
}
}
if "_grokparsefailure" in [tags]
{
drop { }
}
date
{
match => [ "DATE_BATCH", "yyyyMMdd" ]
}
mutate
{
remove_field => [ "@version","ID1","_id","_index","_score","_type","beat.hostname","beat.name","beat.version","filetype","host","offset","prospector.type" ]
convert => { "CODE_RETOUR" => "integer" }
}
}
output
{
elasticsearch
{
hosts => "http://localhost:9200"
index => "essai"
}
stdout { codec => rubydebug }
}
I don't know if something like that is possible to inplement on filebeat conf file :
processors:
- drop_file:
when:
regexp:
message: "^CODE RETOUR : 0:"
Thx for all