Reg Exp
Web Design
Notes Client
IsServerUp Function
Scheduled agents in ND6 can now access other servers. But what if the other server is down? You won't be able to access it, but your code won't know why. This function should be able to reliably tell you when the remote server you're connecting to is down. We have only been using it in production for a few weeks, so we haven't run into times when there's network problems or the server is up but it's just slow. So if anyone has any input about this function, please use the feedback button at the bottom of the tip.

Basically, the code connects to the remote server and checks to see if the template log.ntf can be found and it has a valid replica ID. If the template can be found and has a valid replica ID, then the server is up. Otherwise, assume the server is down. Our testing of this function amounted to running it as a scheduled agent with the remote server up and after we shut the remote server down. It successfully returned TRUE when the server was up and FALSE when the server has been down. We have been using a scheduled hourly agent as a monitor (this is part of the process of building another application) and, so far, this function has been 100% reliable. But, like I said, we haven't experienced any network problems or unusually heavy loads on one of the servers to be able to see what this function does in those situations. Here's the code:

Function IsServerUp(session As NotesSession, serverName As String) As Boolean
   On Error Goto BubbleError
   ' Return TRUE if the remote server is up, FALSE if it is down
   Dim db As NotesDatabase
   On Error Resume Next
   Set db = session.GetDatabase(serverName, "log.ntf")
   If Not db Is Nothing Then
      If Not db.IsOpen Then Call db.Open("", "")
      ' Every once in a while Notes returns an invalid database as a valid
      ' database with a string of zeros as the replica id. Check for that.
      If db.ReplicaID = String$(Len(db.ReplicaID), "0") Then Set db = Nothing
   End If
   On Error Goto BubbleError
   If Err <> 0 Or db Is Nothing Then
      Err = 0
      IsServerUp = False
      IsServerUp = True
   End If
   Exit Function
   Error Err, Error$ & Chr$(10) & " in procedure " & Getthreadinfo(1) & ", line " & Cstr(Erl)
End Function

If you have any input, or can try this out against a heavily used server (that may not respond) or a lot of network traffic, let us know your results.