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)