Prueba del monitor de interfaces Web

Microsoft.SystemCenter.WebInterfaceWatcher.Probe (ProbeActionModuleType)

Compruebe el estado del sitio web al comprobar el código de respuesta http. En caso de error, se envía un contenedor de propiedades con un mensaje detallado sobre el error que se utilizará en el mensaje de alerta emitido por la prueba.

Element properties:

TypeProbeActionModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
OutputTypeSystem.PropertyBagData

Member Modules:

ID Module Type TypeId RunAs 
PassThrough ProbeAction System.PassThroughProbe Default
Script ProbeAction Microsoft.Windows.ScriptPropertyBagProbe Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
TimeoutSecondsint$Config/TimeoutSeconds$Tiempo de espera en segundos
DebugFlagbool$Config/DebugFlag$Depurar marca

Source Code:

<ProbeActionModuleType ID="Microsoft.SystemCenter.WebInterfaceWatcher.Probe" Accessibility="Internal" Batching="false" PassThrough="false">
<Configuration>
<xsd:element minOccurs="1" name="ComputerName" type="xsd:string"/>
<xsd:element minOccurs="1" name="UrlToCheck" type="xsd:string"/>
<xsd:element minOccurs="1" name="TimeoutSeconds" type="xsd:integer"/>
<xsd:element minOccurs="0" name="DebugFlag" type="xsd:boolean"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
<OverrideableParameter ID="DebugFlag" Selector="$Config/DebugFlag$" ParameterType="bool"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<ProbeAction ID="PassThrough" TypeID="System!System.PassThroughProbe"/>
<ProbeAction ID="Script" TypeID="Windows!Microsoft.Windows.ScriptPropertyBagProbe">
<ScriptName>Microsoft.SystemCenter.WebInterfaceWatcherMonitoring.vbs</ScriptName>
<Arguments>"$Config/ComputerName$" "$Config/UrlToCheck$" "$Config/DebugFlag$"</Arguments>
<ScriptBody><Script>
'Copyright (c) Microsoft Corporation. All rights reserved.

'*************************************************************************
' $ScriptName: "Microsoft.SystemCenter.WebInterfaceWatcherMonitoring" $
'
' Purpose: This script runs a url checks to validate if a website is up and running.
'
' $File: Microsoft.SystemCenter.WebInterfaceWatcherMonitoring.vbs $
'*************************************************************************

Option Explicit
SetLocale("en-us")

'Event Constants
Const EVENT_TYPE_SUCCESS = 0
Const EVENT_TYPE_ERROR = 1
Const EVENT_TYPE_WARNING = 2
Const EVENT_TYPE_INFORMATION = 4
'Other constants
Const SCRIPT_NAME = "Microsoft.SystemCenter.WebInterfaceWatcherMonitoring"
' Event ID Constants
Const EVENTID_SUCCESS = 99
Const EVENTID_SCRIPT_ERROR = 1000

Const APP_DISCOVERY_CONNECT_FAILURE = -1
Const APP_DISCOVERY_QUERY_FAILURE = -2
Const REGISTRY_CONNECT_FAILURE = -3
Const REGISTRY_READ_FAILURE = -4
Const HKEY_CLASSES_ROOT = &amp;H80000000
Const HKEY_CURRENT_USER = &amp;H80000001
Const HKEY_LOCAL_MACHINE = &amp;H80000002
Const HKEY_USERS = &amp;H80000003
Const HKEY_CURRENT_CONFIG = &amp;H80000005
Const StateDataType = 3
Const HTTPREQUEST_SETCREDENTIALS_FOR_SERVER = 0
Const HTTPREQUEST_SETCREDENTIALS_FOR_PROXY = 1
Const HTTPREQUEST_USERAGENTSTRING = "http_requester/0.1"
Const HTTPREQUEST_SSLERRORIGNOREFLAGS = 13056
Const HTTPREQUEST_ENABLEREDIRECTS = True
Const HTTPREQUEST_ENABLEHTTPSTOHTTPREDIRECT = True

Const WinHttpRequestOption_UserAgentString = 0
Const WinHttpRequestOption_URL = 1
Const WinHttpRequestOption_URLCodePage = 2
Const WinHttpRequestOption_EscapePercentInURL = 3
Const WinHttpRequestOption_SslErrorIgnoreFlags = 4
Const WinHttpRequestOption_SelectCertificate = 5
Const WinHttpRequestOption_EnableRedirects = 6
Const WinHttpRequestOption_UrlEscapeDisable = 7
Const WinHttpRequestOption_UrlEscapeDisableQuery = 8
Const WinHttpRequestOption_SecureProtocols = 9
Const WinHttpRequestOption_EnableTracing = 10
Const WinHttpRequestOption_RevertImpersonationOverSsl = 11
Const WinHttpRequestOption_EnableHttpsToHttpRedirects = 12
Const WinHttpRequestOption_EnablePassportAuthentication = 13
Const WinHttpRequestOption_MaxAutomaticRedirects = 14
Const WinHttpRequestOption_MaxResponseHeaderSize = 15
Const WinHttpRequestOption_MaxResponseDrainSize = 16
Const WinHttpRequestOption_EnableHttp1_1 = 17
Const WinHttpRequestOption_EnableCertificateRevocationCheck = 18

Const WinHttpTimeOut_ResolveTimeout = 5000
Const WinHttpTimeOut_ConnectTimeout = 10000
Const WinHttpTimeOut_SendTimeout = 10000
Const WinHttpTimeOut_ReceiveTimeout = 10000


Dim oAPI, oBagState
Dim oParams, bLogSuccessEvent
Dim strMonitorStatus, strErrorDetail, strMessage
Dim dtStart

Dim TargetServer, TargetSite, strStatus, intStatus, UserName, UserPassword
Dim objIIS, objWMIService, colItems, objItem
Dim strWebsite, strStatusText

dtStart = Now
Set oAPI = MomCreateObject("Mom.ScriptAPI")

Set oParams = WScript.Arguments
if oParams.Count &lt; 2 then
strMessage = "The script '" &amp; SCRIPT_NAME &amp; "' didn't execute successfully because some parameters were missing: Param Count(" &amp; CStr(oParams.Count) &amp; ")"
CreateEvent EVENTID_SUCCESS, EVENT_TYPE_INFORMATION, strMessage
Wscript.Quit -1
End if
strMonitorStatus = "0"

TargetServer = oParams(0)
TargetSite = oParams(1)
bLogSuccessEvent = CBool(oParams(2))

Set oBagState = oAPI.CreateTypedPropertyBag(StateDataType)
GetMonitorStatus

Sub GetMonitorStatus()
Dim e
Dim sWBState, ObjWebSite
Dim boolStatus

Set e = New Error
e.Clear
On Error Resume Next

boolStatus = PingSite(TargetSite)

If boolStatus = true Then
call ReturnResponse(false, "")
Else
strErrorDetail = SCRIPT_NAME &amp; ": - WebSite " &amp; TargetSite &amp; " Failure on Server " &amp; TargetServer &amp; " Error Detail: " &amp; strStatusText
call ReturnResponse(true, strErrorDetail)
End If

End Sub

'---------------------------------------------------------------------------
' Retrieves the script output.
'---------------------------------------------------------------------------
Sub ReturnResponse(boolErrorFlag, strMessage)
If boolErrorFlag = true Then
oBagState.AddValue "State", "0"
oBagState.AddValue "ErrorDetail", strMessage
Else
strMessage = "The script '" &amp; SCRIPT_NAME &amp; "' completed successfully in " &amp; _
DateDiff("s", dtStart, Now) &amp; " seconds."

oBagState.AddValue "State", "1"
oBagState.AddValue "ErrorDetail", ""
End If

If bLogSuccessEvent Then
CreateEvent EVENTID_SUCCESS, EVENT_TYPE_INFORMATION, strMessage
End If

oAPI.AddItem oBagState
Call oAPI.ReturnItems
WScript.Quit
End Sub


Sub CreateEvent(lEventID, lEventType, strMessage)
oAPI.LogScriptEvent SCRIPT_NAME,lEventID, lEventType, strMessage
End Sub

Function MomCreateObject(ByVal sProgramId)
Dim oError, strErrorMsg
Set oError = New Error

On Error Resume Next
Set MomCreateObject = CreateObject(sProgramId)
oError.Save
On Error Goto 0

If oError.Number &lt;&gt; 0 Then
strErrorMsg = "Unable to create automation object '" &amp; sProgramId &amp; "' " &amp; oError.Description
call ReturnResponse(true, strErrorMsg)
End If
End Function

Function PingSite( myWebsite )
Dim intStatus, objHTTP
Dim oError
Set oError = New Error
On Error Resume Next

Set objHTTP = MomCreateObject( "WinHttp.WinHttpRequest.5.1" )
objHTTP.Open "GET", myWebsite, False
objHTTP.SetRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MyApp 1.0; Windows NT 5.1)"
objHTTP.SetTimeouts WinHttpTimeOut_ResolveTimeout, WinHttpTimeOut_ConnectTimeout, WinHttpTimeOut_SendTimeout, WinHttpTimeOut_ReceiveTimeout
objHTTP.Option(WinHttpRequestOption_UserAgentString) = HTTPREQUEST_USERAGENTSTRING
objHTTP.Option(WinHttpRequestOption_SslErrorIgnoreFlags) = HTTPREQUEST_SSLERRORIGNOREFLAGS
objHTTP.Option(WinHttpRequestOption_EnableRedirects) = HTTPREQUEST_ENABLEREDIRECTS
objHTTP.Option(WinHttpRequestOption_EnableHttpsToHttpRedirects) = HTTPREQUEST_ENABLEHTTPSTOHTTPREDIRECT
objHTTP.Send

intStatus = objHTTP.Status

If bLogSuccessEvent Then
strMessage = "Return Status " &amp; CStr(intStatus)
CreateEvent EVENTID_SUCCESS, EVENT_TYPE_INFORMATION, strMessage
End If

On Error Goto 0

If oError.Number &lt;&gt; 0 Then
strMessage = "Error " &amp; CStr(oError.Number)
call ReturnResponse(true, strMessage)
End If

If intStatus = 200 Or intStatus = 401 Or intStatus = 403 Or intStatus = 407 Then
PingSite = True
Else
If IsEmpty(intStatus) = true Then
strStatusText = "IIS Down or unavailable"
else
strStatusText = objHTTP.StatusText
End If
PingSite = False
End If

Set objHTTP = Nothing
End Function

Class Error
Private m_lNumber
Private m_sSource
Private m_sDescription
Private m_sHelpContext
Private m_sHelpFile
Public Sub Save()
m_lNumber = Err.number
m_sSource = Err.Source
m_sDescription = Err.Description
m_sHelpContext = Err.HelpContext
m_sHelpFile = Err.helpfile
End Sub
Public Sub Raise()
Err.Raise m_lNumber, m_sSource, m_sDescription, m_sHelpFile, m_sHelpContext
End Sub
Public Sub Clear()
m_lNumber = 0
m_sSource = ""
m_sDescription = ""
m_sHelpContext = ""
m_sHelpFile = ""
End Sub
Public Default Property Get Number()
Number = m_lNumber
End Property
Public Property Get Source()
Source = m_sSource
End Property
Public Property Get Description()
Description = m_sDescription
End Property
Public Property Get HelpContext()
HelpContext = m_sHelpContext
End Property
Public Property Get HelpFile()
HelpFile = m_sHelpFile
End Property
End Class
</Script></ScriptBody>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</ProbeAction>
</MemberModules>
<Composition>
<Node ID="Script">
<Node ID="PassThrough"/>
</Node>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.PropertyBagData</OutputType>
<TriggerOnly>true</TriggerOnly>
</ProbeActionModuleType>