package Smokeping::probes::EchoPingWhois;

=head1 301 Moved Permanently

This is a Smokeping probe module. Please use the command 

C<smokeping -man Smokeping::probes::EchoPingWhois>

to view the documentation or the command

C<smokeping -makepod Smokeping::probes::EchoPingWhois>

to generate the POD document.

=cut

use strict;
use base qw(Smokeping::probes::EchoPing);
use Carp;

sub pod_hash {
	return {
		name => <<DOC,
Smokeping::probes::EchoPingWhois - an echoping(1) probe for SmokePing
DOC
		overview => <<DOC,
Measures whois roundtrip times (whois servers, RFC 3912) for SmokePing.
DOC
		notes => <<DOC,
You should consider setting a lower value for the C<pings> variable than the
default 20, as repetitive URL fetching may be quite heavy on the server.

The I<fill>, I<size> and I<udp> EchoPing variables are not valid for EchoPingWhois.
DOC
		authors => <<'DOC',
Niko Tyni <ntyni@iki.fi>
DOC
		see_also => <<DOC,
L<Smokeping::probes::EchoPing>, L<Smokeping::probes::EchoPingWhois>
DOC
	}
}

sub _init {
	my $self = shift;
	# whois doesn't fit with filling or size
	my $arghashref = $self->features;
	delete $arghashref->{size};
	delete $arghashref->{fill};
}

sub proto_args {
	my $self = shift;
	my $target = shift;
	my $request = $target->{vars}{request};

	my @args = ("-m whois");

	return @args;
}

sub post_args {
	my $self = shift;
	my $target = shift;
	my $request = $target->{vars}{request};

	my $host = $self->SUPER::make_host($target);

	my @args = ($request);

	return @args;
}

sub test_usage {
	my $self = shift;
	my $bin = $self->{properties}{binary};
	croak("Your echoping binary doesn't support whois")
		if `$bin -m whois 127.0.0.1 2>&1` =~ /(Cannot load)/i;
	$self->SUPER::test_usage;
	return;
}

sub ProbeDesc($) {
        return "WhoIs pings using echoping(1)";
}

sub targetvars {
	my $class = shift;
	my $h = $class->SUPER::targetvars;
	delete $h->{udp};
	delete $h->{fill};
	delete $h->{size};
	$h->{timeout}{default} = 10;
	$h->{timeout}{example} = 20;
	return $class->_makevars($h, {
		request => {
			_doc => <<DOC,
The request to the whois server.
DOC
		},
	});
   }

1;
