Home > Ask the Domino Experts > LotusScript Questions & Answers > How to parse the user activity of a Lotus Notes database
Ask The Domino Expert: Questions & Answers
EMAIL THIS

How to parse the user activity of a Lotus Notes database

Cregg Hardwick EXPERT RESPONSE FROM: Cregg Hardwick

Pose a Question
Other Domino Categories
Meet all Domino Experts
Become an Expert for this site


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


>
QUESTION POSED ON: 25 September 2006

Is it possible to parse the user activity of a Lotus Notes database? I want to remove automatic access to the Lotus Notes database (by agents or servers), using LotusScript.


>
EXPERT RESPONSE

VIEW MEMBER FEEDBACK TO THIS ASK THE EXPERT Q&A.

Absolutely. First you will need to visit http://www-10.lotus.com/ldd/sandbox.nsf and search for "UserActivity". Download the "NotesUserActivity Class" file. This is a sample Lotus Notes database containing a script library called "CLASSUserActivity."

When you look at this library, you will see only one subroutine. That's because in Lotus Notes, classes are defined in the "Declarations" section, so this library is basically one giant declaration (thus explaining why no one uses OOP or classes in LotusScript!).

I'm going to give you the LotusScript code you need to use this beastie, thus you'll have to find something else to spend the next two weeks figuring out.

I'll warn you -- pulling the usage history from each Lotus Notes database is fairly time consuming. In this code, lifted directly from my production application inventory crawler, Names2exclude lists the Lotus Domino servers, developers and administrators to ignore.

The usage counters here are declared globally, because the routine must be called once on each Lotus Domino server where a replica of the Lotus Notes database resides. Since each replica copy of a database has its own independent history, in this way the usage from all Lotus Domino server replica copies can be aggregate.

Const Names2exclude=
"CORPAGENTSIGNER~APPS001~CREGG S HARDWICK"

Dim WeekUses As Long,
WeekReads As Long,WeekWrites As Long
Dim MonthUses As 
Long,MonthReads As Long,MonthWrites As Long
Dim totaluses As Long,totalreads 
As Long,totalwrites As Long

Sub GetUserActivity(db As NotesDatabase)
 
Dim ua As New NotesUserActivity(db)

Dim uae As notesuseractivityentry

If ua.HasUserActivity Then
weekUses=ua.PrevWeekUses
weekReads=ua.PrevWeekReads
weekWrites=ua.PrevWeekWrites
monthUses=ua.PrevmonthUses
monthReads=ua.PrevmonthReads
monthWrites=ua.PrevmonthWrites
totalUses=ua.Uses
totalReads=ua.Reads
totalWrites=ua.Writes

Dim ActivityEntries As Long
ActivityEntries=ua.UserActivityCount

If ActivityEntries>0 Then
Print "        -- Reading "+
Format(ActivityEntries,"###,##0")+_
" history records..."
End If 
 
Dim index As Variant,result As Variant
Dim AIndex As Long
For AIndex = 1 To ActivityEntries
Set uae = ua.GetNthUserActivityEntry(AIndex)
result=Evaluate
({@Name([Abbreviate];"}+_
uae.UserName+{"):@Name([cn];"}+_
uae.UserName+{")})
If Instr(names2exclude,Ucase(result(1)))=0 Then
index=Arraygetindex(UserList,result(0))
If Isnull(index) Then
If users<=maxusers Then  
Redim Preserve UserList(Users) As String
Redim Preserve readsList(Users) As Long
Redim Preserve writesList(Users) As Long
Redim Preserve sessionList(Users) As Long
Redim Preserve timeList(Users) As String
UserList(Users)=result(0)
timelist(users)=uae.time
sessionList(Users)=1
readsList(Users)=uae.reads
writeslist(users)=uae.writes
Users=Users+1
End If
Else
sessionList(Index)=sessionList(Index)+1
readsList(Index)=readsList(Index)+uae.reads
writeslist(Index)=writeslist(Index)+uae.writes
End If
End If
Next AIndex
  
End If
End Sub

MEMBER FEEDBACK TO THIS ASK THE EXPERT Q&A:

I still have a problem with this code. When I try to save the agent I get the following error: "Reference occurs before declaration:UserList"

Allow me to point out that the variable is only declared three lines later.

If Instr(names2exclude,Ucase(result(1)))=0 Then
index=Arraygetindex(UserList,result(0))
If Isnull(index) Then
If users<=maxusers Then  
Redim Preserve UserList(Users) As String
Redim Preserve readsList(Users) As Long
Redim Preserve writesList(Users) As Long
Redim Preserve sessionList(Users) As Long
Redim Preserve timeList(Users) As String
UserList(Users)=result(0)
timelist(users)=uae.time
sessionList(Users)=1
readsList(Users)=uae.reads
writeslist(users)=uae.writes
Users=Users+1
End If
Else
sessionList(Index)=sessionList(Index)+1
readsList(Index)=readsList(Index)+uae.reads
writeslist(Index)=writeslist(Index)+uae.writes
End If
End If
Next AIndex

—Wannes R.

******************************************

My apologies, I left out part of the Global Declarations section needed to support the GetUserActivity subroutine. Of course if -- in my production application, I had taken the time to compartmentalize this code in its own script library, then such a mistake would have been much harder to make!

To fix it, add the following to the Declarations section of your agent:

Dim users As Long
Dim UserList() As String
Dim readsList() As Long
Dim writesList() As Long
Dim timelist() As String
Dim sessionList() As Long

Once more, the agent or script library should be set up as follows:

In the Options section:

'Option Public
Use "CLASSUserActivity"
Const Names2exclude=
"CORPAGENTSIGNER~APPS001
~CREGG S HARDWICK"
The Declarations section:
Dim totaluses As Long,totalreads 
Dim WeekUses As Long,
WeekReads As Long,WeekWrites As Long
Dim MonthUses As Long, 
MonthReads As Long, MonthWrites As Long , 
totalwrites As Long
Dim users As Long
Dim UserList() As String
Dim readsList() As Long
Dim writesList() As Long
Dim timelist() As String
Dim sessionList() As Long

The initialize event for a test 
agent that will call it:
Sub Initialize
Dim db As New notesdatabase("","")
Call db.OpenByReplicaID
(YOURSERVER,YOURDBREPLICAID)
Call GetUserActivity(db)
' Access the global variables 
above to get results…
End Sub
The subroutine that does the work:
Sub GetUserActivity(db As NotesDatabase)
            
Dim ua As New NotesUserActivity(db)
            
Dim uae As notesuseractivityentry
            
If ua.HasUserActivity Then
weekUses=ua.PrevWeekUses
weekReads=ua.PrevWeekReads
weekWrites=ua.PrevWeekWrites
monthUses=ua.PrevmonthUses
monthReads=ua.PrevmonthReads
monthWrites=ua.PrevmonthWrites
totalUses=ua.Uses
totalReads=ua.Reads
totalWrites=ua.Writes
                        
Dim ActivityEntries As Long
ActivityEntries=ua.UserActivityCount
                        
If ActivityEntries>0 Then
Print "        
-- Reading "+Format(ActivityEntries,"###,##0")
+" history records..."
End If 
                        
Dim index As Variant,result As Variant
Dim AIndex As Long
For AIndex = 1 To ActivityEntries
Set uae = ua.GetNthUserActivityEntry(AIndex)
result=Evaluate({@Name([Abbreviate];"}
+uae.UserName+{"):@Name([cn];"}
+uae.UserName+{")})
If Instr(names2exclude,Ucase(result(1)))=0 Then
index=Arraygetindex(UserList,result(0))
If Isnull(index) Then
 If users<=maxusers Then  
Redim Preserve UserList(Users) As String
Redim Preserve readsList(Users) As Long
Redim Preserve writesList(Users) As Long
Redim Preserve sessionList(Users) As Long
Redim Preserve timeList(Users) As String
UserList(Users)=result(0)
timelist(users)=uae.time
sessionList(Users)=1
readsList(Users)=uae.reads
writeslist(users)=uae.writes
Users=Users+1
End If
Else
sessionList(Index)=sessionList(Index)+1
readsList(Index)=readsList(Index)+uae.reads
writeslist(Index)=writeslist(Index)+uae.writes
End If
End If
                        Next AIndex
                        
            End If
End Sub

Cregg Hardwick, LotusScript expert

Do you have comments on this Ask the Expert Q&A? Let us know.

Related information from SearchDomino.com:

  • Learning Guide: LotusScript development
  • FAQ: LotusScript advice
  • Reference Center: LotusScript tips and resources


  • Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


    RELATED CONTENT
    LotusScript
    Can I use LotusScript to merge cells in a Microsoft Word table?
    Modifying LotusScript code for date and time handling
    Use DXL utilities for advanced replication settings in Notes
    Use LotusScript to create encrypted replicas
    Write a LotusScript agent to automate file attachments
    Troubleshooting a scheduled agent not running on a Global Notes Architecture (GNA) server
    Setting up local replication of a Lotus Notes database for offline employees
    Creating a link on an HTML page to a Microsoft Word attachment in a Lotus Notes database
    LotusScript to extract and move attachments to a Lotus Notes mailbox or file folder
    Copying a rich-text field with attachments to a Lotus Notes document

    LotusScript
    Alternate version of @Command forwards subform via LotusScript
    Process large arrays in Notes forms without undue coding or testing
    How to use LotusScript to modify a Lotus Notes view selection
    Display a custom message box using a LotusScript-generated button
    Can I use LotusScript to merge cells in a Microsoft Word table?
    Debug Lotus Notes documents using extracted data
    Extracting attachments from a Lotus Notes rich-text field
    Programmatically replace the design of Lotus Notes databases
    Reading a binary field in an Oracle database with LotusScript
    LotusScript equivalent of @Picklist for Lotus Notes

    Database
    Fix and update Lotus Notes documents with limited access
    Programmatically replace the design of Lotus Notes databases
    Add a program doc to compact Lotus Notes databases automatically
    More efficient local Lotus Notes database replication
    Remove orphaned Lotus Notes documents on Domino databases with a 'virtual delete'
    Detect and fix 'Manager' access control list settings in Lotus Notes Domino
    Copy Lotus Notes databases from the Domino Server console command line
    Tutorial: How to import data into Lotus Notes -- without programming
    A flexible data export agent for Lotus Notes
    Managing Lotus Notes doclinks with LotusScript

    RELATED RESOURCES
    2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
    Search Bitpipe.com for the latest white papers and business webcasts
    Whatis.com, the online computer dictionary



    Search and Browse the Expert Answer Center
    Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
    Browse our Expert Advice

    HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
    About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
    SEARCH 
    TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

    TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




    All Rights Reserved, Copyright 1999 - 2008, TechTarget | Read our Privacy Policy
      TechTarget - The IT Media ROI Experts