xen.vbs - vbscript script by ActiveXperts Software
xen.vbs checks a counter on a Xen server or a Virtual Maching running on a Xen server.
Use xen.vbs directly from ActiveXperts Network Monitor; in the Manager's 'Monitor' menu, select 'New Check (Script)' and select xen.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.
xen.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
Dim objConstants
' Constants - return values
Const retvalUnknown = 1 ' ActiveXperts Network Monitor functions should always return True (-1, Success), False (0, Error) or retvalUnknown (1, Uncertain)
Set objConstants = CreateObject( "AxNetwork.NwConstants" )
' // 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 = Check_CPU_Usage_Percent( "esx01", "", "<90" )
' WScript.Echo "Return value: [" & bResult & "]"
' WScript.Echo "SYSDATA: [" & SYSDATA & "]"
' WScript.Echo "SYSEXPLANATION: [" & SYSEXPLANATION & "]"
Function Check_CPU_Usage_Percent( strHost, strVM, strCondition )
' Description:
' Checks CPU usage on a Xen host or virtual machine.
' Parameters:
' 1) strHost As String - Hostname or IP address of the ESXi Xen Server
' 2) strVM As String - The Virtual Machine you want to monitor; use empty string to monitor the Xen host
' 3) strCondition As String - The condition, formatted as the operator (<, >, <>, =, <=, >=) followed by a number, e.g.: "< 95"
' Usage:
' Check_CPU_Usage_Percent( "<Hostname | IP>", "<VM>", "<Condition>" )
' Sample:
' Check_CPU_Usage_Percent( "esx01", "", "<90" )
Check_CPU_Usage_Percent = checkXen( strHost, strVM, objConstants.nmXEN_CPU_USAGE, "", strCondition )
End Function
' //////////////////////////////////////////////////////////////////////////////
Function Check_Memory_Usage_Percent( strHost, strVM, strCondition )
' Description:
' Checks Memory usage on a Xen host or virtual machine.
' Parameters:
' 1) strHost As String - Hostname or IP address of the ESXi Xen Server
' 2) strVM As String - The Virtual Machine you want to monitor; use empty string to monitor the Xen host
' 3) strCondition As String - The condition, formatted as the operator (<, >, <>, =, <=, >=) followed by a number, e.g.: "< 95"
' Usage:
' Check_Memory_Usage_Percent( "<Hostname | IP>", "<VM>", "<Condition>" )
' Sample:
' Check_Memory_Usage_Percent( "esx01", "", "<90" )
Check_Memory_Usage_Percent = checkXen( strHost, strVM, objConstants.nmXEN_MEMORY_USAGE, "", strCondition )
End Function
' //////////////////////////////////////////////////////////////////////////////
Function Check_Memory_Available_MB( strHost, strVM, strCondition )
' Description:
' Checks Memory Availabe in MB on a Xen host or virtual machine.
' Parameters:
' 1) strHost As String - Hostname or IP address of the ESXi Xen Server
' 2) strVM As String - The Virtual Machine you want to monitor; use empty string to monitor the Xen host
' 3) strCondition As String - The condition, formatted as the operator (<, >, <>, =, <=, >=) followed by a number, e.g.: "< 95"
' Usage:
' Check_Memory_Available_MB( "<Hostname | IP>", "<VM>", "<Condition>" )
' Sample:
' Check_Memory_Available_MB( "esx01", "", ">200" )
Check_Memory_Available_MB = checkXen( strHost, strVM, objConstants.nmXEN_MEMORY_AVAILABLE, "", strCondition )
End Function
' //////////////////////////////////////////////////////////////////////////////
Function Check_Memory_Used_MB( strHost, strVM, strCondition )
' Description:
' Checks Memory Used in MB on a Xen host or virtual machine.
' Parameters:
' 1) strHost As String - Hostname or IP address of the ESXi Xen Server
' 2) strVM As String - The Virtual Machine you want to monitor; use empty string to monitor the Xen host
' 3) strCondition As String - The condition, formatted as the operator (<, >, <>, =, <=, >=) followed by a number, e.g.: "<2000"
' Usage:
' Check_Memory_Usage_Percent( "<Hostname | IP>", "<VM>", "<Condition>" )
' Sample:
' Check_Memory_Usage_Percent( "esx01", "", "<20000" )
Check_Memory_Used_MB = checkXen( strHost, strVM, objConstants.nmXEN_MEMORY_USED, "", strCondition)
End Function
' //////////////////////////////////////////////////////////////////////////////
Function Check_Network_Packets_Received_Per_Second( strHost, strVM, strContext, strCondition )
' Description:
' Checks Network Packets Received Per Second on a Xen host or virtual machine.
' Parameters:
' 1) strHost As String - Hostname or IP address of the ESXi Xen Server
' 2) strVM As String - The Virtual Machine you want to monitor; use empty string to monitor the Xen host
' 3) strContext as String - The context of the counter, indicating the NIC card (zero-based index, as a string), e.g.: "0", or "1", etc.
' 4) strCondition As String - The condition, formatted as the operator (<, >, <>, =, <=, >=) followed by a number, e.g.: "<100000"
' Usage:
' Check_Network_Packets_Received_Per_Second( "<Hostname | IP>", "<VM>", "<Context>", "<Condition>" )
' Sample:
' Check_Network_Packets_Received_Per_Second( "esx01", "", "0", "<100000" )
Check_Network_Packets_Received_Per_Second = checkXen( strHost, strVM, objConstants.nmXEN_NETWORK_PACKETSRX, strContext, strCondition )
End Function
' //////////////////////////////////////////////////////////////////////////////
Function Check_Network_Packets_Transmitted_Per_Second( strHost, strVM, strContext, strCondition )
' Description:
' Checks Network Packets Transmitted Per Second on a Xen host or virtual machine.
' Parameters:
' 1) strHost As String - Hostname or IP address of the ESXi Xen Server
' 2) strVM As String - The Virtual Machine you want to monitor; use empty string to monitor the Xen host
' 3) strContext as String - The context of the counter, indicating the NIC card (zero-based index, as a string), e.g.: "0", or "1", etc.
' 4) strCondition As String - The condition, formatted as the operator (<, >, <>, =, <=, >=) followed by a number, e.g.: "< 95"
' Usage:
' Check_Network_Packets_Transmitted_Per_Second( "<Hostname | IP>", "<VM>", "<Context>", "<Condition>" )
' Sample:
' Check_Network_Packets_Transmitted_Per_Second( "esx01", "", "0", "<100000" )
Check_Network_Packets_Transmitted_Per_Second = checkXen( strHost, strVM, objConstants.nmXEN_NETWORK_PACKETSTX, strContext, strCondition )
End Function
' //////////////////////////////////////////////////////////////////////////////
Function Check_Network_Receiving_Rate_KBS(strHost, strVM, strContext, strCondition )
' Description:
' Checks Network Receiving Rate in KB per Second on a Xen host or virtual machine.
' Parameters:
' 1) strHost As String - Hostname or IP address of the ESXi Xen Server
' 2) strVM As String - The Virtual Machine you want to monitor; use empty string to monitor the Xen host
' 3) strContext as String - The context of the counter, indicating the NIC card (zero-based index, as a string), e.g.: "0", or "1", etc.
' 4) strCondition As String - The condition, formatted as the operator (<, >, <>, =, <=, >=) followed by a number, e.g.: "< 95"
' Usage:
' Check_Network_Receiving_Rate_KBS( "<Hostname | IP>", "<VM>", "<Context>", "<Condition>" )
' Sample:
' Check_Network_Receiving_Rate_KBS( "esx01", "", "0", "<250" )
Check_Network_Receiving_Rate_KBS = checkXen( strHost, strVM, objConstants.nmXEN_NETWORK_RATERX, strContext, strCondition )
End Function
' //////////////////////////////////////////////////////////////////////////////
Function Check_Network_Transmitting_Rate_KBS( strHost, strVM, strContext, strCondition )
' Description:
' Checks Network Transmitting Rate in KB per Second on a Xen host or virtual machine.
' Parameters:
' 1) strHost As String - Hostname or IP address of the ESXi Xen Server
' 2) strVM As String - The Virtual Machine you want to monitor; use empty string to monitor the Xen host
' 3) strContext as String - The context of the counter, indicating the NIC card (zero-based index, as a string), e.g.: "0", or "1", etc.
' 4) strCondition As String - The condition, formatted as the operator (<, >, <>, =, <=, >=) followed by a number, e.g.: "< 95"
' Usage:
' Check_Network_Transmitting_Rate_KBS( "<Hostname | IP>", "<VM>", "<Context>", "<Condition>" )
' Sample:
' Check_Network_Transmitting_Rate_KBS( "esx01", "", "0", "<250" )
Check_Network_Transmitting_Rate_KBS = checkXen( strHost, strVM, objConstants.nmXEN_NETWORK_RATETX, strContext, strCondition )
End Function
' //////////////////////////////////////////////////////////////////////////////
Function Check_Disk_Usage_Percent( strHost, strVM, strContext, strCondition )
' Description:
' Checks Disk Usage in Percentage on a Xen host or virtual machine.
' Parameters:
' 1) strHost As String - Hostname or IP address of the ESXi Xen Server
' 2) strVM As String - The Virtual Machine you want to monitor; use empty string to monitor the Xen host
' 3) strContext as String - The context of the counter, indicating the Disk (zero-based index, as a string), e.g.: "0", or "1", etc.
' 4) strCondition As String - The condition, formatted as the operator (<, >, <>, =, <=, >=) followed by a number, e.g.: "< 95"
' Usage:
' Check_Disk_Usage_Percent( "<Hostname | IP>", "<VM>", "<Context>", "<Condition>" )
' Sample:
' Check_Disk_Usage_Percent( "esx01", "", "0", "<95" )
Check_Disk_Usage_Percent = checkXen( strHost, strVM, objConstants.nmXEN_DISK_USAGE, strContext, strCondition )
End Function
' //////////////////////////////////////////////////////////////////////////////
Function Check_Disk_Space_Available_MB(strHost, strVM, strContext, strCondition )
' Description:
' Checks Disk Space Available in MB on a Xen host or virtual machine.
' Parameters:
' 1) strHost As String - Hostname or IP address of the ESXi Xen Server
' 2) strVM As String - The Virtual Machine you want to monitor; use empty string to monitor the Xen host
' 3) strContext as String - The context of the counter, indicating the Disk (zero-based index, as a string), e.g.: "0", or "1", etc.
' 4) strCondition As String - The condition, formatted as the operator (<, >, <>, =, <=, >=) followed by a number, e.g.: "< 95"
' Usage:
' Check_Disk_Space_Available_MB( "<Hostname | IP>", "<VM>", "<Context>", "<Condition>" )
' Sample:
' Check_Disk_Space_Available_MB( "esx01", "", "0", ">10000" )
Check_Disk_Space_Available_MB = checkXen( strHost, strVM, objConstants.nmXEN_DISK_AVAILABLE, strContext, strCondition )
End function
' //////////////////////////////////////////////////////////////////////////////
Function Check_Disk_Space_Used_MB( strHost, strVM, strContext, strCondition )
' Description:
' Checks Disk Space Used in MB on a Xen host or virtual machine.
' Parameters:
' 1) strHost As String - Hostname or IP address of the ESXi Xen Server
' 2) strVM As String - The Virtual Machine you want to monitor; use empty string to monitor the Xen host
' 3) strContext as String - The context of the counter, indicating the Disk (zero-based index, as a string), e.g.: "0", or "1", etc.
' 4) strCondition As String - The condition, formatted as the operator (<, >, <>, =, <=, >=) followed by a number, e.g.: "< 95"
' Usage:
' Check_Disk_Space_Used_MB( "<Hostname | IP>", "<VM>", "<Context>", "<Condition>" )
' Sample:
' Check_Disk_Space_Used_MB( "esx01", "", "0", "<500000" )
Check_Disk_Space_Used_MB = checkXen( strHost, strVM, objConstants.nmXEN_DISK_USED, strContext, strCondition )
End Function
' //////////////////////////////////////////////////////////////////////////////
Function Check_VM_Powered_ON( strHost, strVM, strCondition )
' Description:
' Checks if VirtualMachine is PoweredON.
' This check only works on a Virtual Machine, not on the Host
' Use one of the following integers in the nValue parameter:
' 0: Off; 1: On; 2: Suspended
' Parameters:
' 1) strHost As String - Hostname or IP address of the ESXi Xen Server
' 2) strVM As String - The Virtual Machine you want to monitor; use empty string to monitor the Xen host
' 3) strCondition As String - The condition, formatted as the operator (<, >, <>, =, <=, >=) followed by a number, e.g.: "=1"
' Usage:
' Check_VM_Powered_ON( "<Hostname | IP>", "<VM>", "<Condition>" )
' Sample:
' Check_VM_Powered_ON( "esx01", "dell15", "=1" )
Check_VM_Powered_ON = checkXen( strHost, strVM, objConstants.nmXEN_MACHINE_STATE, "", strCondition )
End Function
' //////////////////////////////////////////////////////////////////////////////
Function Check_VM_Running( strHost, strVM, strCondition )
' Description:
' Checks if VirtualMachine is Running.
' This check only works on a Virtual Machine, not on the Host
' Use one of the following integers in the nValue parameter:
' 0: Not Running; 1: Resetting; 2: Running; 3: Shutting Down; 4: Standby; 5: Unknown
' Parameters:
' 1) strHost As String - Hostname or IP address of the ESXi Xen Server
' 2) strVM As String - The Virtual Machine you want to monitor
' 3) strCondition As String - The condition, formatted as the operator (<, >, <>, =, <=, >=) followed by a number, e.g.: "=1"
' Usage:
' Check_VM_Running( "<Hostname | IP>", "<VM>", "<Condition>" )
' Sample:
' Check_VM_Running( "esx01", "dell15", "=1" )
Check_VM_Running = checkXen( strHost, strVM, objConstants.nmXEN_POWER_STATE, "", strCondition )
End Function
' //////////////////////////////////////////////////////////////////////////////
Function Check_VM_Guest_Tools_Installed(strHost, strVM, strCondition )
' Description:
' Checks if Quest Tools are Installed/Running is Running.
' This check only works on a Virtual Machine, not on the Host
' Use one of the following integers in the nValue parameter:
' 0: Not Running
' 1: Running
' Parameters:
' 1) strHost As String - Hostname or IP address of the ESXi Xen Server
' 2) strVM As String - The Virtual Machine you want to monitor
' 3) strCondition As String - The condition, formatted as the operator (<, >, <>, =, <=, >=) followed by a number, e.g.: "=1"
' Usage:
' Check_VM_Guest_Tools_Installed( "<Hostname | IP>", "<VM>", "<Condition>" )
' Sample:
' Check_VM_Guest_Tools_Installed( "esx01", "dell15", "=1" )
Check_VM_Guest_Tools_Installed = checkXen( strHost, strVM, objConstants.nmXEN_GUESTTOOLS, "", strCondition )
End Function
' //////////////////////////////////////////////////////////////////////////////
' // --- Private Functions section ---
' // Private functions names should start with a lower case character, so they
' // will not be listed in the Network Monitor's function browser.
' //////////////////////////////////////////////////////////////////////////////
Function checkXen(strHost, strVM, nCounterID, strContext, strCondition )
Dim objXen, objServerCredentials, nCurrValue, strEval, strResultKeywork
checkXen = retvalUnknown
SYSDATA = ""
SYSEXPLANATION = ""
Set objXen = CreateObject( "AxNetwork.Xen" )
Set objServerCredentials = CreateObject( "ActiveXperts.NMXenCredentials" )
objXen.Server = strHost
objXen.ServerAccount = objServerCredentials.GetLogin( strHost )
objXen.ServerPassword = objServerCredentials.GetPassword( strHost )
' Get Credentials of Xen Server
If( objXen.ServerAccount = "" ) Then
SYSEXPLANATION = "No Xen credentials defined for [" & strHost & "]. In the Manager application, create a 'new Monitoring Check', Pick the 'Xen ESXi' check and add the credentials."
Exit Function
End If
' Initialize Xen object
objXen.Initialize
If( objXen.LastError <> 0 ) Then
SYSEXPLANATION = "Xen Initialize failed, error [" & objXen.LastError & "]: " & objXen.GetErrorDescription( objXen.LastError )
Exit Function
End If
' Connect to Xen Server
objXen.Connect
If ( objXen.LastError <> 0 ) Then
SYSEXPLANATION = "Xen Connect failed, error [" & objXen.LastError & "]: " & objXen.GetErrorDescription( objXen.LastError )
objXen.Disconnect
objXen.Shutdown
Exit Function
End If
' Get counter value
nCurrValue = objXen.GetPerfData( strVM, nCounterID, strContext )
If ( objXen.LastError <> 0 ) Then
SYSEXPLANATION = "Xen GetPerfData failed, error [" & objXen.LastError & "]: " & objXen.GetErrorDescription( objXen.LastError )
objXen.Disconnect
objXen.Shutdown
Exit Function
End If
strEval = nCurrValue & strCondition
If( Not Eval( strEval ) ) Then
checkXen = False
strResultKeywork = "failed"
Else
checkXen = True
strResultKeywork = "OK"
End If
SYSDATA = nCurrValue
SYSEXPLANATION = "Counter [" & objXen.GetCounterDescription( nCounterID ) & "], Condition [" & strCondition & "] " & strResultKeywork & ", Current Value=[" & nCurrValue & "]"
objXen.Disconnect
objXen.Shutdown
End Function
