How to parse the user activity of a Lotus Notes database

来源:互联网 发布:图片相似度对比算法 编辑:程序博客网 时间:2024/06/05 11:54

How to parse the user activity of a Lotus Notes database

Cregg Hardwick
  • E-Mail
  • Print
  • A
  • AA
  • AAA
  • LinkedInShare
  • Facebook
  • Twitter
  • Share This
  • Reprints

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.

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 LongDim MonthUses As Long,MonthReads As Long,MonthWrites As LongDim totaluses As Long,totalreads As Long,totalwrites As LongSub GetUserActivity(db As NotesDatabase) Dim ua As New NotesUserActivity(db)Dim uae As notesuseractivityentryIf ua.HasUserActivity ThenweekUses=ua.PrevWeekUsesweekReads=ua.PrevWeekReadsweekWrites=ua.PrevWeekWritesmonthUses=ua.PrevmonthUsesmonthReads=ua.PrevmonthReadsmonthWrites=ua.PrevmonthWritestotalUses=ua.UsestotalReads=ua.ReadstotalWrites=ua.WritesDim ActivityEntries As LongActivityEntries=ua.UserActivityCountIf ActivityEntries>0 ThenPrint "        -- Reading "+Format(ActivityEntries,"###,##0")+_" history records..."End If  Dim index As Variant,result As VariantDim AIndex As LongFor AIndex = 1 To ActivityEntriesSet uae = ua.GetNthUserActivityEntry(AIndex)result=Evaluate({@Name([Abbreviate];"}+_uae.UserName+{"):@Name([cn];"}+_uae.UserName+{")})If Instr(names2exclude,Ucase(result(1)))=0 Thenindex=Arraygetindex(UserList,result(0))If Isnull(index) ThenIf users<=maxusers Then  Redim Preserve UserList(Users) As StringRedim Preserve readsList(Users) As LongRedim Preserve writesList(Users) As LongRedim Preserve sessionList(Users) As LongRedim Preserve timeList(Users) As StringUserList(Users)=result(0)timelist(users)=uae.timesessionList(Users)=1readsList(Users)=uae.readswriteslist(users)=uae.writesUsers=Users+1End IfElsesessionList(Index)=sessionList(Index)+1readsList(Index)=readsList(Index)+uae.readswriteslist(Index)=writeslist(Index)+uae.writesEnd IfEnd IfNext AIndex  End IfEnd 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 Thenindex=Arraygetindex(UserList,result(0))If Isnull(index) ThenIf users<=maxusers Then  Redim Preserve UserList(Users) As StringRedim Preserve readsList(Users) As LongRedim Preserve writesList(Users) As LongRedim Preserve sessionList(Users) As LongRedim Preserve timeList(Users) As StringUserList(Users)=result(0)timelist(users)=uae.timesessionList(Users)=1readsList(Users)=uae.readswriteslist(users)=uae.writesUsers=Users+1End IfElsesessionList(Index)=sessionList(Index)+1readsList(Index)=readsList(Index)+uae.readswriteslist(Index)=writeslist(Index)+uae.writesEnd IfEnd IfNext 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 LongDim UserList() As StringDim readsList() As LongDim writesList() As LongDim timelist() As StringDim sessionList() As Long

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

In the Options section:

'Option PublicUse "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 LongDim MonthUses As Long, MonthReads As Long, MonthWrites As Long , totalwrites As LongDim users As LongDim UserList() As StringDim readsList() As LongDim writesList() As LongDim timelist() As StringDim sessionList() As LongThe initialize event for a test agent that will call it:Sub InitializeDim 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 ThenweekUses=ua.PrevWeekUsesweekReads=ua.PrevWeekReadsweekWrites=ua.PrevWeekWritesmonthUses=ua.PrevmonthUsesmonthReads=ua.PrevmonthReadsmonthWrites=ua.PrevmonthWritestotalUses=ua.UsestotalReads=ua.ReadstotalWrites=ua.Writes                        Dim ActivityEntries As LongActivityEntries=ua.UserActivityCount                        If ActivityEntries>0 ThenPrint "        -- Reading "+Format(ActivityEntries,"###,##0")+" history records..."End If                         Dim index As Variant,result As VariantDim AIndex As LongFor AIndex = 1 To ActivityEntriesSet uae = ua.GetNthUserActivityEntry(AIndex)result=Evaluate({@Name([Abbreviate];"}+uae.UserName+{"):@Name([cn];"}+uae.UserName+{")})If Instr(names2exclude,Ucase(result(1)))=0 Thenindex=Arraygetindex(UserList,result(0))If Isnull(index) Then If users<=maxusers Then  Redim Preserve UserList(Users) As StringRedim Preserve readsList(Users) As LongRedim Preserve writesList(Users) As LongRedim Preserve sessionList(Users) As LongRedim Preserve timeList(Users) As StringUserList(Users)=result(0)timelist(users)=uae.timesessionList(Users)=1readsList(Users)=uae.readswriteslist(users)=uae.writesUsers=Users+1End IfElsesessionList(Index)=sessionList(Index)+1readsList(Index)=readsList(Index)+uae.readswriteslist(Index)=writeslist(Index)+uae.writesEnd IfEnd If                        Next AIndex                                    End IfEnd Sub

Cregg Hardwick, LotusScript expert

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

原创粉丝点击