[smokeping-users] Re: Patch for SSH.pm
Igor Petrovski
pigor at mm.st
Sat Dec 10 20:51:58 MET 2005
Igor Petrovski wrote:
> Niko Tyni wrote:
>
>> Thanks! This will be in the next release.
>>
>> I'm wondering, though, whether it would be smarter to use Time::HiRes
>> instead of POSIX::times(), to get a better time resolution. 100 ticks
>> per second seems a bit coarse...
>>
>>
>
> Changed to Time::HiRes and cleaned-up a little.
>
>
This one actually works. I should test better before posting. Please
ignore the previous patch.
--- SSH.pm.original 2005-12-07 00:57:15.000000000 -0500
+++ SSH.pm 2005-12-10 14:39:18.000000000 -0500
@@ -19,7 +19,7 @@
use IPC::Open3;
use Symbol;
use Carp;
-use POSIX;
+use Time::HiRes qw(gettimeofday tv_interval);
sub pod_hash {
return {
@@ -31,8 +31,12 @@
point to your copy of the ssh-keyscan program. If it is not installed on
your system yet, you should install openssh >= 3.8p1
-The Probe asks the given host n-times for it's public key. Where n is
+The Probe asks the given host n-times for it's public key, where n is
the amount specified in the config File.
+
+As part of the initialization, the probe asks localhost for it's public key
+and tries to parse the output. Make sure you have SSH running on the
+localhost as well.
DOC
authors => <<'DOC',
Christian Recktenwald <smokeping-contact at citecs.de>
@@ -51,10 +55,9 @@
# no need for this if we run as a cgi
unless ( $ENV{SERVER_SOFTWARE} ) {
- my $call = "$self->{properties}{binary} -t rsa localhost";
+ my $call = "$self->{properties}{binary} -t dsa,rsa,rsa1 localhost";
my $return = `$call 2>&1`;
if ($return =~ m/$ssh_re/s){
- $self->{pingfactor} = 10;
print "### parsing ssh-keyscan output...OK\n";
} else {
croak "ERROR: output of '$call' does not match $ssh_re\n";
@@ -79,27 +82,28 @@
my $host = $target->{addr};
- my $query = "$self->{properties}{binary} -t rsa $host";
+ my $query = "$self->{properties}{binary} -t
$target->{vars}->{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 $t0 = [gettimeofday];
+
my $pid = open3($inh,$outh,$errh, $query);
- while (<$outh>) {
- if (/$ssh_re/i) {
- last;
- }
- }
+ while (<$errh>) {
+ if (/$ssh_re/i) {
+ push @times, tv_interval($t0);
+ last;
+ }
+ }
waitpid $pid,0;
close $errh;
close $inh;
close $outh;
- my @times2 = POSIX::times;
- push @times, $times2[0]-$times1[0];
+
}
- @times = map {sprintf "%.10e", $_ / $self->{pingfactor}} sort {$a
<=> $b} grep {$_ ne "-"} @times;
+ @times = map {sprintf "%.10e", $_ } sort {$a <=> $b} @times;
# $self->do_debug("time=@times\n");
return @times;
@@ -121,4 +125,14 @@
})
}
+sub targetvars {
+ my $class = shift;
+ return $class->_makevars($class->SUPER::targetvars, {
+ keytype => {
+ _doc => "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