From 8a4c23496d19915818b87a9050e01a478b94a5cc Mon Sep 17 00:00:00 2001 From: Tobi Oetiker Date: Thu, 7 Sep 2006 22:02:35 +0000 Subject: added WebProxyFilter probe --- lib/Smokeping/probes/WebProxyFilter.pm | 171 +++++++++++++++++++++++++++++++++ 1 file changed, 171 insertions(+) create mode 100644 lib/Smokeping/probes/WebProxyFilter.pm (limited to 'lib/Smokeping') diff --git a/lib/Smokeping/probes/WebProxyFilter.pm b/lib/Smokeping/probes/WebProxyFilter.pm new file mode 100644 index 0000000..e4b97f6 --- /dev/null +++ b/lib/Smokeping/probes/WebProxyFilter.pm @@ -0,0 +1,171 @@ +package Smokeping::probes::WebProxyFilter; + +=head1 301 Moved Permanently + +This is a Smokeping probe module. Please use the command + +C + +to view the documentation or the command + +C + +to generate the POD document. + +=cut + +use strict; +use base qw(Smokeping::probes::basefork); +use LWP::UserAgent; +use Time::HiRes qw(gettimeofday sleep); +use Carp; + +my $DEFAULTINTERVAL = 1; + +sub pod_hash { + return { + name => < < < <<'DOC', +Tobias Oetiker sponsored by Virtela +DOC + bugs => <SUPER::new(@_); + return $self; +} + +sub pingone { + my $self = shift; + my $target = shift; + my $host = $target->{addr}; + my $vars = $target->{vars}; + my $mininterval = $self->{properties}{min_interval}; + my @times; + my $elapsed; + my $ua = LWP::UserAgent->new; + $ua->agent($vars->{useragent}); + $ua->timeout($vars->{timeout}); + $ua->max_size($vars->{max_size}); + my @targets = ($host, split /\s*,\s*/, $vars->{more_hosts}); + my $targcount = scalar @targets; + my $pingcount = $self->pings($target); + my $deny_re = $vars->{deny_re}; + if ($targcount > $self->pings($target)) { + $self->do_log("ERROR There are more host addresses ($targcount) than ping slots ($pingcount), either increasse the pings or reduce the targets.\n"); + return; + } + + for (1..$pingcount) { + if (defined $elapsed) { + my $timeleft = $mininterval - $elapsed; + sleep $timeleft if $timeleft > 0; + } + my $target = shift @targets; + push @targets,$target; + my $start = gettimeofday(); + my $response = $ua->get("http://$target"); + my $end = gettimeofday(); + if ($response->is_success){ + if ($response->content =~ /$deny_re/ism){ + push @times,($end-$start); + } else { + my $content = substr($response->content,0,80)." ..."; + $content =~ s/[\n\r]/ /g; + $self->do_log("Warning: Problem with target $host: got unexpected content from $target: $content"); + } + } else { + $self->do_log("Warning: Problem with target $host: got this error from $target: ".$response->status_line); + } + } + return sort { $a <=> $b } @times; +} + +sub probevars { + my $class = shift; + my $h = $class->SUPER::probevars; + return $class->_makevars($h, { + _mandatory => ['deny_re'], + min_interval => { + _default => $DEFAULTINTERVAL, + _doc => "The minimum interval between each starting GETs in seconds.", + _re => '(\d*\.)?\d+', + _example => '0.1' + }, + useragent => { + _default => "SmokePing/2.x (WebProxyFilter Probe)", + _doc => "The web browser we claim to be, just in case the FW is interested" + }, + maxsize => { + _default => 2000, + _doc => "How much of the webpage should be retreived." + }, + + }); +} + +sub targetvars { + my $class = shift; + return $class->_makevars($class->SUPER::targetvars, { + timeout => { + _default => 2, + _doc => "Timeout in seconds for the test complete.", + _re => '\d+', + _example => 2, + }, + deny_re => { + _doc => "Regular expression, matching the 'deny' response from the firewall", + _example => 'Access Prohibited', + }, + more_hosts => { + _doc => < variable. The websites will be tested one after the +other in one round, this means that while normal probes do run the same test +serveral times in a row, this one will alter the webpage with each round. +The reason for this is, that eventhough we try to retreive remote webpages, +the answer will come from the firewall everytime, so we kill two birds in +one go. First we test the firewalls latency and second we make sure its +filter works properly. +DOC + _re => '[^\s.]+(?:\.[^\s.]+)*(\s*,[^\s.]+(?:\.[^\s.]+)*)*', + _example => 'www.playboy.com, www.our-competition.com', + }, + + }); +} + +1; -- cgit v1.2.3-24-g4f1b