Monday, September 13, 2010

Lotus Script to check if a server is available

After searching through the Lotus Notes forums and blogs looking for code to determine if a server was up or not I figured out a good solution. Some of the examples I found use a template or database to check if the server is up. However there might be that chance that the template file is corrupt or missing. So here is a code snippet using the NotesDBDirectory class:


Function checkServerAvailability( ) As Boolean
' this function will check if a server is available from a user's client
On Error GoTo errorfound

Dim session As New NotesSession
Dim db As NotesDatabase
Dim dirdb As NotesDbDirectory
Dim ServerName As String

ServerName = InputBox("Enter the server name to check")

' assign database directory to dirdb variable
Set dirdb = session.GetDbDirectory(ServerName)

' grab the first database from the directory
' this line will throw the error if the server cannot be accessed
Set db = dirdb.GetFirstDatabase( DATABASE )


msgbox "Server " & Servername & " found"


checkServerAvailability = True

Exit Function

errorfound:
' since server is not found, return false with debug string
msgbox "Error" & Str(Err) & ": " & Error$

Exit Function


End Function

2 comments:

  1. Thanks a lot!!!! It helped me to check whether the server is up or not.

    ReplyDelete
  2. Can you tell me how to schedule this check using an agent? I would like it to check if the server is down at 3:15am everyday and email me if it is not.

    Thanks.

    ReplyDelete