Support Questions

Find answers, ask questions, and share your expertise

Send email from Oozie Kill section

avatar
Expert Contributor

Hello,

I would like to send an email in case an oozie workflow fails, i.e. from the "kill" section of the workflow. Is this possible? The documentation I found on oozie website only mentions the "message" element which simply writes to a log.

 

https://oozie.apache.org/docs/4.0.0/WorkflowFunctionalSpec.html#a3.1.3_Kill_Control_Node

 

Thanks, Martin

1 ACCEPTED SOLUTION

avatar
Super Collaborator

Hey,

 

You can't have a kill action send an email.  However, you can have your other actions change their kill to be an email action that sends the email and then the email action goes to a kill.  Like:

 

<workflow-app name="shell-wf" xmlns="uri:oozie:workflow:0.4">
<start to="shell"/>
<action name="shell">
<shell xmlns="uri:oozie:shell-action:0.1">
<job-tracker>${jobTracker}</job-tracker>
<name-node>${nameNode}</name-node>
<configuration>
<property>
<name>mapred.job.queue.name</name>
<value>${queueName}</value>
</property>
</configuration>
<exec>shell.sh</exec>
<file>shell.sh#shell.sh</file>
</shell>
<ok to="end"/>
<error to="kill-email"/>
</action>
<action name="kill-email">
<email xmlns="uri:oozie:email-action:0.1">
<to>cconner@test.com</to>
<cc>other-cconner@test.com</cc>
<subject>WF ${wf:id()} failed</subject>
<body>Shell action failed.</body>
</email>
<ok to="kill"/>
<error to="kill"/>
</action>
<kill name="kill">
<message>Action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
</kill>
<end name="end"/>
</workflow-app>

View solution in original post

4 REPLIES 4

avatar
Super Collaborator

Hey,

 

You can't have a kill action send an email.  However, you can have your other actions change their kill to be an email action that sends the email and then the email action goes to a kill.  Like:

 

<workflow-app name="shell-wf" xmlns="uri:oozie:workflow:0.4">
<start to="shell"/>
<action name="shell">
<shell xmlns="uri:oozie:shell-action:0.1">
<job-tracker>${jobTracker}</job-tracker>
<name-node>${nameNode}</name-node>
<configuration>
<property>
<name>mapred.job.queue.name</name>
<value>${queueName}</value>
</property>
</configuration>
<exec>shell.sh</exec>
<file>shell.sh#shell.sh</file>
</shell>
<ok to="end"/>
<error to="kill-email"/>
</action>
<action name="kill-email">
<email xmlns="uri:oozie:email-action:0.1">
<to>cconner@test.com</to>
<cc>other-cconner@test.com</cc>
<subject>WF ${wf:id()} failed</subject>
<body>Shell action failed.</body>
</email>
<ok to="kill"/>
<error to="kill"/>
</action>
<kill name="kill">
<message>Action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
</kill>
<end name="end"/>
</workflow-app>

avatar
Expert Contributor
Thanks, that does the trick!

avatar
New Contributor

How about rerun? If the oozie job fails during rerun this email action will not send email as this action is marked as SUCCESS during first run. How to kick email action during failure in rerun?

 

Thanks.

avatar
New Contributor

this workflow is working? Just workflow and it will send to email?