Sub ReturnSystemBag(ByRef oApi, ByVal status, ByVal message)
' Create SCOM property bag
Dim oBag
Set oBag = oApi.CreatePropertyBag()
' Set Status property
If status = STATUS_OK Then
WScript.Echo "Info: Status: OK" & ", Message: " & message
oBag.AddValue "Status", "OK"
Else
WScript.Echo "Info: Status: ERROR" & ", Message: " & message
oBag.AddValue "Status", "ERROR"
End If
oBag.AddValue "Info", message
' Return bag
Call oApi.Return(oBag)
End Sub
WScript.Echo "Info: Initializing..."
' Get SCOM API object
Dim oApi
Set oApi = CreateObject("MOM.ScriptAPI")
' Validate arguments
Dim oArgs
Set oArgs = WScript.Arguments
If Not oArgs.Count = 1 Then
On Error Goto 0
Err.Raise 8, _
"VMware.View.ConnectionServerRole.v0405.VcConnectivityCheck.vbs", _
"Wrong number of arguments"
End If
Dim netbiosComputerName
netbiosComputerName = oArgs(0)
' Status of Monitor
Dim message
Dim status
status = STATUS_OK
' Create mfw channel
Dim oChannel
Set oChannel = CreateObject("VMware.MfwSimpleChannel")
' Create request property bag
Dim oReqIDsBag
Set oReqIDsBag = CreateObject("VMware.MfwPropertyBag")
' Get monitor IDs
oReqIDsBag.add "monitor", "VcMonitor"
On Error Resume Next
Dim oRespIDsBag
Set oRespIDsBag = oChannel.SendMsg("JAdmin", _
"getMonitorIds", _
oReqIDsBag)
Dim errNum
errNum = Err.Number
On Error Goto 0
If errNum <> 0 Then
If errNum = &H80070001 Then
WScript.Echo "Info: Could not open a channel to broker"
ReturnSystemBag oApi, STATUS_ERROR, "Could not open a channel to broker"
WScript.Quit(0)
ElseIf errNum = &H80070003 Then
WScript.Echo "Info: JAdmin queue not present"
ReturnSystemBag oApi, STATUS_ERROR, "JAdmin queue not present"
WScript.Quit(0)
Else
Err.Raise errNum, _
"VMware.View.ConnectionServerRole.v0405.DomainConnectivityCheck.vbs", _
""
End If
End If
' Get each monitor instance
Dim idx
For idx = 0 to oRespIDsBag.Size() - 1
Dim propName
propName = oRespIDsBag.GetName(idx)
If LCase(propName) = "id" Then
Dim instanceID
instanceID = oRespIDsBag.GetIndex(idx)
If Len(instanceID) > 0 Then
' Create request property bag
Dim oReqInstBag
Set oReqInstBag = CreateObject("VMware.MfwPropertyBag")
' Get monitor info
Dim oRespInstBag
Set oRespInstBag = oChannel.SendMsg("JAdmin", _
"getMonitorInstance", _
oReqInstBag)
If oRespInstBag.isBag("monitorBag") = False Then
On Error Goto 0
Err.Raise 9, _
"VMware.View.ConnectionServerRole.v0405.VcConnectivityCheck.vbs", _
"Unexpected response. Cannot find monitorBag"
End If
Dim oMonitorBag
Set oMonitorBag = oRespInstBag.GetBag("monitorBag")
Dim monitorBagIdx
For monitorBagIdx = 0 to oMonitorBag.Size() - 1
If LCase(oMonitorBag.GetName(monitorBagIdx)) = "brokerentry" Then
Dim oBrokerBag
Set oBrokerBag = oMonitorBag.GetBagIndex(monitorBagIdx)
Dim brokerName
brokerName = oBrokerBag.Get("brokerNetbiosName", "")
If UCase(brokerName) = UCase(netbiosComputerName) Then
Dim brokerStatus
brokerStatus = oBrokerBag.get("status", "")
If Not UCase(brokerStatus) = "STATUS_UP" Then
status = STATUS_ERROR
If Len(message) > 0 Then
message = message & ", " & oMonitorBag.get("URL", "Unknown")
Else
message = oMonitorBag.get("URL", "Unknown")
End If
End If
End If
End If
Next
End If
End If
Next
WScript.Echo "Info: Status: " & status & ", Message: " & message
WScript.Echo ""