[resolved] Email notification in case of job failure

One Star

[resolved] Email notification in case of job failure

Hi,
I have a job that takes all data from oracle table and insert it in to ms sql table.
Ex: tOracleInput==>tmap==>tmsSqlOutput
Now, in case the job fails - due to any reason (say database went down or incorrect connection settings or any mismatch etc), I want to capture the error log in a email. I want to notify by sending email that the job has been failed with the error code attached in email body.
I tried 2 approaches using tSendMail component as given below:
Approach1 : tOracleInput==>tmap==>tmsSqlOutput==>onComponentError==>tSendMail
Approach2: tOracleInput==>tmap==>tmsSqlOutput==>onComponentError==>tDie
and tLogCatcher==>tSendMail
But I was not able to get the expected result with these 2 approaches.
Please help me out here!! Appreciate the responses with solutions.

Thanks
Xan

Accepted Solutions
Community Manager

Re: [resolved] Email notification in case of job failure

Hi
What's the problem? You don't receive the email or the error message is null in the email body? Any case, the job design looks like:
tOracle--main--tMssql

tLogCatcher--main--tJavaRow
|
onsubjobok
|
tSendmail
uncheck the option 'die on error' on all the component, so that the job will throw the exception once fails and die.
on tJavaRow:
globalMap.put("errorCode", input_row.message);
on the message body of tsendmail:
"the error message is: "+(String)globalMap.get("errorCode")
uncheck the option 'die on error' on all the components.

Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business

All Replies
One Star

Re: [resolved] Email notification in case of job failure

The catch java exception and catch error check boxes on tLogCatcher are checked!! Still the issue!
Community Manager

Re: [resolved] Email notification in case of job failure

Hi
What's the problem? You don't receive the email or the error message is null in the email body? Any case, the job design looks like:
tOracle--main--tMssql

tLogCatcher--main--tJavaRow
|
onsubjobok
|
tSendmail
uncheck the option 'die on error' on all the component, so that the job will throw the exception once fails and die.
on tJavaRow:
globalMap.put("errorCode", input_row.message);
on the message body of tsendmail:
"the error message is: "+(String)globalMap.get("errorCode")
uncheck the option 'die on error' on all the components.

Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] Email notification in case of job failure

Thanks for the response Shong!
It does work now. I forgot to uncheck the die on error option. Thanks again! Really appreciate it.
Community Manager

Re: [resolved] Email notification in case of job failure

Thanks for the response Shong!
It does work now. I forgot to uncheck the die on error option. Thanks again! Really appreciate it.

Good news, thanks for your feedback!
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] Email notification in case of job failure

Hi Shong,
I was working on the other approach for this same functionality. When there is any failure to Talend Job, I have written a java class which sends email. This routine I have saved in the Routines section in talend. Now, how to call this routine when the job fails?
Suppose I have the routine named "sendEmail" and I have written the usual java mail code to send email(It has a main() method and inside main (), the send() method is called. This send() method sends the email actually). Now, in order to call this routine when our talend job fails, will it be called as:
tlogCatcher--onSubjobOk-->tJava
On tJava: just sendMail.this ? It did not work this way, so was wondering if you can give your inputs!
Community Manager

Re: [resolved] Email notification in case of job failure

Hi
There should not be a main() method in the routine, please take a look at the system routines. To call a routine method, the format is routineName.methodName, for example:
tlogCatcher--onSubjobOk-->tJava
on tJava:sendEmail.send()
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] Email notification in case of job failure

Got it!! thanks much man!
One Star

Re: [resolved] Email notification in case of job failure

Hello,
I was trying to implement several approaches of sending email. I tried sending email if the job fails to run and sending attachment with the email. Now I was trying with sending a plain email if the job fails and below was the code I wrote for it -
tOracleInput-->tMap-->tMySQLOutput
tLogCatcher--row1-->tFileOutputXML
|
onSubjobOk
|
tSendMail1
Now I have set all the properties. when I run the job, it triggers email 2 times. I verified the parameters and there is really nothing specific mentioned in this simple job which will trigger email twice.
Can anyone please help me here, why am I getting 2 emails instead of one simple email - as per this flow. . ?
Thanks
Xan
Community Manager

Re: [resolved] Email notification in case of job failure

Hi Xan
I don't understand why it sends two emaisl either. Even, I don't believe the two emails are sent from the same component in this job. Do you have other subjobs in this job?
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] Email notification in case of job failure

Thanks for ur reply Shong. No I do not have any subjob but I have two email notification processes.
One tsendmail to send email to one group of people and other tsendmail to send email to different group of users.
I had to use 2 email process cz I want to send plain email to certain group and a log file attachment to another group. I hope this should not bother.
Later I tried deleting one of the tSendMail component hoping to see any change, but to my surprise, it is still sending 2 same emails.
One Star

Re: [resolved] Email notification in case of job failure

Hi, I have exactly the same case, but input_row.message is null (in my case it's row18.message). 
   
{

tLogCatcher--main--tJavaRow
   |
onsubjobok
   |
tSendmail

uncheck the option 'die on error' on all the component, so that the job will throw the exception once fails and die.
on tJavaRow:
globalMap.put("errorCode", input_row.message);

on the message body of tsendmail:
"the error message is: "+(String)globalMap.get("errorCode")

uncheck the option 'die on error' on all the components.
}
Bu if I do, tLogCatcher--main--tSendmail, and inside of Email I do input_row.message, it works. There's problem getting a message inside of tJava.
Even this does send me null: System.out.println(insert_row.message);
Six Stars

Re: [resolved] Email notification in case of job failure

Hi there and thanks for posting this.

 

It works but I also get 2 emails instead of one.

 

In one email the +(String)globalMap.get("errorCode")+ component is "null", and in the other it contains the actual error.

 

My setup is exactly as described:

 

tLogCatcher-->tJavaRow-->onSubJobOk-->tSendEmail

 

Thoughts?