Subversion Repositories sysadmin_scripts

Rev

Rev 89 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
88 rodolico 1
#! /usr/bin/env perl
2
 
3
use strict;
4
use warnings;
5
 
6
use Data::Dumper;
7
 
8
my $DEFAULT_TIMEOUT = 60;
9
 
10
# hashref which holds targets
11
my $sitesToCheck;
12
 
13
sub loadConf {
14
}
15
 
16
 
17
sub checkNC {
18
   use Net::Netcat;
19
} 
20
 
21
 
22
sub checkHTTP {
23
   use LWP::UserAgent;
24
   my ($url, $timeout) = @_;
25
   #print "URL = $url\nTimeout = $timeout\n\n";
26
   return -1 unless $url && $timeout;
27
   my $r = HTTP::Request->new( 'HEAD', $url );
28
   my $ua = LWP::UserAgent->new();
29
   my $res = $ua->request($r);
30
   return $res->is_success;
31
   #die Dumper( $res );
32
}
33
 
34
sub checkPing {
35
   my ($url,$type,$timeout) = @_;
36
   use Net::Ping;
37
   my $p = Net::Ping->new('icmp');
38
   return $p->ping( $url ) ? 1 : 0;
39
}   
40
 
41
sub runTest {
42
   my $parameters = shift;
43
   my $result;
44
   if ( $parameters->{'type'} eq 'lwp' ) {
45
      $result = &checkHTTP( $parameters->{'url'}, $parameters->{'timeout'} ? $parameters->{'timeout'} : $DEFAULT_TIMEOUT );
46
   } elsif ( $parameters->{'type'} eq 'ping' ) {
47
      $result = checkPing( $parameters->{'url'}, $parameters->{'timeout'} ? $parameters->{'timeout'} : $DEFAULT_TIMEOUT );
48
   }
49
   return $result;
50
}
51
 
52
my $login = (getpwuid $>);
53
die "This script must be run as root\n" if $login ne 'root';
54
 
55
my $result;
56
foreach my $testToRun( keys %$sitesToCheck ) {
57
   $result = &runTest( $sitesToCheck->{$testToRun} );
58
   print "Results for $testToRun " . ( $result ? "is" : "is not" ) . " ok\n";
59
}