Contact Info

Crumbtrail

ActiveXperts.com » Administration » VBScript » Network Monitor » SharePoint Server

MsSharePointServer.vbs - Microsoft SharePoint Server monitoring using ActiveXperts Network Monitor

ActiveXperts Network Monitor ships with a powerful set of pre-defined checks. Each individual check has a static number of configuration items. To monitor other items, or to combine monitoring items, you can make use of custom VBScript checks.

Most of the built-in checks have a VBScript equivalent, implemented as a Function in a VBScript (.vbs) file. Out-of-the-box, each VBScript function monitors the same items as the built-in check. Feel free to modify a function. The VBScript check can be customized by editing the VBScript function.

To add a new VBScript-based Microsoft SharePoint Server monitoring check, do the following:

To customize the above monitoring check, click on the 'Edit button' next to the 'File selection box'. Notepad will be launched. You can now make changes to the VBScript function(s).

Screenshot of a VBScript MsSharePointServer check

MsSharePointServer.vbs script source code

' ///////////////////////////////////////////////////////////////////////////////
' // ActiveXperts Network Monitor  - VBScript based checks
' //  ActiveXperts Software B.V.
' //
' // For more information about ActiveXperts Network Monitor and VBScript, please
' // visit the online ActiveXperts Network Monitor VBScript Guidelines at:
' //    https://www.activexperts.com/support/network-monitor/online/vbscript/
' // 
' ///////////////////////////////////////////////////////////////////////////////
'  /

Option Explicit
Const  retvalUnknown = 1
Dim    SYSDATA, SYSEXPLANATION  ' Used by Network Monitor, don't change the names


' ///////////////////////////////////////////////////////////////////////////////

' // To test a function outside Network Monitor (e.g. using CSCRIPT from the
' // command line), remove the comment character (') in the following 5 lines:
' Dim bResult
' bResult =  CheckSharePointServer( "localhost", "", "moss", 2007 )
' WScript.Echo "Return value: [" & bResult & "]"
' WScript.Echo "SYSDATA: [" & SYSDATA & "]"
' WScript.Echo "SYSEXPLANATION: [" & SYSEXPLANATION & "]"

' //////////////////////////////////////////////////////////////////////////////


' //////////////////////////////////////////////////////////////////////////////

Function CheckSharePointServer( strComputer, strCredentials, strAppType, numVersion )

' Description: 
'     Checks if SharePoint Server is running; it checks the SharePoint services
' Parameters:
'     1) strComputer As String - Hostname or IP address of the SharePoint server you want to check
'     2) strCredentials As String - Specify an empty string to use Network Monitor service credentials.
'         To use alternate credentials, enter a server that is defined in Server Credentials table.
'         (To define Server Credentials, choose Tools->Options->Server Credentials)
'     3) strAppType As String - "wss" means: Windows SharePoint Services (WSS); "moss" means: Microsoft Offcie SharePoint Server
'     4) numVersion As Number - SharePoint version (either 2, 3, 2003 or 2007)
' Usage:
'     CheckSharePointServer( "", "", "",  )
' Sample:
'     CheckSharePointServer( "localhost", "", "moss", 2007 )


    Dim objWMIService, numResult

    CheckSharePointServer  = retvalUnknown  ' Default return value
    SYSDATA                = ""             ' Not used by this function
    SYSEXPLANATION         = ""             ' Set initial value

    If( Not getWMIObject( strComputer, strCredentials, objWMIService, SYSEXPLANATION ) ) Then
        Exit Function
    End If

    CheckSharePointServer = checkSharePointServerWMI( objWMIService, strComputer, strAppType, numVersion, SYSEXPLANATION )
    
End Function





' //////////////////////////////////////////////////////////////////////////////
' //
' // Private Functions
' //   NOTE: Private functions are used by the above functions, and will not
' //         be called directly by the ActiveXperts Network Monitor Service.
' //         Private function names start with a lower case character and will
' //         not be listed in the Network Monitor's function browser.
' //
' //////////////////////////////////////////////////////////////////////////////

Function checkSharePointServerWMI( objWMIService, strComputer, strAppType, numVersion, BYREF strSysExplanation )

    Dim lstServices, numResult
    Dim strLAppType 

    checkSharePointServerWMI     = retvalUnknown  ' Default return value
    strSysExplanation            = "Unable to check the SharePoint server machine"

    strLAppType = LCase( strAppType )

     ' Get the services list
    If( Not retrieveServicesList( objWMIService, strComputer, lstServices, strSysExplanation ) ) Then
        Exit Function
    End If 

    If( strLAppType = "wss" AND numVersion = 2 ) Then
        numResult = checkSharePointServerWss20Services( lstServices, strAppType, strSysExplanation )
        If( numResult <> True ) Then
            checkSharePointServerWMI = numResult
            Exit Function
        End If

    ElseIf( strLAppType = "wss" AND numVersion = 3 ) Then
        numResult = checkSharePointServerWss30Services( lstServices, strAppType, strSysExplanation )
        If( numResult <> True ) Then
            checkSharePointServerWMI = numResult
            Exit Function
        End If

    ElseIf( strLAppType = "moss" AND numVersion = 2003 ) Then
        numResult = checkSharePointServerMoss2003Services( lstServices, strAppType, strSysExplanation )
        If( numResult <> True ) Then
            checkSharePointServerWMI = numResult
            Exit Function
        End If
    ElseIf( strLAppType = "moss" AND numVersion = 2007 ) Then
        numResult = checkSharePointServerMoss2007Services( lstServices, strAppType, strSysExplanation )
        If( numResult <> True ) Then
            checkSharePointServerWMI = numResult
            Exit Function
        End If

    Else
        checkSharePointServerWMI = retvalUnknown
        strSysExplanation            = "Cannot check this version of SharePoint Server"
        Exit Function
    End If

    checkSharePointServerWMI     = True
    strSysExplanation            = "All conditions are met"

End Function


' //////////////////////////////////////////////////////////////////////////////

Function checkSharePointServerWss20Services( objServices, strAppType, BYREF strSysExplanation )
' Check if the Windows SharePoint 2.0 Services are running

    Dim result	
	
    result = isServiceRunning( objServices, "MSSQL$SHAREPOINT", "MSSQL$SHAREPOINT", strSysExplanation )				
    If( result = True ) Then
        result = isServiceRunning( objServices, "SPTimer", "SharePoint Timer Service", strSysExplanation )		
    End If		
	
    checkSharePointServerWss20Services = result
End Function

' //////////////////////////////////////////////////////////////////////////////

Function checkSharePointServerWss30Services( objServices, strAppType, BYREF strSysExplanation )
' Check if the Windows SharePoint 3.0 Services are running

    Dim result	
	
    result = isServiceRunning( objServices, "SPSearch", "Windows SharePoint Services Search", strSysExplanation )		
    If( result = True ) Then
        result = isServiceRunning( objServices, "SPTimerV3", "Windows SharePoint Services Timer", strSysExplanation )		
    End If		
    If( result = True ) Then
        result = isServiceRunning( objServices, "SPTrace", "Windows SharePoint Services Tracing", strSysExplanation )		
    End If	
' Following service is started manually, so it is not checked (remove comments to check this service)	
'   If( result = True ) Then
'       result = isServiceRunning( objServices, "SPAdmin", "Windows SharePoint Services Administration", strSysExplanation )				
'   End If		
' Following service is started manually, so it is not checked (remove comments to check this service)	
'   If( result = True ) Then
'      result = isServiceRunning( objServices, "SPWriter", "Windows SharePoint Services VSS Writer", strSysExplanation )		
'   End If		
	
    checkSharePointServerWss30Services = result
End Function


' //////////////////////////////////////////////////////////////////////////////

Function checkSharePointServerMoss2003Services( objServices, strAppType, BYREF strSysExplanation )
' Check if the SharePoint 2003 Services are running

    Dim result	
	
    result = isServiceRunning( objServices, "MSSQL$SHAREPOINTPORTAL", "MSSQL$SHAREPOINTPORTAL", strSysExplanation )				
    If( result = True ) Then
        result = isServiceRunning( objServices, "SPSAdmin", "SharePoint Portal Administration", strSysExplanation )		
    End If		
' Following service is started manually, so it is not checked (remove comments to check this service)
'   If( result = True ) Then
'       result = isServiceRunning( objServices, "SPSAlert", "SharePoint Portal Alert", strSysExplanation )		
'   End If		
    If( result = True ) Then
        result = isServiceRunning( objServices, "SPTimer", "SharePoint Timer Service", strSysExplanation )		
    End If
' Following service is started manually, so it is not checked (remove comments to check this service)		
'   If( result = True ) Then
'       result = isServiceRunning( objServices, "SQLAgent$SHAREPOINTPORTAL", "SQLAgent$SHAREPOINTPORTAL", strSysExplanation )		
'   End If		
	
    checkSharePointServerMoss2003Services = result
End Function



' //////////////////////////////////////////////////////////////////////////////

Function checkSharePointServerMoss2007Services( objServices, strAppType, BYREF strSysExplanation )
' Check if the SharePoint 2007 Services are running

    Dim result	
	
    result = isServiceRunning( objServices, "SPSearch", "Windows SharePoint Services Search", strSysExplanation )		
    If( result = True ) Then
        result = isServiceRunning( objServices, "SPTimerV3", "Windows SharePoint Services Timer", strSysExplanation )		
    End If		
    If( result = True ) Then
        result = isServiceRunning( objServices, "SPTrace", "Windows SharePoint Services Tracing", strSysExplanation )		
    End If	
' Following service is started manually, so it is not checked (remove comments to check this service)	
'   If( result = True ) Then
'       result = isServiceRunning( objServices, "SPAdmin", "Windows SharePoint Services Administration", strSysExplanation )				
'   End If		
' Following service is started manually, so it is not checked (remove comments to check this service)	
'   If( result = True ) Then
'      result = isServiceRunning( objServices, "SPWriter", "Windows SharePoint Services VSS Writer", strSysExplanation )		
'   End If		
	
    checkSharePointServerMoss2007Services = result
End Function



' //////////////////////////////////////////////////////////////////////////////

Function retrieveServicesList( objWMIService, strComputer, BYREF lstServices, BYREF strSysExplanation )
' Retrieve the list of running services	

    retrieveServicesList = False
    Set lstServices      = Nothing

    Set lstServices      = objWMIService.ExecQuery( "Select * from Win32_Service WHERE state = ""Running""" )
    If( Err.Number <> 0 ) Then
        strSysExplanation  = "Unable to query WMI on computer [" & strComputer & "]"
        Exit Function
    End If
    If( lstServices.Count <= 0  ) Then
        strSysExplanation  = "Win32_Service class does not exist on computer [" & strComputer & "]"
        Exit Function
    End If 

On Error Goto 0

    retrieveServicesList = True    

End Function

' //////////////////////////////////////////////////////////////////////////////

Function isServiceRunning( BYREF lstServices, strServiceName, strServiceDescription, BYREF strSysExplanation )
' Check if a given service exists as running service in the services list
    
    Dim objService

    isServiceRunning = False  ' Default return value
				
    For Each objService in lstServices			
		
        If( Err.Number <> 0 ) Then
            isServiceRunning    = retvalUnknown
            strSysExplanation   = "Unable to list services" 
            Exit Function
        End If	 
	   
        ' Check If this is the service we are looking for
        If( LCase( objService.Name ) = LCase( strServiceName ) ) Then				
            isServiceRunning    = True
            Exit Function
        End If
    Next
    
    ' The service was not found, show an error message
    strSysExplanation           = "'" & strServiceDescription & "' service is not running"    
    isServiceRunning            = False

End Function


' //////////////////////////////////////////////////////////////////////////////


Function getWMIObject( strComputer, strCredentials, BYREF objWMIService, BYREF strSysExplanation )	

On Error Resume Next

    Dim objNMServerCredentials, objSWbemLocator, colItems
    Dim strUsername, strPassword

    getWMIObject              = False

    Set objWMIService         = Nothing
    
    If( strCredentials = "" ) Then	
        ' Connect to remote host on same domain using same security context
        Set objWMIService     = GetObject( "winmgmts:{impersonationLevel=Impersonate}!\\" & strComputer &"\root\cimv2" )
    Else
        Set objNMServerCredentials = CreateObject( "ActiveXperts.NMServerCredentials" )

        strUsername           = objNMServerCredentials.GetLogin( strCredentials )
        strPassword           = objNMServerCredentials.GetPassword( strCredentials )

        If( strUsername = "" ) Then
            getWMIObject      = False
            strSysExplanation = "No alternate credentials defined for [" & strCredentials & "]. In the Manager application, select 'Options' from the 'Tools' menu and select the 'Server Credentials' tab to enter alternate credentials"
            Exit Function
        End If
	
        ' Connect to remote host using different security context and/or different domain 
        Set objSWbemLocator   = CreateObject( "WbemScripting.SWbemLocator" )
        Set objWMIService     = objSWbemLocator.ConnectServer( strComputer, "root\cimv2", strUsername, strPassword )

        If( Err.Number <> 0 ) Then
            objWMIService     = Nothing
            getWMIObject      = False
            strSysExplanation = "Unable to access [" & strComputer & "]. Possible reasons: WMI not running on the remote server, Windows firewall is blocking WMI calls, insufficient rights, or remote server down"
            Exit Function
        End If

        objWMIService.Security_.ImpersonationLevel = 3

    End If
	
    If( Err.Number <> 0 ) Then
        objWMIService         = Nothing
        getWMIObject          = False
        strSysExplanation     = "Unable to access '" & strComputer & "'. Possible reasons: no WMI installed on the remote server, no rights to access remote WMI service, or remote server down"
        Exit Function
    End If    

    getWMIObject              = True 

End Function