6.1 Concepts

LDAP Event Services utilizes the standard LDAP extension mechanism to expose the eDirectory event system. The LDAP Libraries for C# are enhanced to provide support functions to simplify the use of the event system extension.

The event system extension allows the client to specify the events for which it wants to receive notification. This information is sent in the extension request. If the extension request specifies valid events, the LDAP server keeps the connection open and uses the intermediate extended response to notify the client when events occur. Any data associated with an event is also sent in the response. If an error occurs when processing the extended request or during the subsequent processing of events, the server sends an extended response to the client containing error information and then terminates the processing of the request.

6.1.1 Configuring the eDirectory Event System

The eDirectory Event System extension is configured on a per LDAP server basis using the iManager utility (for information, see the iManager Documentation). There are two parameters that need to be set. The "allow event monitoring" parameter turns event monitoring on or off on that particular server. If event monitoring is turned off, the monitor events request fails. The second parameter is the maximum event monitoring load for the server. A zero value indicates no load limit. Each event type is assigned an integer valued load factor. The load factor is a representation of the loading effect monitoring this event has on the server relative to all other event types. The load is calculated based on each monitored event’s load factor and the number of clients registered for that event.

Client Access Rights to Event Data

Any LDAP client can register to monitor any event. Access retrictions are enforced at the time of notification. If the authenticated client does not have access rights to view all of the information in the event, the event will not be sent. The one exception to this rule is the perpetrator DN. If the client does not have rights to the perpertrator object it will be sent as a zero length string. The event notification will still be sent.

6.1.2 Monitoring the eDirectory Events

The C# sample class EdirEventSample below shows how to monitor the eDirectory events using the Novell.Directory.Ldap namespace. The code below is hard coded to monitor the event type EVT_CREATE_ENTRY and it uses the command line parameters to get the inputs such as the host name, login DN and password.

using System;
//Use the C# LDAP namespaces
using Novell.Directory.Ldap;
using Novell.Directory.Ldap.Events;
using Novell.Directory.Ldap.Events.Edir;
using Novell.Directory.Ldap.Events.Edir.EventData;

public class EdirEventSample 
{
 //Set the time out parameter.
 public const double TIME_OUT_IN_MINUTES = 5;
 public static DateTime timeOut;
	
 /**
  * Check the queue for a response. If a response has been received,
  * print the response information.
  */

 static private bool checkForAChange(LdapResponseQueue queue) 
 {
   LdapMessage message;
   bool result = true;

   try 
   {
     //check if a response has been received so we don't block
     //when calling getResponse()

     if (queue.isResponseReceived()) 
     {
        message = queue.getResponse();
        if (message != null) 
        {
	// is the response a search result reference?
	
	if (message is MonitorEventResponse) 
	{
	  MonitorEventResponse eventerrorresponse =
(MonitorEventResponse) message;
	  Console.WriteLine("\nError in Registration ResultCode  = " +
eventerrorresponse.ResultCode);
	  EdirEventSpecifier[] specifiers =
eventerrorresponse.SpecifierList;
	  for (int i = 0; i < specifiers.Length; i++) 
	  {
	     Console.WriteLine("Specifier:" + "EventType  = " +
specifiers[i].EventType);
	  }
	  Environment.Exit(-1);

	}

	// is the response a event response ?

	else if ( message is EdirEventIntermediateResponse) 
	{
	   Console.WriteLine("Edir Event Occured");
	   EdirEventIntermediateResponse eventresponse =
(EdirEventIntermediateResponse) message;
					
	   //process the eventresponse Data, depending on the
	   // type of response 
	   processEventData(eventresponse.EventResponseDataObject,
eventresponse.EventType);
                        
	}
	
	// the message is an Unknown response
	else 
	{
	   Console.WriteLine("UnKnown Message =" + message);
	}
        }
     }

  } 
  catch (LdapException e) 
  {
     Console.WriteLine("Error: " + e.ToString());
     result = false;
  }

  return result;
 }

 public static void Main(String[] args) 
 {
   if (args.Length != 3) 
   {
     Console.WriteLine("Usage:   mint EdirEventSample <host name>
<login dn>"
				+ " <password> ");
     Console.WriteLine("Example: mint EdirEventSample Acme.com
\"cn=admin,o=Acme\""
				+ " secret ");
     Environment.Exit(0);
   }
		
   int ldapPort = LdapConnection.DEFAULT_PORT;  // Set to the default
LDAP Port
   int ldapVersion = LdapConnection.Ldap_V3;           // Set to the
LDAP version 3
   String ldapHost = args[0];
   String loginDN = args[1];
   String password = args[2];

   LdapResponseQueue queue = null;

   //Create the connection
   LdapConnection lc = new LdapConnection();
		
   try 
   {
      // connect to the server
      lc.Connect(ldapHost, ldapPort);

      // authenticate to the server
      lc.Bind(ldapVersion, loginDN, password);

      //Create an Array of EdirEventSpecifier
      EdirEventSpecifier[] specifier = new EdirEventSpecifier[1];

      //Register for all Add Value events.
		
      specifier[0] = new
EdirEventSpecifier(EdirEventType.EVT_CREATE_ENTRY,
			//Generate an Value Event of Type Add Value 
			EdirEventResultType.EVT_STATUS_ALL
			//Generate Event for all status
			);

      //Create an MonitorEventRequest using the specifiers.        
      MonitorEventRequest requestoperation = new
MonitorEventRequest(specifier);
			
     //Send the request to server and get the response queue.
     queue = lc.ExtendedOperation(requestoperation, null, null);

   } 
		
   //Catch the exception
   catch (LdapException e) 
   {
      Console.WriteLine("Error: " + e.ToString());
      try 
      {
	//Disconnect
	lc.Disconnect();
      } 
      catch (LdapException e2) 
      {
	Console.WriteLine("Error: " + e2.ToString());
      }
      Environment.Exit(1);
    } 

    catch (Exception e) 
    {
	Console.WriteLine("Error: " + e.ToString());
    }

    Console.WriteLine("Monitoring the events for {0} minutes..",
TIME_OUT_IN_MINUTES );
    

    //Set the timeout value
    timeOut= DateTime.Now.AddMinutes(TIME_OUT_IN_MINUTES);

    try 
   {
      //Monitor till the timeout happens
      while (DateTime.Now.CompareTo(timeOut) < 0) 
      {
         if (!checkForAChange(queue))
           break;					
         System.Threading.Thread.Sleep(10);		
      }
   }   

    catch (System.IO.IOException e) 
    {
 	Console.WriteLine(e.Message);
    } 

    catch (System.Threading.ThreadInterruptedException e) 
    {
	Console.WriteLine(e.Message);
    }

    //disconnect from the server before exiting
    try 
    {
        lc.Abandon(queue);   //abandon the queue
        lc.Disconnect();
    } 

     catch (LdapException e) 
     {
        Console.WriteLine("Error: " + e.ToString());
     }

      Environment.Exit(0);

 } // end main


 /**
  * Processes the Event Data depending on the Type.
  */
	
 static private void processEventData( BaseEdirEventData data,
EdirEventType type) 
 {
    switch (type) 
    {	
	case EdirEventType.EVT_CREATE_ENTRY :
	// Value event.
	//Output the relevant Data.
	EntryEventData valueevent = (EntryEventData) data;
	Console.WriteLine("Entry         = " + valueevent.Entry);
	Console.WriteLine("PrepetratorDN = " +
valueevent.PerpetratorDN);
	Console.WriteLine("TimeStamp     = " + valueevent.TimeStamp);
	Console.WriteLine();
	break;
			
	default :
	//Unknow Event.				
	break;
   }

 }
}