Question

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

  • 5 September 2018
  • 7 replies
  • 8 views

Userlevel 1
Badge +8

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

Userlevel 2
Badge +16

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.

Userlevel 4

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.

Userlevel 4

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

Badge +22

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".

 

 

Userlevel 1
Badge +8

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

 

 

 

Userlevel 1
Badge +8

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.

 

 

Userlevel 1
Badge +8

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!

 

 

Reply