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?
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']
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.
@jnsd03
Ideally, you should click Accept to close this question and if you have different query (even if related), ask another question.
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']
I was able to name the attachment using the instructions I listed above.
Glad you figured it out. Mark the answer as accepted and close the thread.
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.
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)