From c804efc1111ab2fc29f90d8ba0dcbfcd25f5b43d Mon Sep 17 00:00:00 2001 From: Niko Tyni Date: Fri, 2 Dec 2005 21:45:05 +0000 Subject: * brought trunk/ up to date --- lib/Smokeping/probes/Curl.pm | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) (limited to 'lib/Smokeping') diff --git a/lib/Smokeping/probes/Curl.pm b/lib/Smokeping/probes/Curl.pm index 6e4625a..2e2ef01 100644 --- a/lib/Smokeping/probes/Curl.pm +++ b/lib/Smokeping/probes/Curl.pm @@ -128,6 +128,26 @@ DOC return undef; }, }, + follow_redirects => { + _doc => < "no", + _re => "(yes|no)", + _example => "yes", + }, + + include_redirects => { + _doc => < "no", + _re => "(yes|no)", + _example => "yes", + }, extraargs => { _doc => <{$_} } @unsupported; - + if (`$bin -o /dev/null -w '<%{time_redirect}>\n' 127.0.0.1 2>&1` =~ /^<>/m) { + $self->do_log("Note: your curl doesn't support the 'time_redirect' output variable; 'include_redirects' will not function."); + } return; } @@ -217,11 +239,13 @@ sub proto_args { my $target = shift; # XXX - It would be neat if curl had a "time_transfer". For now, # we take the total time minus the DNS lookup time. - my @args = ("-o", "/dev/null", "-w", "Time: %{time_total} DNS time: %{time_namelookup}\\n"); + my @args = ("-w", "Time: %{time_total} DNS time: %{time_namelookup} Redirect time: %{time_redirect}\\n"); my $ssl2 = $target->{vars}{ssl2}; push (@args, "-2") if $ssl2; my $insecure_ssl = $target->{vars}{insecure_ssl}; push (@args, '-k') if $insecure_ssl; + my $follow = $target->{vars}{follow_redirects}; + push (@args, '-L') if $follow eq "yes"; return(@args); } @@ -245,10 +269,12 @@ sub make_commandline { my $url = $target->{vars}{urlformat}; my $host = $target->{addr}; $url =~ s/%host%/$host/g; + my @urls = split(/\s+/, $url); + push @args, ("-o", "/dev/null") for (@urls); push @args, $self->proto_args($target); push @args, $self->extra_args($target); - return ($self->{properties}{binary}, @args, $url); + return ($self->{properties}{binary}, @args, @urls); } sub pingone { @@ -268,7 +294,14 @@ sub pingone { my $val; while (

) { - /^Time: (\d+\.\d+) DNS time: (\d+\.\d+)/ and $val = $1 - $2; + chomp; + /^Time: (\d+\.\d+) DNS time: (\d+\.\d+) Redirect time: (\d+\.\d+)?/ and do { + $val += $1 - $2; + if ($t->{vars}{include_redirects} eq "yes" and defined $3) { + $val += $3; + } + $self->do_debug("curl output: '$_', result: $val"); + }; } close P and defined $val and push @times, $val; } -- cgit v1.2.3-24-g4f1b