Reporting

Splunk 7.2 Update sendemail for custom csv attachment names

jnsd03
Explorer

I would like to be able to customize the name of the csv attachments sent using the sendemail function. Is there any other way to do this besides editing the sendemaily.py script?

0 Karma
1 Solution

jnsd03
Explorer

I was able to do this after following the instruction in https://answers.splunk.com/answers/612925/how-to-set-attachment-name-in-sendemail-command.html but I also had to add this to line 525 of my custome sendmail.py script to allow the attachment to also be passed a custome field name:

if ssContent.get('action.email.reportFileName'):
    stringsForPost['action.email.reportFileName'] = ssContent['action.email.reportFileName']

View solution in original post

0 Karma

jawaharas
Motivator

You can use $result.fieldname$ token for custom field value in the email.

| makeresults
| eval today=strftime(now(),"%d-%m-%Y")
| table

For this sample query, use $result.today$ in your email subject to get today's date.

0 Karma

jawaharas
Motivator

@jnsd03
Ideally, you should click Accept to close this question and if you have different query (even if related), ask another question.

0 Karma

jnsd03
Explorer

I was able to do this after following the instruction in https://answers.splunk.com/answers/612925/how-to-set-attachment-name-in-sendemail-command.html but I also had to add this to line 525 of my custome sendmail.py script to allow the attachment to also be passed a custome field name:

if ssContent.get('action.email.reportFileName'):
    stringsForPost['action.email.reportFileName'] = ssContent['action.email.reportFileName']
0 Karma

jnsd03
Explorer

I was able to name the attachment using the instructions I listed above.

0 Karma

jawaharas
Motivator

Glad you figured it out. Mark the answer as accepted and close the thread.

0 Karma

jnsd03
Explorer

I would like to format today's date and use it in the subject and attachment_name but I haven't found a good solution for that. I am able to use the $job.latestTime$ in the subject but I can't format it and it's not being read by in the attachment_name.

0 Karma

jawaharas
Motivator

sendmail documentation doesn't have any options to modify file name of attachment. Be default, the attachment name is the report name (with timestamp as suffix) that generates the alert .

To modify the file name of attachment,
1. Either change the report name
2. Or modify the sendmail.py script

# sendmail.py | Line 1179, 1180
filename = pu.makeReportName(pattern=fileName, type="csv", reportProps=props)
csvAttachment.add_header('Content-Disposition', 'attachment', filename=filename)
0 Karma
Get Updates on the Splunk Community!

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...