~ubuntu-branches/debian/stretch/smokeping/stretch

« back to all changes in this revision

Viewing changes to lib/probes/RemoteFPing.pm

  • Committer: Bazaar Package Importer
  • Author(s): Jose Carlos Garcia Sogo
  • Date: 2005-03-13 13:55:44 UTC
  • mfrom: (1.2.1 upstream) (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050313135544-185x9ub9ef5m4q64
Tags: 1.38-3
* Include missing matchers methods in binary package (Closes: #295354)
* Add missing suggests: libnet-dns-perl, ssh, libio-socket-ssl-perl,
  libnet-telnet-perl (Closes: #295372)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package probes::RemoteFPing;
 
2
 
 
3
=head1 NAME
 
4
 
 
5
probes::RemoteFPing - Remote FPing Probe for SmokePing
 
6
 
 
7
=head1 SYNOPSIS
 
8
 
 
9
 *** Probes ***
 
10
 + RemoteFPing
 
11
 binary = /usr/bin/ssh
 
12
 packetsize = 1024
 
13
 rhost = HostA.foobar.com
 
14
 ruser = foo
 
15
 rbinary = /usr/local/sbin/fping
 
16
 
 
17
 *** Targets ***
 
18
 + Targetname
 
19
 Probe = RemoteFPing
 
20
 Menu = menuname
 
21
 Title = Remote Fping from HostA to HostB
 
22
 Host = HostB.barfoo.com
 
23
 
 
24
 
 
25
=head1 DESCRIPTION
 
26
 
 
27
Integrates the remote execution of FPing via ssh/rsh into smokeping.
 
28
The variable B<binary> must point to your copy of the ssh/rsh program.
 
29
 
 
30
=head1 OPTIONS
 
31
 
 
32
The B<binary> and B<rhost> are mandatory. The B<binary> option
 
33
specifies the path of the remote shell program (usually ssh,
 
34
rsh or remsh). Any other script or binary that can be called as
 
35
 
 
36
 binary [ -l ruser ] rhost rbinary
 
37
 
 
38
may be used.
 
39
 
 
40
The (optional) B<packetsize> option lets you configure the packetsize
 
41
for the pings sent.
 
42
 
 
43
The B<rhost> option specifies the remote device from where fping will
 
44
be launched.
 
45
 
 
46
The (optional) B<ruser> option allows you to specify the remote user,
 
47
if different from the one running the smokeping daemon.
 
48
 
 
49
The (optional) B<rbinary> option allows you to specify the location of
 
50
the remote fping binary. If not specified the probe will assume that
 
51
fping is in the remote host's path.
 
52
 
 
53
=head1 NOTES
 
54
 
 
55
It is important to make sure that you can access the remote machine
 
56
without a password prompt, otherwise this probe will not work properly.
 
57
To test just try something like this:
 
58
 
 
59
    $ ssh foo@HostA.foobar.com fping HostB.barfoo.com 
 
60
 
 
61
The next thing you see must be fping's output.
 
62
 
 
63
The B<rhost>, B<ruser> and B<rbinary> variables used to be configured in
 
64
the PROBE_CONF section of the first target or its parents They were moved
 
65
to the Probes section, because the variables aren't really target-specific
 
66
(all the targets are measured with the same parameters). The PROBE_CONF
 
67
sections aren't recognized anymore.
 
68
 
 
69
=head1 AUTHOR
 
70
 
 
71
Luis F Balbinot <hades@inf.ufrgs.br>
 
72
 
 
73
based on probes::FPing by
 
74
 
 
75
Tobias Oetiker <tobi@oetiker.ch>
 
76
 
 
77
=cut
 
78
 
 
79
use strict;
 
80
use base qw(probes::base);
 
81
use IPC::Open3;
 
82
use Symbol;
 
83
use Carp;
 
84
 
 
85
sub new($$$) {
 
86
    my $proto = shift;
 
87
    my $class = ref($proto) || $proto;
 
88
    my $self = $class->SUPER::new(@_);
 
89
 
 
90
    # no need for this if we run as a cgi
 
91
    unless ( $ENV{SERVER_SOFTWARE} ) {
 
92
        croak "ERROR: RemoteFPing packetsize must be between 12 and 64000"
 
93
           if $self->{properties}{packetsize} and 
 
94
              ( $self->{properties}{packetsize} < 12 or $self->{properties}{packetsize} > 64000 ); 
 
95
 
 
96
        croak "ERROR: RemoteFPing 'binary' not defined in RemoteFPing probe definition"
 
97
            unless defined $self->{properties}{binary};
 
98
 
 
99
        croak "ERROR: RemoteFPing 'binary' does not point to an executable"
 
100
            unless -f $self->{properties}{binary} and -x $self->{properties}{binary};
 
101
 
 
102
        croak "ERROR: RemoteFPing 'rhost' not defined in RemoteFPing probe definition. This might be because the configuration syntax has changed. See the RemoteFPing manual for details."
 
103
            unless defined $self->{properties}{rhost};
 
104
    
 
105
        $self->{pingfactor} = 1000; # Gives us a good-guess default
 
106
        print "### assuming you are using a remote fping copy reporting in milliseconds\n";
 
107
    };
 
108
 
 
109
    return $self;
 
110
}
 
111
 
 
112
sub ProbeDesc($) {
 
113
    my $self = shift;
 
114
    my $bytes = $self->{properties}{packetsize} || 56;
 
115
    return "Remote ICMP Echo Pings ($bytes Bytes)";
 
116
}
 
117
 
 
118
sub ping ($) {
 
119
    my $self = shift;
 
120
 
 
121
    # do NOT call superclass ... the ping method MUST be overwriten
 
122
    my %upd;
 
123
    my $inh = gensym;
 
124
    my $outh = gensym;
 
125
    my $errh = gensym;
 
126
    # pinging nothing is pointless
 
127
    return unless @{$self->addresses};
 
128
    my @bytes = ();
 
129
 
 
130
    push @bytes, "-b$self->{properties}{packetsize}" if $self->{properties}{packetsize};
 
131
 
 
132
    my @rargs;
 
133
    for my $what (qw(ruser rhost rbinary)) {
 
134
        my $prefix = ($what eq 'ruser' ? "-l" : "");
 
135
        if (defined $self->{properties}{$what}) {
 
136
                push @rargs, $prefix . $self->{properties}{$what};
 
137
        } 
 
138
    }
 
139
 
 
140
    my $query = "$self->{properties}{binary} @rargs @bytes -C " . $self->pings . " -q -B1 -i10 -r1 @{$self->addresses}";
 
141
 
 
142
      $self->do_debug("query=$query\n");
 
143
 
 
144
    my $pid = open3($inh,$outh,$errh,$query );
 
145
    my @times =() ;
 
146
    $self->{rtts}={};
 
147
    while (<$errh>) {
 
148
        chomp;
 
149
        next unless /^\S+\s+:\s+[\d\.]/; #filter out error messages from fping
 
150
        $self->do_debug("array element=$_ \n");
 
151
        @times = split /\s+/;
 
152
        my $ip = shift @times;
 
153
        next unless ':' eq shift @times; #drop the colon
 
154
        @times = map {sprintf "%.10e", $_ / $self->{pingfactor}} sort {$a <=> $b} grep {$_ ne "-"} @times;
 
155
        map { $self->{rtts}{$_} = [@times] } @{$self->{addrlookup}{$ip}} ;
 
156
    }
 
157
    waitpid $pid,0;
 
158
    close $inh;
 
159
    close $outh;
 
160
    close $errh;
 
161
    return @times;
 
162
}
 
163
 
 
164
1;