| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Watchdog::HTTP; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 1 |  |  | 1 |  | 165962 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 31 |  | 
| 4 | 1 |  |  | 1 |  | 94499 | use Alias; | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | use base qw(Watchdog::Base); | 
| 6 |  |  |  |  |  |  | use HTTP::Request; | 
| 7 |  |  |  |  |  |  | use LWP::UserAgent; | 
| 8 |  |  |  |  |  |  | use vars qw($VERSION $HOST $PORT $FILE); | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | $VERSION = '0.02'; | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | =head1 NAME | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | Watchdog::HTTP - Test status of HTTP service | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | use Watchdog::HTTP; | 
| 19 |  |  |  |  |  |  | $h = new Watchdog::HTTP($name,$host,$port,$file); | 
| 20 |  |  |  |  |  |  | print $h->id, $h->is_alive ? ' is alive' : ' is dead', "\n"; | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | B is an extension for monitoring an HTTP server. | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | =cut | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | my($name,$port,$file) = ('httpd',80,''); | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | =head1 CLASS METHODS | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | =head2 new($name,$host,$port,$file) | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | Returns a new B object.  I<$name> is a string which | 
| 35 |  |  |  |  |  |  | will identify the service to a human (default is 'httpd').  I<$host> | 
| 36 |  |  |  |  |  |  | is the hostname which is running the service (default is 'localhost'). | 
| 37 |  |  |  |  |  |  | I<$port> is the port on which the service listens (default is 80). | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | =cut | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | sub new($$$) { | 
| 42 |  |  |  |  |  |  | my $proto = shift; | 
| 43 |  |  |  |  |  |  | my $class = ref($proto) || $proto; | 
| 44 |  |  |  |  |  |  | $_[0] = $name unless defined($_[0]); | 
| 45 |  |  |  |  |  |  | $_[2] = $port unless defined($_[2]); | 
| 46 |  |  |  |  |  |  | my $self  = bless($class->SUPER::new(@_),$class); | 
| 47 |  |  |  |  |  |  | return $self; | 
| 48 |  |  |  |  |  |  | } | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | #------------------------------------------------------------------------------ | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | =head1 OBJECT METHODS | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | =head2 is_alive() | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  | Returns true if an HTTP B method succeeds for the URL | 
| 57 |  |  |  |  |  |  | B or false if it doesn't. | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | =cut | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | sub is_alive() { | 
| 62 |  |  |  |  |  |  | my $self = attr shift; | 
| 63 |  |  |  |  |  |  | my $request  = new HTTP::Request(GET => "http://$HOST:$PORT/$FILE"); | 
| 64 |  |  |  |  |  |  | my $ua       = new LWP::UserAgent; | 
| 65 |  |  |  |  |  |  | my $response = $ua->request($request); | 
| 66 |  |  |  |  |  |  | return $response->is_success ? 1 : 0; | 
| 67 |  |  |  |  |  |  | } | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | #------------------------------------------------------------------------------ | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | L | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | =head1 AUTHOR | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | new Maintainer: Clemens Gesell Eclemens.gesell@vegatron.orgE | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | Paul Sharpe Epaul@miraclefish.comE | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | =head1 COPYRIGHT | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | Copyright (c) 1998 Paul Sharpe. England.  All rights reserved.  This | 
| 84 |  |  |  |  |  |  | program is free software; you can redistribute it and/or modify it | 
| 85 |  |  |  |  |  |  | under the same terms as Perl itself. | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | =cut |