Skip to main content
Question

Is it possible to email from a Python Shutdown script on FME Server?

  • September 5, 2018
  • 7 replies
  • 47 views

tb09114
Supporter
Forum|alt.badge.img+22

I was wondering if it is possible to access the content of a workbenchs log file in a Shutdown Python script on FME Server and email the content.

I have a central workbench calling several other workbenches to perform analysis. I want to parse the finished log-file to get warnings, errors and information about features identified and written. The final statement if the run was successful is unfortunately not enough.

 

The parsed data should be send as text in an email.

Until now I was testing locally with success, but the same workbench at a 2018 server fails with FME_END_PYTHON failure.

import fme

 

import smtplib

 

from email.mime.text import MIMEText

 

from email.mime.multipart import MIMEMultipart

 

from email.utils import COMMASPACE, formatdate

 

 

def send_email(send_from, send_to, subject, text, server='*****'):

 

'''send email with analysis results'''

 

assert isinstance(send_to, list)

 

outer = MIMEMultipart()

 

outer['From'] = send_from

 

outer['To'] = COMMASPACE.join(send_to)

 

outer['Date'] = formatdate(localtime=True)

 

outer['Subject'] = subject

 

outer.attach(MIMEText(text))

 

smtp = smtplib.SMTP(server)

 

smtp.sendmail(send_from, send_to, outer.as_string())

 

smtp.close()

 

 

m_text = fme.logFileName

 

send_email('*****', ['*****'], 'Log file from server', m_text)

7 replies

erik_jan
Contributor
Forum|alt.badge.img+17
  • Contributor
  • September 5, 2018

Would it be an idea to use a Notification (email after successful run) instead of a shutdown script?

I have been using that a lot and it works fine and is easy to implement.


david_r
Evangelist
  • September 5, 2018

It should definitely be possible. But have you checked that all the necessary modules are available in the Python interpreter that's used on FME Server.

Also, can please you post the complete error message on FME Server.


david_r
Evangelist
  • September 5, 2018

An alternative is to "wrap up" the workspace in a master workspace that uses the FMEServerJobSubmitter followed by the FMEServerLogRetriever and an Email transformer.


jdh
Contributor
Forum|alt.badge.img+28
  • Contributor
  • September 5, 2018
erik_jan wrote:

Would it be an idea to use a Notification (email after successful run) instead of a shutdown script?

I have been using that a lot and it works fine and is easy to implement.

I second using a notification email. You can customise it in the "central workbench".

 

 


tb09114
Supporter
Forum|alt.badge.img+22
  • Author
  • Supporter
  • September 5, 2018
david_r wrote:

It should definitely be possible. But have you checked that all the necessary modules are available in the Python interpreter that's used on FME Server.

Also, can please you post the complete error message on FME Server.

As far as I can see is there not much of an error message. I attach a screenshot of the result data section

 

 

 


tb09114
Supporter
Forum|alt.badge.img+22
  • Author
  • Supporter
  • September 5, 2018
erik_jan wrote:

Would it be an idea to use a Notification (email after successful run) instead of a shutdown script?

I have been using that a lot and it works fine and is easy to implement.

I do not have huge experience in using the notification email, but if its possible to get the parsed data into the notification email then I will do this.

 

 


tb09114
Supporter
Forum|alt.badge.img+22
  • Author
  • Supporter
  • September 5, 2018
david_r wrote:

An alternative is to "wrap up" the workspace in a master workspace that uses the FMEServerJobSubmitter followed by the FMEServerLogRetriever and an Email transformer.

Interesting!

 

 


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings