Simple HTTP check monitoring plugin on Windows (check_http alternative)

Written by - 6 comments

Published on - Listed in Windows Monitoring Nagios Icinga


I was looking for a way to run a monitoring plugin, similar to check_http, on a Windows OS. The plugin itself would be executed through NRPE (using NSClient installation) and result the HTTP connectivity from the point of view of this Windows server.

I came across some scripts, including some tcp port checks (worth to mention: Protocol.vbs), some overblown power shell scripts and also a kind of check_tcp fork for Windows. Unfortunately none of them was really doing what I needed. So I built my own little vbscript put together with the information found on the following pages using the MSXML2.ServerXMLHTTP object :

So at the end the script looks like this:

url = "ENTER_FULL_URL_HERE"
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)

First define the URL in the first line (e.g. https://www.google.com) and then execute the script using cscript (without cscript you get the script's output as a dialog box):

C:\Users\Claudio\Documents>cscript check_http.vbs
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.

HTTP OK - https://www.google.com returns 200

Or hitting a page not found error:

C:\Users\Claudio\Documents>cscript check_http.vbs
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.

HTTP WARNING - https://www.google.com/this-should-not-exist returns 404

There's still much room to improve the script. It would be very nice to use "url" as an argument added in the command line. Maybe I get to that some time.

Finally in the nsclient.ini the script was defined to be called as nrpe command:

; External scripts
[/settings/external scripts]
allow arguments=true
allow nasty characters=true
[/settings/external scripts/scripts]
check_http_google=scripts\\check_http_google.vbs

Update August 31st 2017: The plugin is available on Github, too: https://github.com/Napsty/check_http_win. It now allows multiple arguments, including expected return codes and both GET and POST methods.


Add a comment

Show form to leave a comment

Comments (newest first)

ck from Switzerland wrote on Aug 31st, 2017:

Hi Babak. Use it this way:

cscript check_http_win.vbs GET "http://estelamwebservice.nocrservices.org/iws/Estelam?wsdl" "" ""


Babak from wrote on Aug 31st, 2017:

dear friend
thanks

but i am realy confused which script is ok ?
one script is on this page in your article and the other script is here : https://github.com/Napsty/check_http_win/blob/master/check_http_win.vbs

also i read the read me file but realy there is not anythind on that

can you help me please

BR


ck from Switzerland wrote on Aug 31st, 2017:

Please read the usage on https://github.com/Napsty/check_http_win. One argument is not enough for the new script.
But still: The DNS must be resolvable or it won't work with the new script either.


babak from wrote on Aug 31st, 2017:

dear friend
thanks

2 problem :

1 - with previous script when i run that it work correct but problem is for that when it could not open a url in description appear :

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

but nagios ststus show OK not changed to warning or critical why ???

and now use your new script

just put my url in that
please see this link:
https://ufile.io/ktry6

but now your new script appear this message in nagios:

check_http_win UNKNOWN - Missing arguments. Usage is: check_http_win.vbs 'Method' 'URL' 'ExpectStatus' 'POSTData'


ck from Switzerland wrote on Aug 31st, 2017:

Hello Babak. Meanwhile I updated the script. You can find the newest version here: https://github.com/Napsty/check_http_win. I will update the article here, too.
But the error you're hitting is because the DNS could not be resolved. This is not handled within the script. If you know how to check for a valid DNS in VBscript, you're welcome to contribute on the repository.


Babak from US wrote on Aug 30th, 2017:

Dear friend
Hi

this is my vbs script:

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 = 3
End If

WScript.Quit(exitCode)

and the file name is now url.vbs

now when run url.vbs in cmd
cscript url.vbs

appear below message :

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


problem is :
1- that url can not open from my pc and it had show warning or critical but in nagios status is OK and description is above

wy not show warning or critical

BR


RSS feed

Blog Tags:

  AWS   Android   Ansible   Apache   Apple   Atlassian   BSD   Backup   Bash   Bluecoat   CMS   Chef   Cloud   Coding   Consul   Containers   CouchDB   DB   DNS   Database   Databases   Docker   ELK   Elasticsearch   Filebeat   FreeBSD   Galera   Git   GlusterFS   Grafana   Graphics   HAProxy   HTML   Hacks   Hardware   Icinga   Influx   Internet   Java   KVM   Kibana   Kodi   Kubernetes   LVM   LXC   Linux   Logstash   Mac   Macintosh   Mail   MariaDB   Minio   MongoDB   Monitoring   Multimedia   MySQL   NFS   Nagios   Network   Nginx   OSSEC   OTRS   Office   OpenSearch   PGSQL   PHP   Perl   Personal   PostgreSQL   Postgres   PowerDNS   Proxmox   Proxy   Python   Rancher   Rant   Redis   Roundcube   SSL   Samba   Seafile   Security   Shell   SmartOS   Solaris   Surveillance   Systemd   TLS   Tomcat   Ubuntu   Unix   VMWare   VMware   Varnish   Virtualization   Windows   Wireless   Wordpress   Wyse   ZFS   Zoneminder