Show TOC

Procedure documentationRaising Alerts and Notifications from Jobs Locate this document in the navigation structure

 

You can use jobs to generate alerts when they fail with job alert sources. A job alert source can be created to trigger alerts for multiple jobs with pattern matching.

Substitution Parameters

Job definition alert sources support the following substitution parameters:

  • ${jobDefinition} - the name of the job definition.

  • ${jobDefinitionOwner} - the owner of the job definition.

  • ${jobId} - the job id.

  • ${topLevelJobId} - the job id of the highest parent.

  • ${jobOwner} - the owner of the job.

  • ${oldStatus} - the old status of the job.

  • ${newStatus} - the new status of the job.

  • parameters.name - the value of input parameter 'name' of the job, available in REL only.

  • outParameters.name - the value of output parameter 'name' of the job, available in REL only.

  • ${topLevelQueue} - the name of the queue of the highest parent job

  • ${remoteStatus} - the status in the remote system

  • ${returnCode} - the return code of the job

  • ${queue} - the queue of the job

Parameters with the ${} syntax can be entered verbatim, for example:

Job with job id ${jobId} failed!

As soon as you use REL expressions, like parameters.name, you need to use the REL syntax

='Parameter Param1: '+parammeters.Param1

To mix REL and non-REL substitution parameters, proceed as follows:

='Job ${jobId} has a parameter Param1 with the following value: '+parammeters.Param1

Procedure

Creating a job definition alert source

  1. Navigate to   Alerting → Job Definitions Alert Sources  .

  2. Choose New from the context menu.

  3. Fill in a name into the Name field, into the Name Pattern field. Optionally fill the other fields.

  4. On the Statuses tab choose New and select a status in the Status drop-down. Optionally fill in a status-specific operator message that overrules the default message.

  5. Choose Save & Close.

Example

Raise alerts when any SAP_AbapRun job enters status Error, Unknown, Killed or Canceled.

  1. Navigate to   Alerting → Job Definitions Alert Sources  .

  2. Choose New from the context menu.

  3. Fill in a name and SAP_AbapRun* into the Name Pattern field.

  4. Fill Job ${jobOwner}.${jobDefinition} with job id ${jobId} reached status ${newStatus}, has the job been restarted?.

  5. Fill ^Yes|No$ into the Reply Expression field, to force users to reply with Yes or No.

  6. On the Statuses tab:

    1. Choose New and select Error in the Status drop-down.

    2. Repeat previous step for statuses Unknown, Killed, and Canceled.

  7. Choose Save & Close.

Raise alerts when any SAP_AbapRun job where the parameter SAP_SYSTEMS has value ERP enters status Error, Unknown, Killed or Canceled.

For the operator message to work, the job definition needs a parameter Param1.

  1. Navigate to   Alerting → Job Definitions Alert Sources  .

  2. Choose New from the context menu.

  3. Fill in a name and SAP_AbapRun* into the Name Pattern field.

  4. Fill ='Job ${jobOwner}.${jobDefinition} with job id ${jobId} and parameter '+parameters.Param1+'reached status ${newStatus}!' into the Operator Message field.

  5. On the Statuses tab:

    1. Choose New and select Error in the Status drop-down.

    2. Repeat previous step for statuses Unknown, Killed, and Canceled, you can fill a specific operator message for each status.

  6. On the Parameters tab, choose New and fill SAP_SYSTEMS into the Name field and ERP into the Value field.

  7. Choose Save & Close.

A job definition is restarted when it reaches Error, the maximum number of restarts is set to 4. You do not want to have to answer an alert for the first restart. Note that getRestartCount returns the number of remaining restarts.

{

// Get the alert information

Alert alert = jcsAlertSourcePostAlertContext.getAlert();

OperatorMessage om = alert.getOperatorMessage();

SchedulerEntity se = om.getSenderObject();

// Do not send emails for the first failure

if (se instanceof Job)

{

Job j = (Job) se;

Long restartCount = new Long(3L);

// If RestartJobId is null, then this is the first job.

if (j.getStatus().getState() == JobStatusState.Final && restartCount.equals(j.getRestartCount()))

{

// Reply to the operator message and restart the job

om.setReply("Acknowledged");

}

}

}