Rev 89 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
#! /usr/bin/env perl
use strict;
use warnings;
use Data::Dumper;
my $DEFAULT_TIMEOUT = 60;
# hashref which holds targets
my $sitesToCheck;
sub loadConf {
}
sub checkNC {
use Net::Netcat;
}
sub checkHTTP {
use LWP::UserAgent;
my ($url, $timeout) = @_;
#print "URL = $url\nTimeout = $timeout\n\n";
return -1 unless $url && $timeout;
my $r = HTTP::Request->new( 'HEAD', $url );
my $ua = LWP::UserAgent->new();
my $res = $ua->request($r);
return $res->is_success;
#die Dumper( $res );
}
sub checkPing {
my ($url,$type,$timeout) = @_;
use Net::Ping;
my $p = Net::Ping->new('icmp');
return $p->ping( $url ) ? 1 : 0;
}
sub runTest {
my $parameters = shift;
my $result;
if ( $parameters->{'type'} eq 'lwp' ) {
$result = &checkHTTP( $parameters->{'url'}, $parameters->{'timeout'} ? $parameters->{'timeout'} : $DEFAULT_TIMEOUT );
} elsif ( $parameters->{'type'} eq 'ping' ) {
$result = checkPing( $parameters->{'url'}, $parameters->{'timeout'} ? $parameters->{'timeout'} : $DEFAULT_TIMEOUT );
}
return $result;
}
my $login = (getpwuid $>);
die "This script must be run as root\n" if $login ne 'root';
my $result;
foreach my $testToRun( keys %$sitesToCheck ) {
$result = &runTest( $sitesToCheck->{$testToRun} );
print "Results for $testToRun " . ( $result ? "is" : "is not" ) . " ok\n";
}