Monitor for Build WebService

TeamFoundationServer2008.MonitorforBuildWebService (UnitMonitor)

Monitor for Build WebService

Knowledge Base article:

Summary

Monitor for Build WebService

Element properties:

TargetTeamFoundationServer2008.TFSBuildWebService
Parent MonitorSystem.Health.AvailabilityState
CategoryAvailabilityHealth
EnabledTrue
Alert GenerateTrue
Alert SeverityError
Alert PriorityNormal
Alert Auto ResolveTrue
Monitor TypeMicrosoft.Windows.TimedScript.TwoStateMonitorType
RemotableTrue
AccessibilityInternal
Alert Message
Monitor for Build WebService
The Build Web Service is not responding properly
RunAsTFSUserProfile

Source Code:

<UnitMonitor ID="TeamFoundationServer2008.MonitorforBuildWebService" Accessibility="Internal" Enabled="onEssentialMonitoring" Target="TeamFoundationServer2008.TFSBuildWebService" ParentMonitorID="Health!System.Health.AvailabilityState" Remotable="true" Priority="Normal" RunAs="TFSUserProfile" TypeID="Windows!Microsoft.Windows.TimedScript.TwoStateMonitorType" ConfirmDelivery="false">
<Category>AvailabilityHealth</Category>
<AlertSettings AlertMessage="TeamFoundationServer2008.MonitorforBuildWebService_AlertMessageResourceID">
<AlertOnState>Warning</AlertOnState>
<AutoResolve>true</AutoResolve>
<AlertPriority>Normal</AlertPriority>
<AlertSeverity>Error</AlertSeverity>
</AlertSettings>
<OperationalStates>
<OperationalState ID="Success" MonitorTypeStateID="Success" HealthState="Success"/>
<OperationalState ID="Error" MonitorTypeStateID="Error" HealthState="Warning"/>
</OperationalStates>
<Configuration>
<IntervalSeconds>900</IntervalSeconds>
<SyncTime/>
<ScriptName>BuildService.vbs</ScriptName>
<Arguments/>
<ScriptBody><Script>'
Dim oAPI, oBag


Dim WebServiceURL, WebMethodName, xmlDOC2, soapStr, requestHTTP, serviceName, serviceUrl

WebServiceURL = GetTfsUrl() &amp; "/Build/V1.0/BuildStore.asmx"
Call TraceLogMessage("RE-CONSTRUCTED URL = ["&amp; WebServiceURL &amp; "]")

'========================================================================
' Now call the web methods
'========================================================================
' 1. Test the GetRegistrationEntries method
WebMethodName = "GetBuildQualities"
'=========================================================================
' main logic of SOAPClient
'=========================================================================
'Get the Properties of the DOM right
Set xmlDOC2 = CreateObject("MSXML.DOMDocument")
xmlDOC2.SetProperty "SelectionLanguage", "XPath"
XmlDOC2.Async = false
' Do a simple polling check on GetBuildQualities Web Service and check its return status.
'Call TraceLogMessage("Create SOAP Envelope")
' Create the soapEnvelope as a string body

soapStr = soapStr &amp; "&lt;?xml version=""1.0"" encoding=""utf-8""?&gt;" &amp; vbCrLf
soapStr = soapStr &amp; "&lt;soap:Envelope "
soapStr = soapStr &amp; " xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"""
soapStr = soapStr &amp; " xmlns:xsd=""http://www.w3.org/2001/XMLSchema"""
soapStr = soapStr &amp; " xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/""&gt;"
soapStr = soapStr &amp; vbCrLf
soapStr = soapStr &amp; " &lt;soap:Body&gt;" &amp; vbCrLf
soapStr = soapStr &amp; " &lt;GetBuildQualities xmlns=""http://schemas.microsoft.com/TeamFoundation/2005/06/Build/BuildInfo/03""/&gt; "
soapStr = soapStr &amp; vbCrLf
soapStr = soapStr &amp; " &lt;/soap:Body&gt;" &amp; vbCrLf
soapStr = soapStr &amp; " &lt;/soap:Envelope&gt;" &amp; vbCrLf
'Call TraceLogMessage("submitted SOAPSTRING:=&gt;" &amp; soapStr)

'Call TraceLogMessage("Set the RequestHTTP object and properties")

Set requestHTTP = CreateObject("Microsoft.XMLHTTP")
requestHTTP.open "POST", WebServiceURL, false
requestHTTP.setrequestheader "Content-Type", "text/xml"
requestHTTP.setrequestheader "SOAPAction", "http://schemas.microsoft.com/TeamFoundation/2005/06/Build/BuildInfo/03/GetBuildQualities"
requestHTTP.Send soapStr

'''''''DO the XML processing''''''''''''''''''
'========================================================================
' Load the respone.xml into DOM for XPATH processing
'========================================================================
bOK = xmlDOC2.load(requestHTTP.responseXML)
Set oAPI = CreateObject("MOM.ScriptAPI")
'Set oBag = oAPI.CreatePropertyBag()
Set oBag = oAPI.CreateTypedPropertyBag(3)
IF xmlDOC2.parseError.errorCode &lt;&gt; 0 Then
myError = xmlDOC2.parseError
Call TraceLogMessage("You have parse error on loading XmlDOC2" )
Call oBag.AddValue("Status","ERROR")
ELSE
IF requestHTTP.status = "200" THEN
Call oBag.AddValue("Status","OK")
'Call TraceLogMessage("Status: OK")
ELSE
Call oBag.AddValue("Status","ERROR")
'Call TraceLogMessage("Status: ERROR")
END IF
Call oAPI.AddItem(oBag)
Call oAPI.Return(oBag)


END IF

'''########## BEGIN FUNCTION : TraceLogMessage ############################################
Function TraceLogMessage(ByVal sMessage)
Dim lsEventInformation
WScript.Echo sMessage

' Retrieve the name of this (running) script
Dim FSO, ScriptFileName
Set FSO = CreateObject("Scripting.FileSystemObject")
ScriptFileName = FSO.GetFile(WScript.ScriptFullName).Name
Set FSO = Nothing

On Error Resume Next
Dim oAPITemp
Set oAPITemp = CreateObject("MOM.ScriptAPI")
lsEventInformation = 3
oAPITemp.LogScriptEvent ScriptFileName, 4000, lsEventInformation, sMessage
On Error Goto 0
End Function
'''########## END FUNCTION : TraceLogMessage ############################################

Function GetTfsInstallFolder()
Dim WSHShell, RegKey, sFolder

Set WSHShell = CreateObject("WScript.Shell")
RegKey = "HKLM\SOFTWARE\Microsoft\VisualStudio\9.0\TeamFoundation\ATInstallPath"
sFolder = WSHShell.RegRead(RegKey)

GetTfsInstallFolder = sFolder
End Function

Function GetTfsUrl()
Dim sTfsWebConfigFile, xmlWebConfig, nodeTfsUrl, bConfigFileLoaded

sTfsWebConfigFile= GetTfsInstallFolder() &amp; "Web Services\Web.Config"

Set xmlWebConfig = CreateObject("MSXML.DOMDocument")
xmlWebConfig.SetProperty "SelectionLanguage", "XPath"
xmlWebConfig.Async = false
bConfigFileLoaded = xmlWebConfig.load(sTfsWebConfigFile)
If bConfigFileLoaded = False Then
Exit Function
End If

Set nodeTfsUrl = xmlWebConfig.selectSingleNode("//add[@key = 'TFSNameUrl']/@value")
If nodeTfsUrl Is Nothing Then
Exit Function
End If
GetTfsUrl = nodeTfsUrl.Value
End Function
</Script></ScriptBody>
<TimeoutSeconds>360</TimeoutSeconds>
<ErrorExpression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="String">Property[@Name='Status']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="String">ERROR</Value>
</ValueExpression>
</SimpleExpression>
</ErrorExpression>
<SuccessExpression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="String">Property[@Name='Status']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="String">OK</Value>
</ValueExpression>
</SimpleExpression>
</SuccessExpression>
</Configuration>
</UnitMonitor>