OpenNTF.org - Get all the servers in a clust
My Links (Not logged in)
Code Bin Search
 
Hosted by Prominic.NET
Rate This Code
5 - brilliant stuff
4 - very nice
3 - average
2 - needs work
1 - bad
   OpenNTF Code Bin
Edit Document Code By Date > Code Document
About This Code
Brief Description:
Get all the servers in a cluster 
Rating:
Not Rated Yet 
Contributor:
Mike Mortin 
Category:
Lotusscript 
Type:
Miscellaneous 
Notes Version:
R6.x, R8.x, R7.x 
Last Modified:
04 Nov 2008 
OpenNTF Disclaimer

All of the program code and information presented in the OpenNTF.org Code Bin are provided "as-is", and should be used at your own risk. OpenNTF.org make no express or implied warranty about anything in the Code Bin, and OpenNTF.org will not be responsible or liable for any damage caused by the use or misuse of anything from this site. OpenNTF.org makes no guarantees about anything. Please thoroughly test all of the knowledge and code you find here before you attempt to use them in your production environment.

Code / Description
Function GetClusterServers(server As String, getAllServers As Boolean) As Variant

' returns a list of servers in cluster, given one server
' posted to http://www.openntf.org/projects/codebin/codebin.nsf/CodeBySubCategory/71497FFD8E4531A7862574EF006567C5
' written by Mike Mortin 20081027

Dim s As New NotesSession
Dim cluster As String
Dim serverDoc As NotesDocument
Dim serverName As NotesName
Dim key(1 To 1) As Variant
Dim navDoc As NotesViewEntry
Dim nav As NotesViewNavigator

' define domain and name as per the default "Servers" view
Set serverName = New NotesName(server)
key(1) = serverName.Canonical
Set serverDoc = GetDocFromDb(s.CurrentDatabase, "($Servers)", key, True)

' get a list of servers in the same cluster
cluster = serverDoc.ClusterName(0)

If cluster = "" Then
' if there is no cluster
GetClusterServers = Iif(getAllServers, serverName.Abbreviated, Null)
Else
' grab all server documents in the cluster
Set nav = GetCategoryDocsFromDb(currentDb, "Clusters", cluster)

' go through the category, add names to replica list, skip the submitted server if requested
Set navDoc = nav.GetFirstDocument()
While Not navDoc Is Nothing
Set serverDoc = navDoc.Document
If serverDoc.ServerName(0) <> server Or getAllServers Then
Set serverName = New NotesName(serverDoc.ServerName(0))
GetClusterServers = GetClusterServers & serverName.Abbreviated & ","
End If
Set navDoc = nav.GetNextDocument(navDoc)
Wend
End If

' tighten up the list
GetClusterServers = Split(GetClusterServers, ",")
GetClusterServers = Fulltrim(GetClusterServers)
End Function

Usage / Example
use this code to get all the servers in a cluster
the second parameter specifies whether or not you want the submitted server in the list ( ie just the cluster mates or the whole cluster )

... ' here we only only want the cluster mates
' set the primary roaming server
Set primaryName = New NotesName(personDoc.MailServer(0))
Call personDoc.ReplaceItemValue("RoamSrvr", primaryName .Abbreviated)

' populate the replica servers field
replicas = GetClusterServers(primaryName.Abbreviated, false)
replicas = Join(replicas, ",")
Call personDoc.ReplaceItemValue( "RoamRplSrvrs", replicas )


... ' here we only want to search all replicas for user access ( which is stored on each db individually )
servers = GetClusterServers(mailServer, true)
Forall s in servers
Call ExamineUserAccess(s, mailFile)
End Forall
 Comments
Posted by Mike Mortin on 11/04/2008 10:42:04 AMupdated one view ...
The lookup didn't execute corretly when the server had subdomains. I changed these lines:
Dim key(1 To 2) As Variant
...
' define domain and name as per the default "Servers" view
Set serverName = New NotesName(server)
key(1) = serverName.Organization
key(2) = serverName.Abbreviated
Set serverDoc = GetDocFromDb(s.CurrentDatabase, "Servers", key, True)
to this:
Dim key(1 To 1) As Variant
...
' define domain and name as per the default "Servers" view
Set serverName = New NotesName(server)
key(1) = serverName.Canonical
Set serverDoc = GetDocFromDb(currentDb, "($Servers)", key, True)
Posted by Mike Mortin on 11/04/2008 11:34:04 AMaccount for servers that are not in a cluster
I changed these lines:
' get a list of servers in the same cluster
cluster = serverDoc.ClusterName(0)
If cluster = "" Then
' if there is no cluster
GetClusterServers = Iif(getAllServers, serverName.Abbreviated, Null)
Else
' grab all server documents in the cluster
Set nav = GetCategoryDocsFromDb(currentDb, "Clusters", cluster)
makes use of the Iif function found here:
http://www.openntf.org/Projects/codebin/codebin.nsf/CodeBySubCategory/328BED8C4AB8E446862574EF0068734A
 Add your comment!