Find errors in Notes log through mail database

This agent can be added to a user's mail database and launched from the Notes client when a user is in the mail file. It's a modification of a previous tip, which ran on a server.

Editor's note: This is a modified version of a tip that Mike previously posted. The first tip, which can be read

here, runs on a server. This tip, on the other hand, runs in the Notes client itself.

View member feedback to this tip.

This agent can be added to the user's mail database and launched from the Notes client when the user is in the mail file. It may be imported into the design of the mailfile by using Designer client. Create a new agent called "Find Errors". Select Lotusscript as the type of agent in the Options field. Trigger should be "On Event". Run from Actions Menu, Target is None. Place cursor in programmer's pane and choose File, Import and bring in the text file from wherever the attached file was saved.

'Find Errors Agent: 
'This agent should be
 installed in the user's local mail file.
 It is run by selecting Actions, Find Errors. 
'A report message will be presented
when finished.

Option Public

Dim db As NotesDatabase
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument
Dim mailDb As NotesDatabase
Dim mailDoc As NotesDocument
Dim dt As String
Dim item As NotesItem
Dim rtitem As NotesRichTextItem
Dim rtStyle As NotesRichTextStyle


%REM 
This agent searches today's 
documents in server logs for
 particular words that indicate errors.
A list is generated and inserted into 
a mail message that is sent to the current user.
%END REM

Sub Initialize
 Dim s As New NotesSession
 Dim ws As New NotesUIWorkspace
 
 REM Words to search log for. Increase
 or decrease array bounds and add 
more words if needed.
 Dim srch (4) As String
 srch(0) = "unable"
 srch(1) = "error"
 srch(2) = "fail"
 srch(3) = "ATTEMPT"
 srch(4) = "invalid"
 
 REM Servers' logs to search. Increase or
 decrease array bounds and add 
more servers if needed.
 Dim srv (3) As String
 srv(0) = "srv1"
 srv(1) = "srv2"
 srv(2) = "srv3"
 srv(3) = "srv4"
 
 
 REM Set up  today's date and format 
 dt = Format(Date$, "mm/dd/yyyy")
 
 REM Create mail memo 
to hold output from server log    
 Set mailDb = New NotesDatabase("", "")
 Call mailDb.Openmail
 Set mailDoc = New NotesDocument( mailDb )
 Set rtitem = 
New NotesRichTextItem( mailDoc, "Body")
 Set rtStyle = s.CreateRichTextStyle
 Dim msg As String
 msg = "Search Keywords: "
 Forall w In srch
  msg = msg & { "} & w & {"}
 End Forall
 rtStyle.Bold=True
 Call rtitem.AppendStyle(rtStyle)
 Call rtItem.AppendText( msg )
 rtStyle.Bold = False
 Call rtitem.AppendStyle(rtStyle)
 Call rtitem.AddNewline(2)
 
 REM Process for every server
 Forall m In srv
  Print "Searching Notes Log on " & m
  Set db = s.GetDatabase( m, "log.nsf")
  If db Is Nothing Then
   Msgbox "Notes Log not found 
or this ID has no access.", , "Attention"
   Exit Sub
  End If
  Call rtitem.AddNewline(1)  
  rtStyle.Bold = True 
  Call rtitem.AppendStyle(rtStyle)
  Call  rtitem.AppendText("Log for " & db.Server)
  rtStyle.Bold = False
  Call rtitem.AppendStyle(rtStyle)
  Call rtitem.AddNewline(2)
  
  REM Process for each 
search word in one server's log
  Forall e In srch
   Set dc = db.FTSearch( dt , 0)
   Call dc.FTSearch(e, 0)
   
   REM Process if any words are found
   If dc.Count > 0  Then
    REM Process the list of docs 
containing the search word and 
add them to mail message    
    Call FindErrors( dc , e)
   End If
  End Forall  'process next search word
 End Forall  'process next server 
 
 REM Send mail message 
if any errors are found in log 
 If Not mailDoc Is Nothing Then
  mailDoc.Form = "Memo"
  mailDoc.From = "Notes Error Log Report"
  mailDoc.Subject = 
"Error Report from Notes Logs"
  'Call mailDoc.Send(False, s.UserName)
  Call mailDoc.Save(True,False)
  Call mailDoc.PutInFolder("($Inbox)")
  Call ws.EditDocument(True, mailDoc)
 End If
 
End Sub
Sub FindErrors
( coll As NotesDocumentCollection, 
srctxt As String)
 For i = 1 To coll.Count
  Set doc = coll.GetNthDocument(i)
  Set item = doc.GetFirstItem("EventList")
  Forall v In item.Values
   'Msgbox v
   chk = Instr(1, v, srctxt, 5)
   If Not chk = 0 Then
    'Msgbox v
    Call rtitem.AppendText( v )
    Call rtitem.AddNewline(1)
   End If
  End Forall
 Next
End Sub

MEMBER FEEDBACK TO THIS TIP

I have found this tip very usefull but I had to improve it with respect to some differences in log documents format in older versions.

First, I improved Subroutine FindErrors:

Sub FindErrors( coll As 
NotesDocumentCollection, 
srctxt As String) 
        Dim i As Integer, chk As Integer 
        Dim EventList As Variant 
        For i = 1 To coll.Count 
 Set doc = coll.GetNthDocument(i) 
Set item = doc.GetFirstItem("EventList") 
                If item Is Nothing Then 
' Older versions had field Events 
                        EventList = Evaluate
("@Explode( Events; @NewLine)", doc) 
                Else 
                        EventList = item.Values 
                End If 
                Forall v In EventList 
   'Msgbox v 
                        chk = Instr(1, v, srctxt, 5) 
                        If chk > 0 Then 
                                Call rtitem.AppendText( v ) 
                                Call rtitem.AddNewline(1) 
                        End If 
                End Forall 
        Next 
End Sub 

Also, for sake of efficiency (and limitations) I replaced TFSearch method with simple Search method:

Dim cutoffdate As 
New NotesDateTime( Date$) 
        Call cutoffdate.AdjustDay(-1) 
... 
 REM Process for each 
search word in one server's log 
                Forall e In srch 
                        Set dc = db.Search
( |Form="Events"|, cutoffdate , 0) 
                        Call dc.FTSearch(e, 0) 
... 

—Milos S.

Do you have comments on this tip? Let us know.

This tip was submitted to the SearchDomino.com tip exchange by member Mike Long. Please let others know how useful it is via the rating scale below. Do you have a useful Notes/Domino tip or code to share? Submit it to our bimonthly tip contest and you could win a prize and a spot in our Hall of Fame.

This was first published in July 2005

Dig deeper on Lotus Notes Domino Agents

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

SearchWinIT

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchEnterpriseLinux

SearchVirtualDataCentre.co.uk

Close