How to send a single email after csv file saved and attached to email output plugin

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.

I am also struggling with the output email.

But there is an output to create csv

    csv {   
        fields  =>["case_id", "cpr"]
        csv_options => {
        #    "write_headers" => true
        #    "headers" =>["case_id","cpr"]
            "col_sep" => ";"
        path => "cpr_sagsnummer_liste-%{+YYYY-MM-dd-kk-mm}.csv"

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

I found a solution to my problem. one config file can create a csv AND send an email with the same csv, all in one A.conf. using if condition

Can I see your conf file?

below is the blue print of my conf file

input {
##use the input plugin as per your requirement

filter {
#filters script as per your requirement

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 => ''
  from => ''
  subject => 'Alert - %{title}'
  body => "Tags: %{tags}\\n\\Content:\\n%{message}"
  template_file => "/tmp/email_template.mustache"
  domain => ''
  port => 25
 attachments => "/home/clouduser/efg.csv"

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.