OIM 11g R2 PS2 - Notify Failed Reconciliation Events

In this post , I will cover a scenario where in we want to notify an admin for the failed reconciliation events specially for trusted recon on a regular basis.

This feature is not available out-of-the-box and a custom scheduled job can be developed to address this requirement.


RECON_EVENTS is the OIM table which holds the information about all the recon events till date along with status and dates.  


























                                                                                                                                                             

Event Management Console











                                                                                                                                                                 
All we need is construct a sql query to get failed events for the current sys date


select RE_KEY as ReconEventNo , RE_KEYFIELD as LoginID , RE_STATUS as Status from RECON_EVENTS where to_char(RE_CREATE,'YYYY-MM-DD') = to_char(SYSDATE , 'YYYY-MM-DD') AND (RE_STATUS not like '%Succeeded%' OR RE_STATUS IS NULL)







                                                                                                                                                 
                                                                                                                                                 
                                                                                                                                                 
Once all the failed events are consolidated and mailed to the concerned person manual action can be taken by going too event management console.


Sample Scheduled Task Code
  1 package com.dubey.deepak.oim.scheduledtasks;
  2 
  3 import java.sql.Connection;
  4 import java.sql.PreparedStatement;
  5 import java.sql.ResultSet;
  6 import java.util.ArrayList;
  7 import java.util.HashMap;
  8 import java.util.HashSet;
  9 import java.util.List;
 10 import java.util.Map;
 11 import java.util.Set;
 12 
 13 import com.dubey.deepak.oim.model.ITMailServer;
 14 
 15 import oracle.iam.platform.Platform;
 16 import oracle.iam.scheduler.vo.TaskSupport;
 17 import Thor.API.tcResultSet;
 18 import Thor.API.Exceptions.tcAPIException;
 19 import Thor.API.Operations.tcITResourceInstanceOperationsIntf;
 20 
 21 public class NotifyFailedReconEvents extends TaskSupport {
 22 
 23  public static final String RECON_QUERY = "select RE_KEY as ReconEventNo , RE_KEYFIELD as LoginID
 , RE_STATUS as Status from RECON_EVENTS where to_char(RE_CREATE,'YYYY-MM-DD') = to_char(SYSDATE , 'YYYY-MM-DD')
 AND (RE_STATUS not like '%Succeeded%' OR RE_STATUS IS NULL)";
 24  private int totalExceptions = 0;
 25 
 26  public NotifyFailedReconEvents() {
 27   super();
 28  }
 29 
 30  public void execute(HashMap hashMap) {
 31   System.out.println("Starting Notify Failed Recon Events Job");
 32   String from = (String) hashMap.get("From Address");
 33   System.out.println("from is : " + from);
 34   String to = (String) hashMap.get("To Address");
 35   System.out.println("to is : " + to);
 36 
 37   Connection conn = null;
 38   PreparedStatement prest = null;
 39   ResultSet rs = null;
 40 
 41   try {
 42    String itResName = "Email Server";
 43    tcITResourceInstanceOperationsIntf tcITResOps = Platform
 44      .getService(tcITResourceInstanceOperationsIntf.class);
 45 
 46    HashMap itResSearch = new HashMap();
 47    itResSearch.put("IT Resources.Name", itResName);
 48    tcResultSet itResources = tcITResOps
 49      .findITResourceInstances(itResSearch);
 50    System.out.println("itResources.getRowCount()---->"
 51      + itResources.getRowCount());
 52    long itResourceKey = 0L;
 53    if (itResources.getRowCount() == 1) {
 54     itResources.goToRow(0);
 55     itResourceKey = itResources.getLongValue("IT Resources.Key");
 56     System.out.println("itResourceKey---->" + itResourceKey);
 57    }
 58    Map itResMap = new HashMap();
 59    tcResultSet itResourceDetails = tcITResOps
 60      .getITResourceInstanceParameters(itResourceKey);
 61    int itResCount = itResourceDetails.getRowCount();
 62    System.out.println("itResCount------->" + itResCount);
 63    for (int i = 0; i < itResCount; i++) {
 64     itResourceDetails.goToRow(i);
 65     String key = itResourceDetails
 66       .getStringValue("IT Resources Type Parameter.Name");
 67 
 68     System.out.println("key------->" + key);
 69     String value = itResourceDetails
 70       .getStringValue("IT Resources Type Parameter Value.Value");
 71 
 72     System.out.println("value------->" + value);
 73     itResMap.put(key, value);
 74    }
 75 
 76    conn = Platform.getOperationalDS().getConnection();
 77    prest = conn.prepareStatement(RECON_QUERY);
 78    rs = prest.executeQuery();
 79    ITMailServer itMailServer = new ITMailServer(itResMap.get(
 80      "Authentication").toString(), itResMap.get("Server Name")
 81      .toString(), itResMap.get("User Login").toString(),
 82      itResMap.get("User Password").toString());
 83    FailReconEventMailer mailer = new FailReconEventMailer(itMailServer);
 84    List<Map> reconEventList = new ArrayList<Map>();
 85    while (rs.next()) {
 86     Map<String, String> map = new HashMap<String, String>();
 87     String reconEventNo = rs.getString(1);
 88     map.put("reconEventNo", reconEventNo);
 89     String LoginID = rs.getString(2);
 90     map.put("LoginID", LoginID);
 91     String status = rs.getString(3);
 92     map.put("status", status);
 93     reconEventList.add(map);
 94    }
 95    mailer.sendNotification(reconEventList, from, to);
 96   } catch (tcAPIException e) {
 97    e.printStackTrace();
 98   } catch (Exception e) {
 99    e.printStackTrace();
100   } finally {
101 
102   }
103   System.out.println("Finishing Notify Failed Recon Events Job");
104  }
105 
106  public HashMap getAttributes() {
107   System.out.println("entering get attributes");
108   return null;
109  }
110 
111  public void setAttributes() {
112   System.out.println("entering set attributes");
113  }
114 }
115 

 Mailer class which basically sends the email consolidating all the failed recon events.


  1 package com.dubey.deepak.oim.scheduledtasks;
  2 
  3 import java.text.SimpleDateFormat;
  4 import java.util.Calendar;
  5 import java.util.List;
  6 import java.util.Map;
  7 import java.util.Properties;
  8 
  9 import javax.mail.Message;
 10 import javax.mail.MessagingException;
 11 import javax.mail.Session;
 12 import javax.mail.Transport;
 13 import javax.mail.internet.InternetAddress;
 14 import javax.mail.internet.MimeMessage;
 15 
 16 import com.dubey.deepak.oim.model.ITMailServer;
 17 
 18 public class FailReconEventMailer {
 19 
 20  private Properties properties = null;
 21  public static final String MAILPASSWORD = "mail.password";
 22  public static final String MAILUSER = "mail.user";
 23  public static final String MESSAGE_SENT = "Message sent successfully";
 24  public static final String SMTPHOST = "mail.smtp.host";
 25 
 26  public FailReconEventMailer(ITMailServer itMailServer) {
 27   properties = System.getProperties();
 28   properties.setProperty(SMTPHOST, itMailServer.getServer());
 29   if ((itMailServer.getAuthentication() != null)
 30     && (itMailServer.getAuthentication().equalsIgnoreCase("true"))) {
 31    properties.setProperty(MAILUSER, itMailServer.getUser());
 32    properties.setProperty(MAILPASSWORD, itMailServer.getPassword());
 33   }
 34   Session session = Session.getDefaultInstance(properties);
 35  }
 36 
 37  public String sendNotification(List<Map> reconEventList, String from,
 38    String to) {
 39   String returnMessage = null;
 40   try {
 41    Calendar currentDate = Calendar.getInstance();
 42    SimpleDateFormat formatter = new SimpleDateFormat("dd/MMM/yyyy");
 43    String dateNow = formatter.format(currentDate.getTime());
 44    String subject = "Failed Reconciliation Events for Date : "
 45      + dateNow;
 46 
 47    StringBuilder body = new StringBuilder();
 48    String str = "The below reconciliation events failed within OIM for date : "
 49      + dateNow + ".\n\n\n";
 50    body.append(str);
 51    str = "Recon Event ID\t\t\tNetwork ID\t\t\tStatus\n";
 52    body.append(str);
 53    str = "--------------------------------------------------------------------------------------\n";
 54    body.append(str);
 55    for (Map map : reconEventList) {
 56     str = map.get("reconEventNo").toString() + "\t\t\t"
 57       + map.get("networkID").toString() + "\t\t\t"
 58       + map.get("status").toString() + "\n";
 59     body.append(str);
 60    }
 61    str = "\n\n";
 62    body.append(str);
 63    str = "Please login to OIM Web Console and take appropriate action.";
 64    body.append(str);
 65    Session session = Session.getDefaultInstance(properties);
 66    MimeMessage message = new MimeMessage(session);
 67    message.setFrom(new InternetAddress(from));
 68    message.addRecipient(Message.RecipientType.TO, new InternetAddress(
 69      to));
 70    message.setSubject(subject);
 71    message.setText(body.toString());
 72    Transport.send(message);
 73    System.out.println("Message sent successfully....");
 74    returnMessage = MESSAGE_SENT;
 75   } catch (MessagingException mex) {
 76    returnMessage = "Error in Sending Message";
 77    System.out.println(returnMessage);
 78    mex.printStackTrace();
 79   }
 80   return returnMessage;
 81 
 82  }
 83 }
 84 



Model class to represent IT Mail Server


  1 package com.dubey.deepak.oim.model;
  2 
  3 public class ITMailServer {
  4  private String authentication = "false";
  5  private String server = "127.0.0.1";
  6  private String user = null;
  7  private String password = null;
  8 
  9  public ITMailServer(String authentication, String server, String user,
 10    String password) {
 11   super();
 12   this.authentication = authentication;
 13   this.server = server;
 14   this.user = user;
 15   this.password = password;
 16  }
 17 
 18  public String getAuthentication() {
 19   return authentication;
 20  }
 21 
 22  public void setAuthentication(String authentication) {
 23   this.authentication = authentication;
 24  }
 25 
 26  public String getServer() {
 27   return server;
 28  }
 29 
 30  public void setServer(String server) {
 31   this.server = server;
 32  }
 33 
 34  public String getUser() {
 35   return user;
 36  }
 37 
 38  public void setUser(String user) {
 39   this.user = user;
 40  }
 41 
 42  public String getPassword() {
 43   return password;
 44  }
 45 
 46  public void setPassword(String password) {
 47   this.password = password;
 48  }
 49 
 50 }

Comments

Popular posts from this blog

OIM 11g R2 PS2 : SOA Approval Workflow Sample

Oracle Identity Manager (OIM) Interview Questions

OHS 12c (12.1.3) webgate deployment and configuration