| 1 | package App::MadEye::Plugin::Agent::Perlbal; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | use IO::Socket::INET; | ||
| 5 | use App::MadEye::Plugin::Agent::Base; | ||
| 6 | |||
| 7 | my $req = <<'...'; | ||
| 8 | GET / HTTP/1.0 | ||
| 9 | Host: invalidhostname.example.com | ||
| 10 | |||
| 11 | ... | ||
| 12 | |||
| 13 | sub is_dead { | ||
| 14 | my ($self, $host) = @_; | ||
| 15 | |||
| 16 | my $conf = $self->config->{config}; | ||
| 17 | my $port = $conf->{port} || 80; | ||
| 18 | my $timeout = $conf->{timeout} || 10; | ||
| 19 | |||
| 20 | my $sock = IO::Socket::INET->new( | ||
| 21 | PeerAddr => $host, | ||
| 22 | PeerPort => $port, | ||
| 23 | Timeout => $timeout, | ||
| 24 | ) or return "cannot open socket"; | ||
| 25 | $sock->write($req); | ||
| 26 | |||
| 27 | my $content = join '', <$sock>; | ||
| 28 | if ($content =~ m{Server: Perlbal.+<h1>404 - Not Found</h1>}s) { | ||
| 29 | return; # alive. | ||
| 30 | } else { | ||
| 31 | return "this is not a perlbal?\n\n$content"; | ||
| 32 | } | ||
| 33 | } | ||
| 34 | |||
| 35 | 1; | ||
| 36 | __END__ |