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
Err.Clear
Wscritp.Quit(3)
Else
HttpRequest.open "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
Err.Clear
Wscritp.Quit(2)
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"
Wscript.Quit(2)
Set HttpRequest = Nothing
Else
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"
Wscript.Quit(0)
Set HttpRequest = Nothing
Set myRegExp = Nothing
Else
Wscript.Echo "CRITICAL: match not found, though the URL is accessable|seconds=" & timex & "s;0;60"
Wscript.Quit(2)
Set HttpRequest = Nothing
Set myRegExp = Nothing
End If
End If
End If
Else
Wscript.Echo "Help:"
Wscript.Echo "-u http://google.com"
Wscript.Echo "-m match-pattern"
Wscript.Echo "-l username"
Wscript.Echo "-p password"
Wscript.Echo ""
Wscript.Echo "UNKNOWN: Syntax error"
Wscript.Quit(3)
End If
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
Err.Clear
Wscritp.Quit(3)
Else
HttpRequest.open "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
Err.Clear
Wscritp.Quit(2)
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"
Wscript.Quit(2)
Set HttpRequest = Nothing
Else
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"
Wscript.Quit(0)
Set HttpRequest = Nothing
Set myRegExp = Nothing
Else
Wscript.Echo "CRITICAL: match not found, though the URL is accessable|seconds=" & timex & "s;0;60"
Wscript.Quit(2)
Set HttpRequest = Nothing
Set myRegExp = Nothing
End If
End If
End If
Else
Wscript.Echo "Help:"
Wscript.Echo "-u http://google.com"
Wscript.Echo "-m match-pattern"
Wscript.Echo "-l username"
Wscript.Echo "-p password"
Wscript.Echo ""
Wscript.Echo "UNKNOWN: Syntax error"
Wscript.Quit(3)
End If
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 ""
ReplyDelete