Watchdog::HTTP - Test status of HTTP service


Watchdog documentation Contained in the Watchdog distribution.

Index


Code Index:

NAME

Top

Watchdog::HTTP - Test status of HTTP service

SYNOPSIS

Top

  use Watchdog::HTTP;
  $h = new Watchdog::HTTP($name,$host,$port,$file);
  print $h->id, $h->is_alive ? ' is alive' : ' is dead', "\n";

DESCRIPTION

Top

Watchdog::HTTP is an extension for monitoring an HTTP server.

CLASS METHODS

Top

new($name,$host,$port,$file)

Returns a new Watchdog::HTTP object. $name is a string which will identify the service to a human (default is 'httpd'). $host is the hostname which is running the service (default is 'localhost'). $port is the port on which the service listens (default is 80).

OBJECT METHODS

Top

is_alive()

Returns true if an HTTP GET method succeeds for the URL http://$host:$port/$file or false if it doesn't.

SEE ALSO

Top

Watchdog::Base

AUTHOR

Top

new Maintainer: Clemens Gesell <clemens.gesell@vegatron.org>

Paul Sharpe <paul@miraclefish.com>

COPYRIGHT

Top


Watchdog documentation Contained in the Watchdog distribution.
package Watchdog::HTTP;

use strict;
use Alias;
use base qw(Watchdog::Base);
use HTTP::Request;
use LWP::UserAgent;
use vars qw($VERSION $HOST $PORT $FILE);

$VERSION = '0.02';

my($name,$port,$file) = ('httpd',80,'');

sub new($$$) {
  my $proto = shift;
  my $class = ref($proto) || $proto;
  $_[0] = $name unless defined($_[0]);
  $_[2] = $port unless defined($_[2]); 
  my $self  = bless($class->SUPER::new(@_),$class);
  return $self;
}

#------------------------------------------------------------------------------

sub is_alive() {
  my $self = attr shift;
  my $request  = new HTTP::Request(GET => "http://$HOST:$PORT/$FILE");
  my $ua       = new LWP::UserAgent;
  my $response = $ua->request($request);
  return $response->is_success ? 1 : 0;
}

#------------------------------------------------------------------------------