Freigeben über


Adding and triggering custom audit events in CCAUII

As most folks who work with CCA\UII know,  UII has its own auditing system that audits events for the agent desktop.  I recently was asked how to go about adding a custom audit event and storing that information in UII’s audit system.

Audit events shipped with UII

These are events that are installed by default… by default they are all disabled.  To enable, you need to flip the bits in the UII Options entity to 1 for the events your interested in.

Flag Name What it does
AuditFlagAction Raised when an action is called on a hosted control
AuditFlagAgentState Raised when the CTI State of an agent changes
AuditFlagHostedApplication Raised when a hosted application changes or is loaded
AuditFlagInteraction Can be raised by a developer code as necessary
AuditFlagLogin Raised when a UII Login or Logout event occurs
AuditFlagSession Raised when a session is changed, loaded or closed.
AuditFlagWorkFlow Raised when the onboard workflow system is used with state information on the workflow

So that’s great,  Now how to I add my OWN events.

Adding an audit event to catch the desktop shutdown.

Lets say I want to log the desktop shutdown,  as you can see that’s not covered in the out of the box list.  Lets add it.

Right Way vs Just getting it done…

As with most things in coding,  there are multiple ways to do something, UII is no different.  in this case, I'm going to cover what I suggest is the correct way to add in a log event and provide a means for the operations folks that come behind you to maintain it and switch it.

First thing to do is add a new value to the UII Options table,  lets call this value "AuditFlagDesktopShutdown”.
Goto Settings –> UII Options.  Press the new button and add the entry as it appears below.

image

Ok now to our Agent desktop code,

In the agent UiiServices class,  locate the method “BeforeDesktopClose

Add this code to it

    1: // Generally this part is done in your desktop setup,  I'm doing it here for readability 
    2: // this is the name of my config key.
    3: string myKey = "AuditFlagDesktopShutdown";
    4: // this gets the current value from the UII Options entity
    5: string sValue = ConfigurationReader.ReadAppSettings(myKey);
    6: // this sets the audit state for that key
    7: AuditLog.SetAuditFlag(myKey, sValue);
    8:  
    9: // This part occurs at the time of the event. 
   10: // this creates the data payload for the audit event,
   11: Microsoft.Uii.Common.Entities.LogData data = new Microsoft.Uii.Common.Entities.LogData()
   12: {
   13:     Action = "DesktopShutdown",
   14:     ActionData = string.Format("Desktop Shutdown event at {0}", DateTime.Now.ToString())
   15: };
   16: // this raises the audit event. 
   17: AuditLog.Log(myKey, data); 

This code is broken into two parts. The first part is the setup and registration of the audit key in the desktop. Where the call to ConfigurationReader.ReadAppSettings is reading the key from the UII Options entity.

The set command registers it with UII for future use.  as such you only need to do this part once at the start of your desktop normally.  Once this is done, UII will respect the audit setting and either log or not log the event based on the setting.

The second part is where the actual log event occurs.

Once that is done you can use an Advanced find to locate the and see the UII Audit entity in CRM.

For clarity sake,  my UII Options entity looks like this :

image

Happy Coding.

Comments