123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- use strict;
- use Socket;
- use Net::SSLeay qw(die_now die_if_ssl_error) ;
- use Getopt::Std;
- use English;
- use vars qw($opt_p $opt_t $opt_u $opt_v);
- getopts ("vp:t:u:");
- my $PORT = $opt_p || 443;
- my $TIMEOUT = $opt_t || 30;
- my $URL = $opt_u || "/";
- my $perl = "/usr/bin/perl";
- my $field_delim = "<>";
- my @failures = ();
- my @detail = ();
- my ($host, $OK, $default_header, $auth_header, $end_header, $request_header, $msg);
- my ($dest_ip, $dest_serv, $sockaddr_template, $dest_serv_params, $ctx, $ssl, $res, $reply, $got, $ServerOK);
- foreach $host (@ARGV) {
- $OK = &httpsGET($host, $PORT, $URL);
- if (!defined ($OK) || $OK == 0) {
- push (@failures, $host);
- }
- }
- if (@failures == 0) {
- exit 0;
- }
- print "@failures\n";
- print join(";",@detail);
- exit 1;
- sub httpsGET {
- my ($site, $port, $path) = (@_);
- my $total_bytes = 0;
- my ($page, $result, %headers);
- eval {
- local $SIG{ALRM} = sub { die "Timeout Alarm" };
- alarm $TIMEOUT;
- $result = `$perl -e'use Net::SSLeay ; Net::SSLeay::SSLeay_add_ssl_algorithms() ; print join("$field_delim",Net::SSLeay::get_https("$site", "$port", "$path"))' 2>/dev/null`;
- alarm 0;
- ($page, $result, %headers) = split ("<>",$result);
- print "Result was `$result'\n" if $opt_v;
- foreach my $h (sort keys %headers) {
- print "Header `$h'\tvalue `$headers{$h}'\n" if $opt_v;
- }
- if ($result =~ /^HTTP\/([\d\.]+)\s+(200|301|302)\b/) {
- $ServerOK = 1;
- } else {
- $ServerOK = 0;
- push(@detail,"$result");
- }
- };
- if ($EVAL_ERROR and ($EVAL_ERROR eq 'Timeout Alarm')) {
- print "**** Time Out\n";
- return 0;
- }
- return $ServerOK;
- }
|