performancecounter.vbs - vbscript script by ActiveXperts Software
performancecounter.vbs checks a Windows Performance Counter.
Use performancecounter.vbs directly from ActiveXperts Network Monitor; in the Manager's 'Monitor' menu, select 'New Check (Script)' and select performancecounter.vbs. Configure the required parameter, or press 'Load a working sample'.
In ActiveXperts Network Monitor, Administrators can use three different scripting languages: Powershell, VBScript and SSH.
performancecounter.vbs script code
' ///////////////////////////////////////////////////////////////////////////////
' // ActiveXperts Network Monitor - VBScript based checks
' // For more information about ActiveXperts Network Monitor and VBScript, visit
' // http://www.activexperts.com/support/network-monitor/online/vbscript/
' ///////////////////////////////////////////////////////////////////////////////
Option Explicit
' Declaration of global variables
Dim SYSDATA, SYSEXPLANATION ' SYSDATA is displayed in the 'Data' column in the Manager; SYSEXPLANATION in the 'LastResponse' column
' Constants - return values
Const retvalUnknown = 1 ' ActiveXperts Network Monitor functions should always return True (-1, Success), False (0, Error) or retvalUnknown (1, Uncertain)
' // To test a function outside Network Monitor (e.g. using CSCRIPT from the
' // command line), remove the comment character (') in the following lines:
' Dim bResult
' bResult = CheckPerformanceCounter( "localhost", "", "Processor", "_Total", "% Processor Time", "<=", 2 )
' WScript.Echo "Return value: [" & bResult & "]"
' WScript.Echo "SYSDATA: [" & SYSDATA & "]"
' WScript.Echo "SYSEXPLANATION: [" & SYSEXPLANATION & "]"
Function CheckPerformanceCounter( strHost, strAltCredentials, strPerfObject, strPerfContext, strPerfItem, strOperator, numLimit )
' Description:
' Check a Windows Performance Counter
' This function uses ActiveXperts 'NMPerf' ActiveX object.
' Parameters:
' 1) strHost As String - Hostname or IP address of the computer you want to ping
' 2) strAltCredentials 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) strPerfObject - Performance counter
' 4) strPerfContext - Performance context. Specify an empty string in case there's no context required
' 5) strPerfItem - Performance item.
' 6) strOperator - Operator, used to compare current value against the limit. Valid values are =, <, <=, <>, >, >=
' 7) numLimit - Limit
' Usage:
' CheckPerformanceCounter( "<Hostname | IP>", "<Empty String | Server>", "<Counter>", "<Context>", "<Item>", "<Operator>", <Limit> )
' Sample:
' CheckPerformanceCounter( "localhost", "", "Processor", "_Total", "% Processor Time", "<=", 2 )
Dim objPerf, strPath, strSysExplanation, strEval
Dim strAltUserName, strAltPassword
Dim numValue
Dim bCompareResult
CheckPerformanceCounter = retvalUnknown ' Default return value
SYSDATA = "" ' Will hold the response time in milliseconds
SYSEXPLANATION = "" ' Set initial value
' Load the ActiveXperts Network Monitor Perfomance object
Set objPerf = CreateObject( "ActiveXperts.NMPerf" )
' Initialze Performance object. Optional parameter: a log file, for debugging purposes
objPerf.Initialize( "" )
If( objPerf.LastError <> 0 ) Then
CheckPerformanceCounter = retvalUnknown
SYSDATA = ""
SYSEXPLANATION = "Failed to initialize Performance object."
Exit Function
End If
' If alternate credentials are specified, retrieve the alternate login and password from the ActiveXperts global settings
If( strAltCredentials <> "" ) Then
If( Not getCredentials( strHost, strAltCredentials, strAltLogin, strAltPassword, SYSEXPLANATION )) Then
Exit Function
End If
End If
' Connect. If strAltUserName is empty, the service credentials will be used
objPerf.Connect strHost, strAltUserName, strAltPassword
If( objPerf.LastError <> 0 ) Then
CheckPerformanceCounter = retvalUnknown
SYSDATA = ""
SYSEXPLANATION = "Failed to connect."
Exit Function
End If
' Build the Peformance path
strPath = objPerf.BuildPath( strHost, strPerfObject, strPerfContext, strPerfItem )
' Get integer value. If floating point is expected, use GetDoubleValue instead
numValue = objPerf.GetIntegerValue( strPath )
If( objPerf.LastError <> 0 ) Then
CheckPerformanceCounter = False
SYSDATA = ""
SYSEXPLANATION = "Failed to retrieve value for counter [" & strPath & "]"
Exit Function
End If
strEval = numValue & " " & strOperator & " " & numLimit
bCompareResult = Eval( strEval )
CheckPerformanceCounter = bCompareResult
SYSEXPLANATION = "Path [" & strPath & "], Current Value=[" & numValue & "], Limit=[" & numLimit & "]"
' Disconnect
objPerf.Disconnect()
' Uninitialize
objPerf.Shutdown()
End Function
' //////////////////////////////////////////////////////////////////////////////
Function getCredentials( strHost, strAltCredentials, BYREF strAltLogin, BYREF strAltPassword, BYREF strSysExplanation )
Dim objNMServerCredentials
strAltLogin = ""
strAltPassword = ""
strSysExplanation = ""
getCredentials = False
If( strAltCredentials = "" ) Then
' No alternate credentials specified, so login and password are empty and service credentials will be used
getCredentials = True
Exit Function
End If
Set objNMServerCredentials = CreateObject( "ActiveXperts.NMServerCredentials" )
strAltLogin = objNMServerCredentials.GetLogin( strAltCredentials )
strAltPassword = objNMServerCredentials.GetPassword( strAltCredentials )
If( strAltLogin = "" ) Then
getCredentials = False
strSysExplanation = "No alternate credentials defined for [" & strAltCredentials & "]. In the Manager application, select 'Options' from the 'Tools' menu and select the 'Server Credentials' tab to enter alternate credentials"
Exit Function
End If
getCredentials = True
End Function
