My requirement is send a file ( extracting data from elastic search index is to save in CSV or excel format it contains 1000 records ) in a single mail through logstash output email plugin. is it possible or not?
weather it is possible using if else condition or filters ?
can any one help me on this issue and i am new to this tool.
Logstash will write a header for each line, its a mess, so I don't use the header option
For the email output, there is the attachments option. But I am struggling with sending emails so I haven't gotten to this bit yet.
attachments => "cpr_sagsnummer_liste-%{+YYYY-MM-dd-kk-mm}.csv"
you can send email only when the file is available
Attachment should be a existing file name with path
But in my case i have to save the csv file and send mail with the saved csv file, Both should be done one after another in in single logstash conf file
Logstash saves/creates the csv at the end of the execution, so one config file can't create a csv AND send an email with the same csv, all in one go. You can have a group of conf files all running on a schedule. A.conf creates the csv and B.csv sends the csv a few minutes later.
I found a solution to my problem.
I have row numbers in my log file. I'll send a mail when row_nr == 1, that way I only send one mail pr conf execution. And then I create a csv file on a shared drive
input {
##use the input plugin as per your requirement
}
filter {
#filters script as per your requirement
}
output{
csv {
fields => ["userid","name","country"]
path => "/home/clouduser/efg.csv"
}
if [name] == "smith" { ##smith is the name field in csv file to send single email because it matches if conditon ##
email {
to => 'technical@example.com'
from => 'monitor@example.com'
subject => 'Alert - %{title}'
body => "Tags: %{tags}\\n\\Content:\\n%{message}"
template_file => "/tmp/email_template.mustache"
domain => 'mail.example.com'
port => 25
attachments => "/home/clouduser/efg.csv"
}
}
}
}
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.