package Smokeping::probes::OpenSSHMikrotikPing; =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 Net::OpenSSH; use Carp; use Data::Dumper; my $e = "="; sub pod_hash { return { name => < < < and L. DOC authors => <<'DOC', Vladimir Ivaschenko Lvi@maks.netL http://www.hazard.maks.net, based on plugins by Tobias Oetiker Ltobi@oetiker.chL, and L by S H A N Lshanali@yahoo.comL. DOC } } sub new($$$) { my $proto = shift; my $class = ref($proto) || $proto; my $self = $class->SUPER::new(@_); # no need for this if we run as a cgi unless ( $ENV{SERVER_SOFTWARE} ) { $self->{pingfactor} = 1000; # Gives us a good-guess default print "### assuming you are using an Mikrotik reporting in milliseconds\n"; }; return $self; } sub ProbeDesc($){ my $self = shift; my $bytes = $self->{properties}{packetsize}; return "Mikrotik - ICMP Echo Pings ($bytes Bytes)"; } sub pingone ($$){ my $self = shift; my $target = shift; my $source = $target->{vars}{source}; my $dest = $target->{vars}{host}; my $psource = $target->{vars}{psource}; my @output = (); my $login = $target->{vars}{mikrotikuser}; my $password = $target->{vars}{mikrotikpass}; my $bytes = $self->{properties}{packetsize}; my $pings = $self->pings($target); my $vrf = $target->{vars}{vrf}; # do NOT call superclass ... the ping method MUST be overwriten my %upd; my @args = (); my $ssh = Net::OpenSSH->new( $source, $login ? ( user => $login ) : (), $password ? ( password => $password ) : (), timeout => 60 ); if ($ssh->error) { warn "OpenSSHMikrotikPing connecting $source: ".$ssh->error."\n"; return undef; }; my $extraparam; if ( $vrf ) { $extraparam .= " routing-table=$vrf "; }; if ( $psource ) { $extraparam .= " src-address=$psource "; }; @output = $ssh->capture("/ping $dest count=$pings size=$bytes $extraparam"); my @times = (); for (@output){ chomp; #10.123.123.1 56 64 60ms /$dest.*\s(\d+)ms/ and push @times,$1; } @times = map {sprintf "%.10e", $_ / $self->{pingfactor}} sort {$a <=> $b} @times; open (F, ">>/tmp/mtik-deb.txt"); print F Dumper(\@output); print F Dumper(\@times); close (F); return @times; } sub probevars { my $class = shift; return $class->_makevars($class->SUPER::probevars, { packetsize => { _doc => < 100, _re => '\d+', _sub => sub { my $val = shift; return "ERROR: packetsize must be between 12 and 64000" unless $val >= 12 and $val <= 64000; return undef; }, }, }); } sub targetvars { my $class = shift; return $class->_makevars($class->SUPER::targetvars, { _mandatory => [ 'mikrotikuser', 'mikrotikpass', 'source' ], source => { _doc => < "192.168.2.1", }, psource => { _doc => < "192.168.2.129", }, mikrotikuser => { _doc => < 'user', }, mikrotikpass => { _doc => < 'password', }, vrf => { _doc => < 'officevrf', }, }); } 1;