summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Smokeping.pm25
-rw-r--r--lib/Smokeping/probes/base.pm33
2 files changed, 48 insertions, 10 deletions
diff --git a/lib/Smokeping.pm b/lib/Smokeping.pm
index 18415f4..a14699f 100644
--- a/lib/Smokeping.pm
+++ b/lib/Smokeping.pm
@@ -110,6 +110,11 @@ sub lnk ($$) {
}
}
+sub dyndir ($) {
+ my $cfg = shift;
+ return $cfg->{General}{dyndir} || $cfg->{General}{datadir};
+}
+
sub update_dynaddr ($$){
my $cfg = shift;
my $q = shift;
@@ -125,7 +130,12 @@ sub update_dynaddr ($$){
return "Error: Invalid target or secret"
unless defined $targetptr->{host} and
$targetptr->{host} eq "DYNAMIC/${secret}";
- my $file = $cfg->{General}{datadir}."/".(join "/", @target);
+ my $file = dyndir($cfg);
+ for (0..$#target-1) {
+ $file .= "/" . $target[$_];
+ ( -d $file ) || mkdir $file, 0755;
+ }
+ $file.= "/" . $target[-1];
my $prevaddress = "?";
my $snmp = snmpget_ident $address;
if (-r "$file.adr" and not -z "$file.adr"){
@@ -852,7 +862,7 @@ sub get_detail ($$$$){
);
# if we have uptime draw a colorful background or the graph showing the uptime
- my $cdir=$cfg->{General}{datadir}."/".(join "/", @dirs)."/";
+ my $cdir=dyndir($cfg)."/".(join "/", @dirs)."/";
if (-f "$cdir/${file}.adr") {
@upsmoke = ();
@upargs = ("COMMENT:Link Up${BS}: ",
@@ -1567,7 +1577,7 @@ DOC
General configuration values valid for the whole SmokePing setup.
DOC
_vars =>
- [ qw(owner imgcache imgurl datadir pagedir piddir sendmail offset
+ [ qw(owner imgcache imgurl datadir dyndir pagedir piddir sendmail offset
smokemail cgiurl mailhost contact netsnpp
syslogfacility syslogpriority concurrentprobes changeprocessnames tmail) ],
_mandatory =>
@@ -1637,7 +1647,16 @@ DOC
The directory where SmokePing can keep its rrd files.
DOC
},
+ dyndir =>
+ {
+ %$DIRCHECK_SUB,
+ _doc => <<DOC,
+The base directory where SmokePing keeps the files related to the DYNAMIC function.
+This directory must be writeable by the WWW server.
+If this variable is not specified, the value of C<datadir> will be used instead.
+DOC
+ },
piddir =>
{
%$DIRCHECK_SUB,
diff --git a/lib/Smokeping/probes/base.pm b/lib/Smokeping/probes/base.pm
index a322a21..c0525b6 100644
--- a/lib/Smokeping/probes/base.pm
+++ b/lib/Smokeping/probes/base.pm
@@ -90,6 +90,23 @@ sub ProbeDesc ($) {
return "Probe which does not overrivd the ProbeDesc methode";
}
+sub target2dynfile ($$) {
+ # the targets are stored in the $self->{targets}
+ # hash as filenames pointing to the RRD files
+ #
+ # now that we use a (optionally) different dir for the
+ # . adr files, we need to derive the .adr filename
+ # from the RRD filename with a simple substitution
+
+ my $self = shift;
+ my $target = shift; # filename with <datadir> embedded
+ my $dyndir = $self->{cfg}{General}{dyndir};
+ return $target unless defined $dyndir; # nothing to do
+ my $datadir = $self->{cfg}{General}{datadir};
+ $target =~ s/^\Q$datadir\E/$dyndir/;
+ return $target;
+}
+
sub rrdupdate_string($$)
{ my $self = shift;
my $tree = shift;
@@ -107,17 +124,18 @@ sub rrdupdate_string($$)
my $upperloss = $loss - $lowerloss;
@times = ((map {'U'} 1..$lowerloss),@times, (map {'U'} 1..$upperloss));
my $age;
- if ( -f $self->{targets}{$tree}.".adr" ) {
- $age = time - (stat($self->{targets}{$tree}.".adr"))[9];
+ my $dynbase = $self->target2dynfile($self->{targets}{$tree});
+ if ( -f $dynbase.".adr" ) {
+ $age = time - (stat($dynbase.".adr"))[9];
} else {
$age = 'U';
}
if ( $entries == 0 ){
$age = 'U';
$loss = 'U';
- if ( -f $self->{targets}{$tree}.".adr"
- and not -f $self->{targets}{$tree}.".snmp" ){
- unlink $self->{targets}{$tree}.".adr";
+ if ( -f $dynbase.".adr"
+ and not -f $dynbase.".snmp" ){
+ unlink $dynbase.".adr";
}
} ;
return "${age}:${loss}:${median}:".(join ":", @times);
@@ -131,12 +149,13 @@ sub addresses($)
foreach my $tree (keys %{$self->{targets}}){
my $target = $self->{targets}{$tree};
if ($target =~ m|/|) {
- if ( open D, "<$target.adr" ) {
+ my $dynbase = $self->target2dynfile($target);
+ if ( open D, "<$dynbase.adr" ) {
my $ip;
chomp($ip = <D>);
close D;
- if ( open D, "<$target.snmp" ) {
+ if ( open D, "<$dynbase.snmp" ) {
my $snmp = <D>;
chomp($snmp);
if ($snmp ne Smokeping::snmpget_ident $ip) {