You could use a <stafcmd> in your STAX job to submit a QUERY request to the LOG service to query the STAX Job log and specify option LEVELMASK fail in the QUERY request. Then you can put a "pretty print" formatted log output string in your emailMessage. For example:
<script> request = 'QUERY MACHINE {STAF/Config/MachineNickname} LOGNAME %s LEVELMASK fail' % \ (STAXJobLogName) </script> <stafcmd name="'Query STAX Job Log'"> <location>'local'</location> <service>'LOG'</service> <request>request</request> </stafcmd> <if expr="RC == 0"> <sequence> <script> if len(STAFResult) == 0: logOutput = '' # No tests failed else: # Assign "pretty print" formatted STAX Job Log output string logOutput = 'Failed Tests:\n%s' % (STAFResultContext) </script> <log message="1">logOutput</log> </sequence> <else> <sequence> <log message="1"> 'LOG %s request failed with RC=%s Result=%s' % (request, RC, STAFResult) </log> <script>logOutput = 'Unknown because LOG QUERY request failed'</script> </sequence> </else> </if> <script> from com.ibm.staf import STAFUtil emailServiceMachine = 'local' emailTo = 'm...@myself.com' subject = ('%s Started %s %s Completed Passed %s Failed %s' % \ (STAXJobLogName,STAXJobStartDate,STAXJobStartTime,totalPasses,totalFails)) emailMessage = '%s\n\n%s' % (subject, logOutput) </script> <!-- Note: Need to specify the NORESOLVEMESSAGE option on the EMAIL SEND TO request (if you didn't register the Email service in the STAF.cfg file with the NORESOLVEMESSAGE parameter) because the message will contain one or more "{" characters if one or more tests fail (and a "{" denotes a STAF variable). --> <stafcmd> <location>emailServiceMachine</location> <service>'EMAIL'</service> <request> 'SEND TO %s SUBJECT %s MESSAGE %s NORESOLVEMESSAGE' % \ (emailTo, STAFUtil.wrapData(subject), STAFUtil.wrapData (emailMessage)) </request> </stafcmd> The eMail message would then look like the following if one or more tests failed. If no tests failed, it wouldn't include the "Failed Tests:" section. ****************************************************************** * DO NOT RESPOND TO THE SERVICE MACHINE THAT GENERATED THIS NOTE * ****************************************************************** STAX_Job_18 Started 20100916 12:01:46 Completed Passed 17 Failed 2 Failed Tests: [ { Date-Time: 20100916-12:01:48 Level : Fail Message : Testcase: My Testcase, Pass: 0, Fail: 1, Last Status: fail, Message: It failed } { Date-Time: 20100916-12:01:48 Level : Fail Message : Testcase: My Testcase, Pass: 0, Fail: 2, Last Status: fail, Message: It failed again } ] How to query the STAX Job log is talked about in the "STAX Logging" section in the STAX User's Guide at http://staf.sourceforge.net/current/STAX/staxug.html#Header_StaxLogging and the LOG service is talked about in section "8.8.6 QUERY" in the STAF User's Guide at http://staf.sourceforge.net/current/STAFUG.htm#HDRLOGSRV. Note though that if the job is terminated (e.g. due to a signal being raised that terminates the job or someone specifies to terminate the job, etc), your xml function may not be called unless you put in in a <finally> block for a <try> block that is in your main function. -------------------------------------------------------------- Sharon Lucas IBM Austin, luc...@us.ibm.com (512) 286-7313 or Tieline 363-7313 From: Matt <mattmora...@gmail.com> To: staf-users@lists.sourceforge.net Date: 09/16/2010 10:43 AM Subject: [staf-users] Capturing job log output from with in <script> I have a xml function that is called at the end of my job. It calls STAXUtilQueryAllTests to email a result. <call function="'STAXUtilQueryAllTests'"/> <script>[rc, result, totals, testcases] = STAXResult</script> <script>[totalTests, totalPasses, totalFails] = totals</script> <call function="'STAXUtilLogAndMsg'"> 'Total Testcases: %s, Total Passes: %s, Total Fails: %s\nTestcases: %s' % \ (totalTests, totalPasses, totalFails, testcases) </call> <script> from com.ibm.staf import STAFUtil emailServiceMachine = 'local' emailTo = 'm...@myself.com' emailMessage = ('%s Started %s %s Completed Passed %s Failed %s %s' % \ (STAXJobLogName,STAXJobStartDate,STAXJobStartTime,totalPasses,totalFails,)) </script> I'd like to be able to also email the JobLog output as this contains details of any failures. What's the best way to go about doing this? What would be better if I was able to only grab level = 'fail' out of the JobLog. Any recommendations appreciated. Thanks, Matt ------------------------------------------------------------------------------ Start uncovering the many advantages of virtual appliances and start using them to simplify application deployment and accelerate your shift to cloud computing. http://p.sf.net/sfu/novell-sfdev2dev _______________________________________________ staf-users mailing list staf-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/staf-users ------------------------------------------------------------------------------ Start uncovering the many advantages of virtual appliances and start using them to simplify application deployment and accelerate your shift to cloud computing. http://p.sf.net/sfu/novell-sfdev2dev _______________________________________________ staf-users mailing list staf-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/staf-users