From 7d68f748c5fdb8e1fe8d5daeb1deda2b9dafa435 Mon Sep 17 00:00:00 2001 From: Jeremy Weatherford Date: Wed, 12 Sep 2012 08:34:35 -0700 Subject: add expect parameter to Curl.pm --- lib/Smokeping/probes/Curl.pm | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'lib/Smokeping/probes') diff --git a/lib/Smokeping/probes/Curl.pm b/lib/Smokeping/probes/Curl.pm index 7b3d3a9..b9c10e7 100644 --- a/lib/Smokeping/probes/Curl.pm +++ b/lib/Smokeping/probes/Curl.pm @@ -164,6 +164,14 @@ and then specify C. DOC _example => "-6 --head --user user:password", }, + expect => { + _doc => < "", + _example => "Status: green", + }, }); } @@ -271,7 +279,7 @@ sub make_commandline { my $host = $target->{addr}; $url =~ s/%host%/$host/g; my @urls = split(/\s+/, $url); - push @args, ("-o", "/dev/null") for (@urls); +# push @args, ("-o", "/dev/null") for (@urls); push @args, $self->proto_args($target); push @args, $self->extra_args($target); @@ -293,10 +301,15 @@ sub pingone { open(P, "-|") or exec @cmd; my $val; + my $expectOK = 1; + $expectOK = 0 if ($t->{vars}{expect} ne ""); while (

) { chomp; - /^Time: (\d+\.\d+) DNS time: (\d+\.\d+) Redirect time: (\d+\.\d+)?/ and do { + if (!$expectOK and index($_, $t->{vars}{expect}) != -1) { + $expectOK = 1; + } + /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; @@ -317,7 +330,7 @@ sub pingone { $self->$function(qq(WARNING: curl exited $why on $t->{addr})); } - push @times, $val if defined $val; + push @times, $val if (defined $val and $expectOK); } # carp("Got @times") if $self->debug; -- cgit v1.2.3-24-g4f1b From 75dcab25f99f7f074514e9d184c6de268fd18601 Mon Sep 17 00:00:00 2001 From: Jeremy Weatherford Date: Wed, 12 Sep 2012 08:36:16 -0700 Subject: fix stray spaces --- lib/Smokeping/probes/Curl.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/Smokeping/probes') diff --git a/lib/Smokeping/probes/Curl.pm b/lib/Smokeping/probes/Curl.pm index b9c10e7..66c5560 100644 --- a/lib/Smokeping/probes/Curl.pm +++ b/lib/Smokeping/probes/Curl.pm @@ -330,7 +330,7 @@ sub pingone { $self->$function(qq(WARNING: curl exited $why on $t->{addr})); } - push @times, $val if (defined $val and $expectOK); + push @times, $val if (defined $val and $expectOK); } # carp("Got @times") if $self->debug; -- cgit v1.2.3-24-g4f1b