App::MadEye::Plugin::Agent::HTTP - check HTTP


App-MadEye documentation Contained in the App-MadEye distribution.

Index


Code Index:

NAME

Top

App::MadEye::Plugin::Agent::HTTP - check HTTP

SCHEMA

Top

    type: map
    mapping:
        target:
            type: seq
            required: yes
            sequence:
                - type: str
        timeout:
            required: yes
            type: int
        user_agent:
            required: no
            type: str
        part:
            required: no
            type: str

AUTHOR

Top

Tokuhiro Matsuno

SEE ALSO

Top

App::MadEye, Gearman::Client, Gearman::Worker


App-MadEye documentation Contained in the App-MadEye distribution.

package App::MadEye::Plugin::Agent::HTTP;
use strict;
use warnings;
use LWP::UserAgent;
use App::MadEye::Plugin::Agent::Base;

our $TIMEOUT = 15;

sub is_dead {
    my ($self, $url) = @_;

    my $ua = LWP::UserAgent->new(
        timeout => $TIMEOUT,
        agent   => $self->config->{config}->{user_agent} || "App::MadEye($App::MadEye::VERSION)",
    );
    my $res = $ua->get($url);

    if ($res->code == 200) {
        if (my $part = $self->config->{config}->{part}) {
            if (index($res->content, $part) >= 0) {
                return; # ok
            } else {
                return "contents does not contain $part";
            }
        } else {
            return 0;
        }
    } else {
        return join( "\n", $res->code, $res->message, $res->content );
    }
}

1;
__END__