Operating System - Microsoft
1752780 Members
6081 Online
108789 Solutions
New Discussion юеВ

Re: monitoring HTTP GET and HTTPS - 200

 
SOLVED
Go to solution
Omar Alvi_1
Super Advisor

monitoring HTTP GET and HTTPS - 200

Hi,

I want to create a monitoring script for website up/down status which will eventually be run as a scheduled action with OVOW as a scheduled action and opcmsg.

I'm looking to use perl for this purpose but have not been able to find anything straightforward as to how such monitoring can be done through scripting.

Any idea - what are the commands that will "ping" a website using http / https and then I can evaluate the 200 OK response or otherwise.

Really appreciate any assistance and support.

Thanks and Regards,

-Alvi
15 REPLIES 15
James R. Ferguson
Acclaimed Contributor

Re: monitoring HTTP GET and HTTPS - 200

Hi:

You could do something like this:

# cat .probeurl
#!/usr/bin/perl
use strict;
use warnings;
use HTTP::Headers;
use LWP::UserAgent;
my $url = shift or die "URL expected\n";
my $useragent = LWP::UserAgent->new;
my $request = HTTP::Request->new( HEAD => $url );
my $response = $useragent->request($request);
if ( $response->is_success ) {
print $response->status_line, "\n";
}
else {
print "Failed: ", $response->status_line, "\n";
}
1;

...run as:

# ./probeurl http://www.womesite.com

# ./probeurl http://www.hp.com

Regards!

...JRF...
Steven E. Protter
Exalted Contributor
Solution

Re: monitoring HTTP GET and HTTPS - 200

Shalom,

wget is the tool for this.

Available for 11.23
http://h20392.www2.hp.com/portal/swdepot/displayProductInfo.do?productNumber=HPUXIEXP1123

For 11.31
http://h20392.www2.hp.com/portal/swdepot/displayProductInfo.do?productNumber=HPUXIEXP1131

Part of a multi tool set you will need to choose it or download the entire package.

http://hpux.connect.org.uk/hppd/hpux/Gnu/wget-1.11.4/

Another source that includes 11.11.

wget http://www.yoursite.com

Will get index.html

Script example.

wget http://www.yoursite.com
rc=$?
if [ $rc -eq 0 ]
then
echo "site is up"
else
echo site is down"
fi

You can work the script from there.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Steven Schweda
Honored Contributor

Re: monitoring HTTP GET and HTTPS - 200

> wget is the tool for this.

It's certainly _a_ tool for this, and it's
the one I use.

> wget http://www.yoursite.com
> rc=$?
> if [ $rc -eq 0 ]

I would not rely on the exit status from
wget. It's often very happy with results I
find unsatisfactory. I use a command like
"wget -O ", and then scan
for "200 ".
James R. Ferguson
Acclaimed Contributor

Re: monitoring HTTP GET and HTTPS - 200

Hi (again):

Actually, I could simply the Perl you are looking to use (since I gutted some features I had that were not germane to your need:

# cat ./probeurl
#!/usr/bin/perl
use strict;
use warnings;
use LWP::UserAgent;
my $url = shift or die "URL expected\n";
my $useragent = LWP::UserAgent->new;
my $request = HTTP::Request->new( HEAD => $url );
my $response = $useragent->request($request);
print $response->status_line, "\n";
1;

# ./probeurl http://www.hp.com
200 OK
# https://www.hp.com
404 Not Found
# ftp://www.hp.com
200 OK

Regards!

...JRF...
Omar Alvi_1
Super Advisor

Re: monitoring HTTP GET and HTTPS - 200

Thanks a lot,

I've been trying out the perl script option, but it seems I'm getting time outs for webstes I'm accessing normally using my browser.

I haven't tried wget yet on my windows.

Will get back with the results - after my weekend.

Really appreciate the great inputs.

Thanks and Regards,

-Alvi
Steven Schweda
Honored Contributor

Re: monitoring HTTP GET and HTTPS - 200

> I haven't tried wget yet on my windows.

Windows? Now you're scaring me.
James R. Ferguson
Acclaimed Contributor

Re: monitoring HTTP GET and HTTPS - 200

Hi (again):

> I've been trying out the perl script option, but it seems I'm getting time outs for webstes I'm accessing normally using my browser

I'd be interested to know a few of the URLs that give you problems, including the HTTP code the script returns.

Regards!

...JRF...
Omar Alvi_1
Super Advisor

Re: monitoring HTTP GET and HTTPS - 200

Hi JRF,

Following ares ome of my trials with this script.

E:\dump\scripts\elm-urlmon\Test>URLTEST.pl http://www.google.com
500 Can't connect to www.google.com:80 (connect: timeout)

E:\dump\scripts\elm-urlmon\Test>URLTEST.pl http://elm.com.sa
500 Can't connect to elm.com.sa:80 (connect: timeout)

E:\dump\scripts\elm-urlmon\Test>URLTEST.pl http://www.hp.com
500 Can't connect to www.hp.com:80 (connect: timeout)

E:\dump\scripts\elm-urlmon\Test>URLTEST.pl http://www.hp.com:8080
500 Can't connect to www.hp.com:8080 (connect: timeout)

There doesn't seem any delay in accessing the internet from this particular server. I tried 8080, as this is the setting of our proxy.

The following, a local site with no security restrictions, came back successfully.

E:\dump\scripts\elm-urlmon\Test>URLTEST.pl http://elm-as-01
200 OK

Really appreciate your support.

I am working with perl on windows, as this will eventually be used on my OVOW server.

Thanks and Regards,

-Alvi
Steven Schweda
Honored Contributor

Re: monitoring HTTP GET and HTTPS - 200

> I am working with perl on windows, [...]

Asking about Windows problems in an HP-UX
forum may not be the most efficient way to
get useful answers.

When you find an appropriate (Microsoft)
forum, you might consider mentioning whether
you can reach these servers from this system
using a Web browser, so that someone could
tell whether you have a Perl problem or a
general network problem.