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('*****', a'*****'], 'Log file from server', m_text)