Skip to main content

Auditing User Activity

Auditing User Activity

You can execute custom code, such as writing to an audit log, every time a user executes a query or accesses a dashboard.

To add custom code to execute when users execute a query, perform the following one-time setup steps:

  • Write a class method, routine, or subroutine that contains the custom code. The first subsection provides details on the requirements and options; the second subsection provides an example.

  • Set ^DeepSee.AuditQueryCode equal to a string containing a valid ObjectScript statement that executes that method, routine, or subroutine.

    For example, do the following in the Terminal:

    set ^DeepSee.AuditCode="do ^MyBIAuditCode"
    

    Every time a query is executed in this namespace, the system executes the code specified in ^DeepSee.AuditQueryCode, thus invoking your routine or class method.

Similarly, to add custom code to execute when users access a dashboard:

  • Write a class method, routine, or subroutine that contains the custom code.

  • Set ^DeepSee.AuditCode equal to a string containing a valid ObjectScript statement that executes that method, routine, or subroutine.

    Every time a dashboard is accessed in this namespace, the system executes the code specified in ^DeepSee.AuditCode.

Audit Code Requirements and Options

When you define audit code for either scenario, make sure that the code does not write any output to the current device. Also make sure that it does not kill any % variables required by InterSystems IRIS® data platform.

Your code can use the following variables:

Typically, audit code writes output to a file or to a global.

Note that %dsQueryText, %dsCubeName, and %dsResultSet are only available to audit routines using ^DeepSee.AuditQueryCode, while %dsDashboard is only available to routines using ^DeepSee.AuditCode.

Example

The following shows a simple example audit routine. It has one subroutine for use with ^DeepSee.AuditQueryCode and another subroutine for use with ^DeepSee.AuditCode:

 ; this is the routine DeepSeeAudit
 quit
 
dashboard 
 set auditentry="At "_$ZDT($H,3)_", " _$USERNAME_" accessed dashboard: "_%dsDashboard
 set ^MyBIAuditLog($INCREMENT(^MyBIAuditLog))=auditentry
 quit

query
 set auditentry="At "_$ZDT($H,3)_", " _$USERNAME_" ran query: "_%dsQueryText
 set ^MyBIAuditLog($INCREMENT(^MyBIAuditLog))=auditentry
 quit

To use this routine, we would enter the following two lines in the Terminal:

SAMPLES>set ^DeepSee.AuditQueryCode="do query^DeepSeeAudit"
 
SAMPLES>set ^DeepSee.AuditCode="do dashboard^DeepSeeAudit"

To see the audit log, we can use ZWRITE. The following shows example results (with line breaks added for readability):

SAMPLES>zw ^MyBIAuditLog
^MyBIAuditLog=2
^MyBIAuditLog(1)="At 2014-06-20 16:26:38, SamSmith accessed dashboard: User Defined Listing.dashboard"
^MyBIAuditLog(2)="At 2014-06-20 16:26:38, SamSmith ran query: SELECT NON EMPTY {[MEASURES].[AMOUNT SOLD],
[MEASURES].[UNITS SOLD]} ON 0,NON EMPTY [DATEOFSALE].[ACTUAL].[YEARSOLD].MEMBERS ON 1 FROM [HOLEFOODS]"
FeedbackOpens in a new tab