Automic Workload Automation

Expand all | Collapse all

Attaching a failed job's report to a notification email

  • 1.  Attaching a failed job's report to a notification email

    Posted Aug 01, 2017 09:16 AM
    Hi folks,

    I'm working on updating our email notification script to include a bit more information and I'm stuck on how to export the full job report from a failed job to get it into the email notification. Ideally, I'd like for it to export and attach as a .txt file. I've tried using PREP_PROCESS_REPORT, but can't work myself through how to use it correctly. 

    Here's what I have set up right now. Any tips or assistance would be appreciated!

    !-- Call Operator Script
    :SET &DATE = SYS_DATE('MM/DD/YYYY')
    :SET &TIME = SYS_TIME('HH:MM')
    !--
    :SET &P_NAME = GET_PARENT_NAME(,,'ACT')
    :SET &P_NR   = GET_PARENT_NR(,,'ACT')
    !--
    :READ &UC_CAUSE_NAME,,
    :READ &UC_CAUSE_NR,,
    :READ &UC_CAUSE_RETCODE,,
    !--
    :SET &UC_CAUSE_RETCODE = FORMAT(&UC_CAUSE_RETCODE)
    !--
    :SET &MSG = 'Error in Job Plan &p_name (RUN: &p_nr) Job that failed and caused the error '
    :SET &MSG = STR_CAT(&MSG, 'was &UC_CAUSE_NAME (RUN: &UC_CAUSE_NR) Returncode: ')
    :SET &MSG = STR_CAT(&MSG, '&UC_CAUSE_RETCODE, Error occured on &date at &time')
    !--
    :set &email_to  = get_var(EMAIL_RECIPIENTS_ABENDS,'&UC_CAUSE_NAME')
    :if &email_to <> ''
    :  set &return    = send_mail('&email_to',,'&UC_CAUSE_NAME - Failed ','&MSG',)
    :  print &return
    :endif
    :STOP NOMSG
    !-- End Call Operator Script


  • 2.  Attaching a failed job's report to a notification email

    Posted Aug 01, 2017 09:39 AM
    We are using a notification object with its type set to "e-mail", and the script in the Process tab has these lines:
    :  PUT_ATT ATTACH_REPORTS_RUNID = &UC_CAUSE_NR
    :  PUT_ATT ATTACH_REPORTS_SOURCE = "DB"
    We have all reports in the Automic Engine DB, so we just tell the notification object to pull the reports from DB and attach them to the e-mail. We use this notification object for all our jobs so the failure notification e-mails look standard.
    And of course, you can customize email's subject and body through scripting, with company's logo and other details about failed object. This is how it looks in the end:

    appqhpbz9gpx.pnghttps://us.v-cdn.net/5019921/uploads/editor/wu/appqhpbz9gpx.png" width="879">



  • 3.  Attaching a failed job's report to a notification email

    Posted Aug 01, 2017 09:40 AM
    Hi Thomas,

    does it have to be in script? Cause there's an option "Attache reports from task" on the "notification" tab in every Call object.

    You just have to put this in there:  &$ACTIVATOR_RUNID#



  • 4.  Attaching a failed job's report to a notification email

    Posted Aug 01, 2017 09:41 AM
    Hi ThomasKelly613226,

    Why not simply use a notification object ? It already includes the possibility to attach the report from the calling task.
    jvu7c32a7w3t.pnghttps://us.v-cdn.net/5019921/uploads/editor/r6/jvu7c32a7w3t.png" width="708">

    Best regards,
    Antoine



  • 5.  Attaching a failed job's report to a notification email

    Posted Aug 01, 2017 09:46 AM
    Antoine and Matthias, that might be a feature we don't have enabled as the selection boxes are grayed out. 

    kgo13nnmw1k0.pnghttps://us.v-cdn.net/5019921/uploads/editor/po/kgo13nnmw1k0.png" width="717">


  • 6.  Attaching a failed job's report to a notification email

    Posted Aug 01, 2017 09:48 AM
    In the notification Attributes tab set Type to "e-mail"


  • 7.  Attaching a failed job's report to a notification email

    Posted Aug 01, 2017 09:56 AM
    Just had one of those 'duh' moments after looking at the same thing for way too long! Okay, I can add info to that attach reports from task box, but it's not actually attaching anything in the email. It feels like I'm missing something obvious here...


  • 8.  Attaching a failed job's report to a notification email

    Posted Aug 01, 2017 10:01 AM
    You have to call the notification object from the job's Runtime tab, like this:

    raqax48mjgpp.pnghttps://us.v-cdn.net/5019921/uploads/editor/je/raqax48mjgpp.png" width="721">

    Our notification object also sends warning emails if the job takes double the usual time (ERT + 100%).
    In your case, you can ignore the settings in the bottom half, and edit only the section at the top "Definition for ENDED_OK"


  • 9.  Attaching a failed job's report to a notification email

    Posted Aug 01, 2017 10:11 AM
    We have the email triggered from the task properties within the plan, which is working to send the email, but no attachment is coming through on said email.ubdby893an12.pnghttps://us.v-cdn.net/5019921/uploads/editor/45/ubdby893an12.png" width="749">


  • 10.  Attaching a failed job's report to a notification email

    Posted Aug 01, 2017 11:55 AM
    You must do this from the Runtime tab.

    When it is invoked from the Runtime tab, the product also populates several required variables that are used for inclusion in the notification email, including &UC_CAUSE_NR which is responsible for telling it what reports to attach.  


  • 11.  Attaching a failed job's report to a notification email

    Posted Aug 01, 2017 11:56 AM
    The way you have it configured it will send a notification if one or more dependencies failed. However, &UC_CAUSE_NR contains the ID of the task calling the notification object. In your case, it will contain the ID of the task in your screen shot, and not the ID of the failed dependency, because the notification object was not called by the failed dependency.
    The notification has to be called by the failing task in order to be able to retrieve failure info (reports) of the failed task. It will work if you call the notification from task's Runtime tab, as I described above.
    Here are more details:
    https://docs.automic.com/documentation/webhelp/english/ALL/components/AE/10.0/All%20Guides/help.htm#ucacsg.htm?Highlight=UC_CAUSE_NR





  • 12.  Attaching a failed job's report to a notification email

    Posted Aug 01, 2017 12:24 PM
      |   view attached
    Please have a look at the notification object I attached. The export package contains also a variable VARA.SEC_SQLI.JOB_STATS which is used by the notification object to determine ERT of the running task. I could not find any other way to get ERT. The ERT is shown in the warning notification if you set up MRT as ERT + nn% like in my screen shot above.
    You will have to edit the notification object to add proper recipients in the Recipients tab, and also to change the logo at the bottom of Notification tab.

    Attachment(s)



  • 13.  Attaching a failed job's report to a notification email

    Posted Aug 01, 2017 02:16 PM
    Is there a way to build the report attachment into the script that I attached above without having to add/change the Runtime tab on every job we have built? I know it's probably less than ideal, but I'm trying to work with what I have and it's not realistic to go back into every individual job we have to add the runtime tab and remove the notification alert from the plan setup.


  • 14.  Attaching a failed job's report to a notification email

    Posted Aug 01, 2017 03:03 PM
    This is not trivial, and I doubt anyone has solution code to share because this is an unusual approach.  There is a batch utility available for converting reports into flat files that you could then attach to your email, but I've never used it.  I read about it in these forums though.


  • 15.  Attaching a failed job's report to a notification email

    Posted Aug 02, 2017 03:15 AM
    ThomasKelly613226,

    You could

    1) use something like this to add a copy of the report directly in the mail's body:
    :SET &REPORT# = ""
    :SET &HND# = PREP_PROCESS_REPORT(,&$RUNID#,"REP")
    :PROCESS &HND#
    :SET &LINE# = GET_PROCESS_LINE(&HND#)
    :SET &REPORT# = STR_CAT(&REPORT#,&LINE#)
    :ENDPROCESS
    :SET &SEND# = SEND_MAIL("<your email address>",,"job report",&REPORT#)

    2) Save the report locally on the agent,

    5latx4n3f9dk.png

    then add the report as an attachment with SEND_MAIL:
    :SET &REPORT# = RUNNR2ALPHA(&$RUNID#)
    :SET &REPORT# = "O&REPORT#.txt"
    :SET &SEND# = SEND_MAIL("
    <your email address>",,"Report","Here is the report","<agent's temp folder>\&REPORT#")
    HOWEVER I would not recommend using one of these solutions. 1) Will greatly increase the task's processing time and 2) will require some disk space monitoring on the agent's side.
    Editing objects to add a notification object to each one of them does sound like a very time-consuming process, however it probably is the best approach to preserve the system's performance.

    Just my 2 cents...

    Best regards,
    Antoine


  • 16.  Attaching a failed job's report to a notification email

    Posted Aug 02, 2017 05:20 AM
    Hi ThomasKelly613226

    This should be easy to solve. I tried this in our test environment and it worked fine:

    Created a script like this (or modify the one you already have) to pass the &UC_CAUSE_NR Variable to a call object (in this case "CALL.UC4.TEST")
    :READ &UC_CAUSE_NAME,,
    :READ &UC_CAUSE_NR,,
    :READ &UC_CAUSE_STATE,,
    :READ &UC_CAUSE_RETCODE,,

    :PUT_READ_BUF TEST# = &UC_CAUSE_NR
    :SET &RC#  = ACTIVATE_UC_OBJECT(CALL.UC4.TEST)

    Create the call object CALL.UC4.TEST and put this into the script tab:
    :READ &TEST#,,
    :PRINT "&TEST#"
    :PUT_ATT ATTACH_REPORTS_RUNID = &TEST#


    Put the script in the dependency tab of  a job/workflow of your choice (like you already did):
    ouh6ajrcpqw3.pnghttps://us.v-cdn.net/5019921/uploads/editor/3b/ouh6ajrcpqw3.png" width="750">


    This worked in our Automic V10.0.3 test environment. Might not work in other versions. The only problem. If there is more than one dependencies (like in the screenshot) it only gives you the report of one of the failed jobs. This might be a bug in version 10.0.3.

    Regards, Matthias


  • 17.  Attaching a failed job's report to a notification email

    Posted Aug 02, 2017 08:38 AM
    MatthiasSchelp Antoine_Sauteron petwir LeonardOlteanu

    I had my eureka moment last night! I realized the notification wasn't working with the attachment because I still had the SEND_MAIL script in the processing tab so it was ignoring the notification tab. I made the updates and all appears to be working now, including looking into the pre-built email variable we had already built. 

    Some screenshots below to help someone else in the future.

    Thanks for the help guys!abcf03r878oi.pnghttps://us.v-cdn.net/5019921/uploads/editor/hc/abcf03r878oi.png" width="718">mmb6qlg1ee9a.pnghttps://us.v-cdn.net/5019921/uploads/editor/t2/mmb6qlg1ee9a.png" width="717">s6b92dakzas4.pnghttps://us.v-cdn.net/5019921/uploads/editor/rs/s6b92dakzas4.png" width="715">




  • 18.  Attaching a failed job's report to a notification email

    Posted Aug 03, 2017 08:45 AM
    Okay, so the idea I had above is working wonderfully with one email address in the &email_to variable, but I'm receiving an error message "U0050028 SMTP server rejected receiver" when there are two or more recipients in the variable field. It worked fine when using the below code in the processing tab before, but didn't transition over when I just placed the variable in the Recipients tab.

    Any thoughts?
    :set &email_to  = get_var(EMAIL_RECIPIENTS_ABENDS,'&UC_CAUSE_NAME')
    :if &email_to <> ''
    :  set &return    = send_mail('&email_to',,'&UC_CAUSE_NAME - Failed ','&MSG',)
    :  print &return
    :endif



  • 19.  Attaching a failed job's report to a notification email

    Posted Aug 03, 2017 10:08 AM
    Instead of
    :set &email_to  = get_var(EMAIL_RECIPIENTS_ABENDS,'&UC_CAUSE_NAME')
    try using :ADD_ATT with PREP_PROCESS_VAR to add recipients from the variable to the Recipients tab, and remove &email_to from the Recipients tab.




  • 20.  Attaching a failed job's report to a notification email

    Posted Aug 03, 2017 10:13 AM
    LeonardOlteanu

    I received the following message with :ADD_ATT with PREP_PROCESS_VAR as we have semi-colons in the variables to separate the email addresses.

    8/3/2017 10:10:33 AM -  U0003702 Invalid characters in variable name:  Only the following characters may be used: A-Z, 0-9, $, @; maximum length: 200 characters.



  • 21.  Attaching a failed job's report to a notification email

    Posted Aug 03, 2017 10:56 AM
    I assumed you have one e-mail address per row in your variable, but it looks like you have multiple e-mails separated by semi-colons in one row. If that is the case, you will have to split that row into individual e-mails.
    This would be one way to store mailing lists: have mailing list code in column 1, and one e-mail in each row in column 2. The variable key would be given by the mailing list code and a sequential number, like this:
    MLOPS1 MLOPS john@company.com
    MLOPS2 MLOPS jerry@company.com
    MLOPS3 MLOPS jack@company.com
    MLDEV1 MLDEV don@company.com
    MLDEV2 MLDEV dan@company.com
    MLDEV3 MLDEV doe@company.com
    Then you can process each row in a specified mailing list using :ADD_ATT and something like PREP_PROCESS_VAR(EMAIL_RECIPIENTS_ABENDS, "MLOPS*")