cancel
Showing results for 
Search instead for 
Did you mean: 

Exclude jobs with remote status warning

former_member587730
Participant
0 Kudos

Hello Experts,

  1. We have trigger to get alerted up on job failure however end user do not want alert in case job which has failed with remote status warning.
  2. What changes I can make here so that I can ignore remote status of the job is warning
{
jcsPostRunningContext.setFailJobOnError(false) ;
jcsPostRunningContext.setMaximumRestarts(5) ;
jcsPostRunningContext.setLogRestarts(false) ;
  // definition of job witch failed
  JobDefinition jcsJobDefinition = jcsJob.getJobDefinition();
  Partition jcsPartition = jcsJobDefinition.getPartition();
  
  if((!jcsJobDefinition.getJobDefinitionType().getName().equals(JobDefinitionType.JOB_CHAIN)) && (!jcsPartition.getName().equals("GLOBAL"))) {
    // not a jobchain
    
    Table System_Variables = jcsSession.getTableByName("System_Variables");
    String MailRecipients = System_Variables.getTableValueBySearchKeySearchColumnName("ALERT_RECIPIENTS", "SYSTEMVALUE").getColumnValue();
    if (jcsPostRunningContext.getNewStatus().equals(JobStatus.Error) || jcsPostRunningContext.getNewStatus().equals(JobStatus.Killed)) {
      // Error and Kill status
      
      String jcsMailRecipients = MailRecipients + isMail(jcsJobDefinition.getComment()) + isMail(jcsJobDefinition.getParentApplication().getComment());
      String jcsJobName = jcsJobDefinition.getName();
      // Parent jo handling        
      Job jcsParentJob = jcsJob.getParentJob();
      if(jcsParentJob != null) {
        // get mail from parent job and it's aplication
        jcsMailRecipients = jcsMailRecipients + isMail(jcsParentJob.getJobDefinition().getComment()) + isMail(jcsParentJob.getJobDefinition().getParentApplication().getComment());
        jcsJobName = jcsParentJob.getJobDefinition().getName() + "    - step [" + jcsJobName + "]";
        jcsPartition = jcsParentJob.getJobDefinition().getPartition();
      }
      
      // Partition description      
      String jcsDescription = jcsPartition.getComment();
      if(jcsDescription == null) 
        jcsDescription = jcsPartition.getName();
        
      // Start mail job now
      Job jcsMailJob = jcsSession.getJobDefinitionByName("Alert_Send_Mail_Job_Alert").prepare();
//      jcsMailRecipients = System_Variables.getTableValueBySearchKeySearchColumnName("ALERT_RECIPIENTS", "SYSTEMVALUE").getColumnValue();
      jcsMailJob.getJobParameterByName("Mail_To").setInValueString(jcsMailRecipients);
      jcsMailJob.getJobParameterByName("Error_JobID").setInValueString(jcsJob.getJobId().toString());
      jcsMailJob.getJobParameterByName("Error_Description").setInValueString(jcsDescription + " - Error in job '" + jcsJobName + "'");
    }
    if (jcsPostRunningContext.getNewStatus().equals(JobStatus.Unknown)) {
      // Unknown status handling
      Job jcsMailJob = jcsSession.getJobDefinitionByName("Alert_Send_Mail_Job_Alert").prepare();
      jcsMailJob.getJobParameterByName("Mail_To").setInValueString(MailRecipients);
      jcsMailJob.getJobParameterByName("Error_JobID").setInValueString(jcsJob.getJobId().toString());
      jcsMailJob.getJobParameterByName("Error_Description").setInValueString("Job '" + jcsJobDefinition.getName() + "' has got the status Unknown. Please investigate.");
    } 
  }
}
private String isMail(String str) {
  if(str == null)
    return "";
  if(str.indexOf("@") < 0)
    return "";
  if(str.indexOf(" ") >= 0)
    return "";
  if(str.indexOf("#") >= 0)
    return "";
  return "," + str.toLowerCase();
}

Accepted Solutions (0)

Answers (1)

Answers (1)

gmblom
Active Contributor
0 Kudos

Hello,

Add a check on the remote status in your first if statement:

if(!jcsJobDefinition.getJobDefinitionType().getName().equals(JobDefinitionType.JOB_CHAIN) && !jcsPartition.getName().equals("GLOBAL") && !"Warning".equals(jcsJob.getRemoteStatus()))
{
//not a jobchain and not remote status is Warning

Regards Gerben

former_member587730
Participant
0 Kudos

Hello Gerben,

I have modified the trigger as you suggested but still it does not exclude the warning status jobs.

Trigger still shoot failure alert for remote status warning jobs 😞

Please suggest.

gmblom
Active Contributor
0 Kudos

So what is the exact value that is in the RemoteStatus field? It is now performing an exact case sensitive match against the string Warning.

Regards Gerben

former_member587730
Participant
0 Kudos

You are right Gerben its exact string match.

I made the change, it was 'warning' and not 'Warning' 🙂

Thanks lot for the help.