why not show warning or critical when output is not ok

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
baber
Posts: 295
Joined: Wed Oct 21, 2015 4:39 am

why not show warning or critical when output is not ok

Post 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
bolson

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

Post 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)
baber
Posts: 295
Joined: Wed Oct 21, 2015 4:39 am

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

Post 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 ??
baber
Posts: 295
Joined: Wed Oct 21, 2015 4:39 am

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

Post by baber »

please help me i am so confused
bolson

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

Post 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)
baber
Posts: 295
Joined: Wed Oct 21, 2015 4:39 am

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

Post 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
Last edited by baber on Wed Aug 30, 2017 3:36 pm, edited 1 time in total.
dwhitfield
Former Nagios Staff
Posts: 4583
Joined: Wed Sep 21, 2016 10:29 am
Location: NoLo, Minneapolis, MN
Contact:

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

Post 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.
baber
Posts: 295
Joined: Wed Oct 21, 2015 4:39 am

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

Post by baber »

Can anyone help me ???

What is my problem ??
bolson

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

Post 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)
Locked