[smokeping-users] Patch for SSH.pm

Igor Petrovski pigor at mm.st
Sat Dec 10 01:41:31 MET 2005


This is the patch that I'm using for the SSH probe.

It adds another target variable, 'keytype', that specifies the type of 
key to be used. I have
few devices that only respond to queries for 'dsa' keys, so I needed a 
way to pass the param.

It fixes the "pingfactor", which in the original is set to 10. 
POSIX::times reports in clock ticks,
which on my system is 100, so the probe was off by a factor of 10.

It also only reports the time only if it sees $ssh_re on STDERR,  and 
unreachable otherwise.

If this works for other people, I'd appreciate if it can be added to the 
distribution.

Regards,
Igor.
---------------------------------------------------------

--- SSH.pm.original     2005-12-07 00:57:15.000000000 -0500
+++ SSH.pm      2005-12-09 19:24:37.000000000 -0500
@@ -54,7 +54,7 @@
         my $call = "$self->{properties}{binary} -t rsa localhost";
         my $return = `$call 2>&1`;
         if ($return =~ m/$ssh_re/s){
-            $self->{pingfactor} = 10;
+            $self->{pingfactor} = POSIX::sysconf( &POSIX::_SC_CLK_TCK ) 
|| 100 ;
             print "### parsing ssh-keyscan output...OK\n";
         } else {
             croak "ERROR: output of '$call' does not match $ssh_re\n";
@@ -79,25 +79,28 @@

     my $host = $target->{addr};

-    my $query = "$self->{properties}{binary} -t rsa $host";
+    my $query = "$self->{properties}{binary} -t 
$self->{properties}{keytype} $host";
     my @times;

     # get the user and system times before and after the test
     $self->do_debug("query=$query\n");
     for (my $run = 0; $run < $self->pings; $run++) {
        my @times1 = POSIX::times;
+        my $time = '-';  # assume it failed
        my $pid = open3($inh,$outh,$errh, $query);
-       while (<$outh>) {
-           if (/$ssh_re/i) {
-               last;
-           }
-       }
+       while (<$errh>) {
+            if (/$ssh_re/i) {
+                my @times2 = POSIX::times;
+                $time = $times2[0]-$times1[0];
+                last;
+            }
+        }
        waitpid $pid,0;
        close $errh;
        close $inh;
        close $outh;
-       my @times2 = POSIX::times;
-       push @times, $times2[0]-$times1[0];
+
+       push @times, $time;
     }
     @times = map {sprintf "%.10e", $_ / $self->{pingfactor}} sort {$a 
<=> $b} grep {$_ ne "-"} @times;

@@ -121,4 +124,14 @@
        })
 }

+sub targetvars {
+        my $class = shift;
+        return $class->_makevars($class->SUPER::targetvars, {
+           keytype => {
+               _doc => "The type of key, used in ssh-keyscan -t <keytype>",
+               _example => 'dsa',
+                _default => 'rsa',
+           },
+       })
+}
 1;

--
Unsubscribe mailto:smokeping-users-request at list.ee.ethz.ch?subject=unsubscribe
Help        mailto:smokeping-users-request at list.ee.ethz.ch?subject=help
Archive     http://lists.ee.ethz.ch/smokeping-users
WebAdmin    http://lists.ee.ethz.ch/lsg2.cgi



More information about the smokeping-users mailing list