Subversion Repositories sysadmin_scripts

Rev

Rev 92 | Rev 94 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 92 Rev 93
Line 14... Line 14...
14
#
14
#
15
# type: netcat
15
# type: netcat
16
# url: site to test
16
# url: site to test
17
# port: port to test on
17
# port: port to test on
18
# timeout: optional integer, number of seconds. defaults to 'default timeout'
18
# timeout: optional integer, number of seconds. defaults to 'default timeout'
-
 
19
# additional parameters: any additional cli parameters to add.
-
 
20
 
19
 
21
 
20
use Data::Dumper;
22
use Data::Dumper;
21
use FindBin;
23
use FindBin;
22
use File::Spec;
24
use File::Spec;
23
 
25
 
-
 
26
my $TESTING = 0;
-
 
27
 
24
# name of script directory, no trailing slash
28
# name of script directory, no trailing slash
25
my $MY_DIR = $FindBin::Bin;
29
my $MY_DIR = $FindBin::Bin;
26
# name of currently executing file
30
# name of currently executing file
27
my $MY_NAME = $FindBin::Script;
31
my $MY_NAME = $FindBin::Script;
28
 
32
 
Line 48... Line 52...
48
   $yaml->write( $filename );
52
   $yaml->write( $filename );
49
}
53
}
50
 
54
 
51
# check using netcat
55
# check using netcat
52
sub checkNetCat {
56
sub checkNetCat {
53
   my ($url, $port, $timeout ) = @_;
57
   my ($url, $port, $timeout, $additionalParameters ) = @_;
54
   my $netcat = `which nc`;
58
   my $netcat = `which nc`;
55
   chomp $netcat;
59
   chomp $netcat;
56
   unless ( $netcat ) {
60
   unless ( $netcat ) {
57
      warn "Netcat not found, not testing\n";
61
      warn "Netcat not found, not testing\n";
58
      return 0;
62
      return 0;
59
   }
63
   }
60
   $netcat = join( ' ', ($netcat, "-z -w $timeout", $url, $port ) );
64
   $netcat = join( ' ', ($netcat, "-z -w $timeout", $additionalParameters, $url, $port ) );
-
 
65
   print "\t$netcat\n" if $TESTING;
61
   `$netcat`;
66
   `$netcat`;
62
   return not $? >> 8;
67
   return not $? >> 8;
63
} 
68
} 
64
 
69
 
65
# this has only been tested on http and https, but with a little work
70
# this has only been tested on http and https, but with a little work
Line 102... Line 107...
102
   if ( $parameters->{'type'} eq 'lwp' ) {
107
   if ( $parameters->{'type'} eq 'lwp' ) {
103
      $result = &checkHTTP( $parameters->{'url'}, $parameters->{'timeout'} );
108
      $result = &checkHTTP( $parameters->{'url'}, $parameters->{'timeout'} );
104
   } elsif ( $parameters->{'type'} eq 'ping' ) {
109
   } elsif ( $parameters->{'type'} eq 'ping' ) {
105
      $result = checkPing( $parameters->{'url'}, $parameters->{'timeout'} );
110
      $result = checkPing( $parameters->{'url'}, $parameters->{'timeout'} );
106
   } elsif ( $parameters->{'type'} eq 'netcat' ) {
111
   } elsif ( $parameters->{'type'} eq 'netcat' ) {
-
 
112
      $result = checkNetCat( 
-
 
113
               $parameters->{'url'},
-
 
114
               $parameters->{'port'},
-
 
115
               $parameters->{'timeout'}, 
107
      $result = checkNetCat( $parameters->{'url'}, $parameters->{'port'}, $parameters->{'timeout'} );
116
               defined $parameters->{'additional parameters'} ? $parameters->{'additional parameters'} : '' 
-
 
117
               );
108
   } else {
118
   } else {
109
      warn "Unknown test type $parameters->{type}, aborting test\n";
119
      warn "Unknown test type $parameters->{type}, aborting test\n";
110
      $result = 0;
120
      $result = 0;
111
   }
121
   }
112
   return $result;
122
   return $result;
Line 158... Line 168...
158
# countdown in case of failure
168
# countdown in case of failure
159
# if the countdown is exceeded, it will report the status 
169
# if the countdown is exceeded, it will report the status 
160
sub processFailure {
170
sub processFailure {
161
   my ( $name, $parameters ) = @_;
171
   my ( $name, $parameters ) = @_;
162
   # temporary for testing
172
   # temporary for testing
163
   print "Failed test for $name\n";
-
 
164
   my $flagFileName = &flagFileName( $name );
173
   my $flagFileName = &flagFileName( $name );
165
   my $remainingCounts = $parameters->{'failure count'};
174
   my $remainingCounts = $parameters->{'failure count'};
-
 
175
   print "$name => Failed\n" if $TESTING;
166
   if ( -f $flagFileName ) {
176
   if ( -f $flagFileName ) {
167
      # open flag file, read the value into $remaingCounts
177
      # open flag file, read the value into $remaingCounts
168
      return if $remainingCounts == -1;
178
      return if $remainingCounts == -1;
169
   }
179
   }
170
   if ( $remainingCounts-- == 0 ) {
180
   if ( $remainingCounts-- == 0 ) {
Line 174... Line 184...
174
}
184
}
175
 
185
 
176
# we are up, so check for any flag file and unlink if found
186
# we are up, so check for any flag file and unlink if found
177
sub cleanUp {
187
sub cleanUp {
178
   my $name = shift;
188
   my $name = shift;
-
 
189
   print "$name => Success\n" if $TESTING;
179
   $name = &flagFileName( $name );
190
   $name = &flagFileName( $name );
180
   unlink $name if -f $name;
191
   unlink $name if -f $name;
181
}
192
}
182
 
193
 
183
#######################################################################
194
#######################################################################