Page 1 of 1

why not show warning or critical when output is not ok

Posted: Wed Aug 30, 2017 10:16 am
by baber
dear all
Hi

i have a vbs script that can check a url is opening or not

Code: Select all

url = "http://estelamwebservice.nocrservices.org/iws/Estelam?wsdl"
Set http = CreateObject("MSXML2.ServerXMLHTTP")
http.open "GET",url,false
http.send
If http.Status = 200 Then
  wscript.echo "HTTP OK - " & url & " returns " & http.Status
  exitCode = 0
ElseIf http.Status > 400 And http.Status < 500 Then
  wscript.echo "HTTP WARNING - " & url & " returns " & http.Status
  exitCode = 1
Else
  wscript.echo "HTTP CRITICAL - " & url & " returns " & http.Status
  exitCode = 2
End If

WScript.Quit(exitCode)
and put this in nsclient.ini

[/settings/external scripts/scripts]
check_url = cscript.exe //T:30 //NoLogo scripts\\url.vbs $ARG1$
check_myurl = cscript.exe //T:30 //NoLogo scripts\\url.vbs

when web site can open it will ok on nagios

but when i change url for example change to

ttt.com

C:Program FilesNSClient++scriptsurl.vbs(4, 1) msxml3.dll: The server name or address could not be resolved

and not change to warning or critical it show ok with above decription

why it don't show warning or critical ?
BR

Re: why not show warning or critical when output is not ok

Posted: Wed Aug 30, 2017 10:45 am
by bolson
Add the bold line to your script and run from the command line.

url = "http://ttt.com"
Set http = CreateObject("MSXML2.ServerXMLHTTP")
http.open "GET",url,false
http.send
msgbox http.Status
If http.Status = 200 Then
wscript.echo "HTTP OK - " & url & " returns " & http.Status
exitCode = 0
ElseIf http.Status > 400 And http.Status < 500 Then
wscript.echo "HTTP WARNING - " & url & " returns " & http.Status
exitCode = 1
Else
wscript.echo "HTTP CRITICAL - " & url & " returns " & http.Status
exitCode = 2
End If

WScript.Quit(exitCode)

Re: why not show warning or critical when output is not ok

Posted: Wed Aug 30, 2017 2:04 pm
by baber
bolson wrote:Add the bold line to your script and run from the command line.

url = "http://ttt.com"
Set http = CreateObject("MSXML2.ServerXMLHTTP")
http.open "GET",url,false
http.send
msgbox http.Status
If http.Status = 200 Then
wscript.echo "HTTP OK - " & url & " returns " & http.Status
exitCode = 0
ElseIf http.Status > 400 And http.Status < 500 Then
wscript.echo "HTTP WARNING - " & url & " returns " & http.Status
exitCode = 1
Else
wscript.echo "HTTP CRITICAL - " & url & " returns " & http.Status
exitCode = 2
End If

WScript.Quit(exitCode)

i have used from below scirpt

Code: Select all

url = "http://estelamwebservice.nocrservices.org/iws/Estelam?wsdl"
Set http = CreateObject("MSXML2.ServerXMLHTTP")
http.open "GET",url,false
http.send
msgbox http.Status
If http.Status = 200 Then
  wscript.echo "HTTP OK - " & url & " returns " & http.Status
  exitCode = 0
ElseIf http.Status > 400 And http.Status < 500 Then
  wscript.echo "HTTP WARNING - " & url & " returns " & http.Status
  exitCode = 1
Else
  wscript.echo "HTTP CRITICAL - " & url & " returns " & http.Status
  exitCode = 3
End If

WScript.Quit(exitCode)
but when run cscript url.vbs on cmd not changed and output is :

C:Program FilesNSClient++scriptsurl.vbs(4, 1) msxml3.dll: The server name or address could not be resolved

and status is OK not change to warning or critical because that url (http://estelamwebservice.nocrservices.o ... telam?wsdl ) not open from this VM

what is my problem ??

Re: why not show warning or critical when output is not ok

Posted: Wed Aug 30, 2017 3:12 pm
by baber
please help me i am so confused

Re: why not show warning or critical when output is not ok

Posted: Wed Aug 30, 2017 3:15 pm
by bolson
Hello baber,

The problem has to do with how your script is written. The function

Code: Select all

http.open "GET",url,false
is failing so there never is an http.Status for your script to check.

Add the code I've added below in bold and let me know if it works as expected.

On Error Resume Next
url = "http://estelamwebservice.nocrservices.o ... telam?wsdl"
Set http = CreateObject("MSXML2.ServerXMLHTTP")
http.open "GET",url,false
http.send
msgbox http.Status
If http.Status = 200 Then
wscript.echo "HTTP OK - " & url & " returns " & http.Status
exitCode = 0
ElseIf http.Status > 400 And http.Status < 500 Then
wscript.echo "HTTP WARNING - " & url & " returns " & http.Status
exitCode = 1
Else
wscript.echo "HTTP CRITICAL - " & url & " returns " & "Error number " & err.Number & " " & err.Description
exitCode = 3
End If

WScript.Quit(exitCode)

Re: why not show warning or critical when output is not ok

Posted: Wed Aug 30, 2017 3:27 pm
by baber
bolson wrote:Hello baber,

The problem has to do with how your script is written. The function

Code: Select all

http.open "GET",url,false
is failing so there never is an http.Status for your script to check.

Add the code I've added below in bold and let me know if it works as expected.

On Error Resume Next
url = "http://estelamwebservice.nocrservices.o ... telam?wsdl"
Set http = CreateObject("MSXML2.ServerXMLHTTP")
http.open "GET",url,false
http.send
msgbox http.Status
If http.Status = 200 Then
wscript.echo "HTTP OK - " & url & " returns " & http.Status
exitCode = 0
ElseIf http.Status > 400 And http.Status < 500 Then
wscript.echo "HTTP WARNING - " & url & " returns " & http.Status
exitCode = 1
Else
wscript.echo "HTTP CRITICAL - " & url & " returns " & "Error number " & err.Number & " " & err.Description
exitCode = 3
End If

WScript.Quit(exitCode)
i use this script

Code: Select all

On Error Resume Next
url = "http://estelamwebservice.nocrservices.org/iws/Estelam?wsdl"
Set http = CreateObject("MSXML2.ServerXMLHTTP")
http.open "GET",url,false
http.send
msgbox http.Status
If http.Status = 200 Then
wscript.echo "HTTP OK - " & url & " returns " & http.Status
exitCode = 0
ElseIf http.Status > 400 And http.Status < 500 Then
wscript.echo "HTTP WARNING - " & url & " returns " & http.Status
exitCode = 1
Else
wscript.echo "HTTP CRITICAL - " & url & " returns " & "Error number " & err.Number & " " & err.Description
exitCode = 3
End If

WScript.Quit(exitCode)
but now when run in cmd nothing return

this is output

Code: Select all

C:\Program Files\NSClient++\scripts>cscript url.vbs
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.


C:\Program Files\NSClient++\scripts>

i find the script from this article can you help me please ???
script is working just problem is when it can not resolve a url don't show warning or critical but when resolve a url all of things are ok and show ok
for example for this server is ok

Code: Select all

HTTP OK - http://estelamwebservice.nocrservices.org/iws/Estelam?wsdl returns 200 

now please help me for solve the problem

Re: why not show warning or critical when output is not ok

Posted: Wed Aug 30, 2017 3:34 pm
by dwhitfield
We are not able to provide support for custom scripts. You may need to speak with someone in your organization that knows vbs.

However, we can leave this open for community input.

Re: why not show warning or critical when output is not ok

Posted: Wed Aug 30, 2017 10:10 pm
by baber
Can anyone help me ???

What is my problem ??

Re: why not show warning or critical when output is not ok

Posted: Thu Aug 31, 2017 1:16 pm
by bolson
**** EDIT ****

Try this... the problem is that your script only looks at http.status and in the case of an invalid URL, http.status is empty. Does that make sense?

Code: Select all

On Error resume next
din errdesc
url = "http://estelamwebservice.nocrservices.org/iws/Estelam?wsdl"
Set http = CreateObject("MSXML2.ServerXMLHTTP")
http.open "GET",url,false
http.send
errdesc=err.description

If http.Status = 200 Then
  wscript.echo "HTTP OK - " & url & " returns " & http.Status
  exitCode = 0
ElseIf http.Status > 400 And http.Status < 500 Then
  wscript.echo "HTTP WARNING - " & url & " returns " & http.Status
  exitCode = 1
  wscript.echo "HTTP CRITICAL - " & url & " returns " & http.Status
  exitCode = 2
End If


wscript.echo errdesc
exitCode = 2

WScript.Quit(exitCode)