summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGES5
-rw-r--r--lib/Config/Grammar.pm2
-rw-r--r--lib/Smokeping.pm14
-rw-r--r--lib/Smokeping/probes/SSH.pm43
4 files changed, 42 insertions, 22 deletions
diff --git a/CHANGES b/CHANGES
index e08ce84..e75de57 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,8 @@
+* SSH.pm: new variable 'keytype' + bugfixes
+ - niko, from Igor Petrovski <pigor *mm.st>
+* fix a bug that broke target sections with the same name
+ in different branches -- niko, reported by Igor Petrovski <pigor *mm.st>
+
2005/12/11 -- released version 20051211_trunk
2005/12/10 -- released version 20051210_trunk
diff --git a/lib/Config/Grammar.pm b/lib/Config/Grammar.pm
index bd3deea..835b12b 100644
--- a/lib/Config/Grammar.pm
+++ b/lib/Config/Grammar.pm
@@ -316,7 +316,7 @@ sub _prev_level($)
# section name
if (defined $self->{section}) {
if ($self->{section} =~ /\//) {
- $self->{section} =~ s/\/.*?$//;
+ $self->{section} =~ s,/[^/]*$,,;
}
else {
$self->{section} = undef;
diff --git a/lib/Smokeping.pm b/lib/Smokeping.pm
index c8b1261..1d82aef 100644
--- a/lib/Smokeping.pm
+++ b/lib/Smokeping.pm
@@ -1266,11 +1266,11 @@ sub get_parser () {
my %storedtargetvars;
# the part of target section syntax that doesn't depend on the selected probe
- my %TARGETCOMMON; # predeclare self-referencing structures
+ my $TARGETCOMMON; # predeclare self-referencing structures
# the common variables
my $TARGETCOMMONVARS = [ qw (probe menu title alerts note email host remark rawlog alertee) ];
- %TARGETCOMMON =
- (
+ $TARGETCOMMON =
+ {
_vars => $TARGETCOMMONVARS,
_inherited=> [ qw (probe alerts alertee) ],
_sections => [ "/$KEY_RE/" ],
@@ -1411,7 +1411,7 @@ DOC
delete $targetvars->{$_}{_default} for @targetvars;
# we replace the current grammar altogether
- %$grammar = ( %TARGETCOMMON, %$targetvars );
+ %$grammar = ( %{_deepcopy($TARGETCOMMON)}, %$targetvars );
$grammar->{_vars} = [ @{$grammar->{_vars}}, @targetvars ];
# the subsections differ only in that they inherit their vars from here
@@ -1433,7 +1433,7 @@ DOC
$g->{host}{_dyn} = $mandatorysub;
},
},
- );
+ };
my $INTEGER_SUB = {
_sub => sub {
@@ -2331,7 +2331,7 @@ DOC
_order => 1,
_sections => [ "/$KEY_RE/" ],
_recursive => [ "/$KEY_RE/" ],
- "/$KEY_RE/" => \%TARGETCOMMON, # this is just for documentation, _dyn() below replaces it
+ "/$KEY_RE/" => $TARGETCOMMON, # this is just for documentation, _dyn() below replaces it
probe => {
_doc => <<DOC,
The name of the probe module to be used for this host. The value of
@@ -2358,7 +2358,7 @@ DOC
$grammar->{$_} = $targetvars->{$_};
}
push @{$grammar->{_vars}}, @targetvars;
- my $g = { %TARGETCOMMON, %{_deepcopy($targetvars)} };
+ my $g = { %{_deepcopy($TARGETCOMMON)}, %{_deepcopy($targetvars)} };
$grammar->{"/$KEY_RE/"} = $g;
$g->{_vars} = [ @{$g->{_vars}}, @targetvars ];
$g->{_inherited} = [ @{$g->{_inherited}}, @targetvars ];
diff --git a/lib/Smokeping/probes/SSH.pm b/lib/Smokeping/probes/SSH.pm
index 0f336d6..7756c03 100644
--- a/lib/Smokeping/probes/SSH.pm
+++ b/lib/Smokeping/probes/SSH.pm
@@ -19,7 +19,7 @@ use base qw(Smokeping::probes::basefork);
use IPC::Open3;
use Symbol;
use Carp;
-use POSIX;
+use Time::HiRes qw(gettimeofday tv_interval);
sub pod_hash {
return {
@@ -31,8 +31,12 @@ Integrates ssh-keyscan as a probe into smokeping. The variable B<binary> must
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@citecs.de>
@@ -51,10 +55,9 @@ sub new($$$)
# 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 @@ sub pingone ($){
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,15 @@ sub probevars {
})
}
+sub targetvars {
+ my $class = shift;
+ return $class->_makevars($class->SUPER::targetvars, {
+ keytype => {
+ _doc => "Type of key, used in ssh-keyscan -t <keytype>",
+ _re => "[dt]sa1*",
+ _example => 'dsa',
+ _default => 'rsa',
+ },
+ })
+}
1;