1
package probes::EchoPing;
3
my $DEFAULTBIN = "/usr/bin/echoping";
7
probes::EchoPing - an echoping(1) probe for SmokePing
11
Measures TCP or UDP echo (port 7) roundtrip times for SmokePing. Can also be
12
used as a base class for other echoping(1) probes.
19
binary = /usr/bin/echoping # default value
28
remark = Top Menu Remark
32
# none of these are mandatory
43
host = router.example.com
45
# PROBE_CONF can be overridden here
51
Supported probe-specific variables:
57
The location of your echoping binary.
61
The number of concurrent processes to be run. See probes::basefork(3pm)
66
Supported target-level probe variables
67
(see echoping(1) for details of the options):
73
The "-t" echoping(1) option.
77
The "-w" echoping(1) option.
81
The "-s" echoping(1) option.
85
The "-u" echoping(1) option. Values other than '0' and 'no' enable UDP.
89
The "-f" echoping(1) option.
93
The "-p" echoping(1) option.
97
The "-P" echoping option.
103
Should we test the availability of the service at startup? After that it's
104
too late to complain.
106
The location of the echoping binary should probably be a global variable
107
instead of a probe-specific one. As things are, every EchoPing -derived probe
108
has to declare it if the default (/usr/bin/echoping) isn't correct.
112
Niko Tyni E<lt>ntyni@iki.fiE<gt>
116
echoping(1), probes::EchoPingHttp(3pm) etc., http://echoping.sourceforge.net/
121
use base qw(probes::basefork);
124
# derived class will mess with this through the 'features' method below
137
$featurehash = $newval if defined $newval;
143
my $class = ref($proto) || $proto;
144
my $self = $class->SUPER::new(@_);
146
$self->_init if $self->can('_init');
148
unless (defined $self->{properties}{binary}) {
149
$self->{properties}{binary} = $DEFAULTBIN;
151
croak "ERROR: EchoPing 'binary' $self->{properties}{binary} does not point to an executable"
152
unless -f $self->{properties}{binary} and -x $self->{properties}{binary};
159
# warn about unsupported features
162
my $bin = $self->{properties}{binary};
165
my $arghashref = $self->features;
166
my %arghash = %$arghashref;
168
for my $feature (keys %arghash) {
169
if (`$bin $arghash{$feature} 1 foo 2>&1` =~ /invalid option|usage/i) {
170
push @unsupported, $feature;
171
carp("Note: your echoping doesn't support the $feature feature (option $arghash{$feature}), disabling it") unless $ENV{SERVER_SOFTWARE};
174
map { delete $arghashref->{$_} } @unsupported;
180
return "TCP or UDP Echo pings using echoping(1)";
183
# This can be overridden to tag the port number to the address
184
# in derived classes (namely EchoPingHttp)
188
return $target->{addr};
192
# other than host, count and protocol-specific args come from here
197
my %arghash = %{$self->features};
199
for (keys %arghash) {
200
my $val = $target->{vars}{$_};
201
$val = $self->{properties}{$_} unless defined $val;
202
push @args, ($arghash{$_}, $val) if defined $val;
207
# this is separated to make it possible to test the service
208
# at startup, although we don't do it at the moment.
213
$count = $self->{cfg}{Database}{pings} unless defined $count;
214
return ("-n", $count);
217
# This is what derived classes will override
220
return $self->udp_arg(@_);
223
# UDP is defined only for echo and discard
229
my $udp = $target->{vars}{udp};
230
$udp = $self->{properties}{udp} unless defined $udp;
231
push @args, "-u" if (defined $udp and $udp ne "no" and $udp != 0);
236
sub make_commandline {
241
my @args = $self->make_args($target);
242
my $host = $self->make_host($target);
243
push @args, $self->proto_args($target);
244
push @args, $self->count_args($count);
246
return ($self->{properties}{binary}, @args, $host);
253
my @cmd = $self->make_commandline($t);
255
my $cmd = join(" ", @cmd);
257
carp "executing cmd $cmd\n" if $self->debug;
261
open(P, "$cmd 2>&1 |") or croak("fork: $!");
263
# what should we do with error messages?
265
/^Elapsed time: (\d+\.\d+) seconds/ and push @times, $1;
269
# carp("Got @times") if $self->debug;
270
return sort { $a <=> $b } @times;
276
$self->{debug} = $newval if defined $newval;
277
return $self->{debug};