Wednesday, February 11, 2015

Web Page Availability using VbScript via "MSXML2.ServerXMLHTTP" ntlm authentication

On Error Resume Next
aurl = Wscript.Arguments.Item(0)
url = Wscript.Arguments.Item(1)
apattern = Wscript.Arguments.Item(2)
pattern = Wscript.Arguments.Item(3)
ausername = Wscript.Arguments.Item(4)
username = Wscript.Arguments.Item(5)
apassword = Wscript.Arguments.Item(6)
password = Wscript.Arguments.Item(7)
If aurl = "-u" and apattern = "-m" and ausername = "-l" and apassword = "-p" Then
time1 = now()
'Wscript.Echo time1
Set HttpRequest = CreateObject("MSXML2.ServerXMLHTTP")
If Err.Number <> 0 Then
Wscript.Echo "UNKNOWN: Unhanlded Exception." &  Err.Description
Else "POST", url, FALSE, username, password
HttpRequest.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
HttpRequest.send ""
If Err.Number <> 0 Then
Wscript.Echo "UNKNOWN: Unhanlded Exception check the URL and the account." &  Err.Description
End If
time2 = now()
'Wscript.Echo time2
timex = DateDiff("s",time1,time2)
'Wscript.Echo HttpRequest.status
'Wscript.Echo HttpRequest.responseText
'Wscript.Echo timex
 If ( HttpRequest.status <> 200 ) then
 Wscript.Echo "CRITICAL: Error code:" & HttpRequest.status & "|seconds=" & timex & "s;0;60"
 Set HttpRequest = Nothing
    Set myRegExp = New RegExp
    myRegExp.IgnoreCase = True
    myRegExp.Global = True
    myRegExp.Pattern = pattern
   'Wscript.Echo "errorPattern:" & errorPattern
   ' Echo for each match
    Set myMatches = myRegExp.Execute(HttpRequest.responseText)

    If myMatches.count > 0 Then
 Wscript.Echo "OK: match found and URL is accessable|seconds=" & timex & "s;0;60"
 Set HttpRequest = Nothing
    Set myRegExp = Nothing
 Wscript.Echo "CRITICAL: match not found, though the URL is accessable|seconds=" & timex & "s;0;60"
    Set HttpRequest = Nothing
    Set myRegExp = Nothing
 End If

 End If
End If
Wscript.Echo "Help:"
Wscript.Echo "-u"
Wscript.Echo "-m match-pattern"
Wscript.Echo "-l username"
Wscript.Echo "-p password"
Wscript.Echo ""
Wscript.Echo "UNKNOWN: Syntax error"
End If

1 comment:

  1. the above script is capable of authentication using ntlm and if you don't want to do any pattern match just pass an empty string as -m ""