From 3946df708ae20686c8453eb55be934103daf2f7e Mon Sep 17 00:00:00 2001 From: Niko Tyni Date: Sun, 4 Sep 2005 11:34:08 +0000 Subject: * lib/Smokeping.pm, lib/Smokeping/probes/base.pm, doc/smokeping_upgrade.pod, TODO, CHANGES: + the DYNAMIC-related files (.adr and .snmp) can now be located outside "datadir" by specifying the new configuration variable "dyndir" --- CHANGES | 5 ++++- TODO | 5 ----- doc/smokeping_upgrade.pod | 11 +++++++++++ lib/Smokeping.pm | 25 ++++++++++++++++++++++--- lib/Smokeping/probes/base.pm | 33 ++++++++++++++++++++++++++------- 5 files changed, 63 insertions(+), 16 deletions(-) diff --git a/CHANGES b/CHANGES index bb48678..cf9ca75 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,8 @@ +* the DYNAMIC-related files (.adr and .snmp) can now be located outside "datadir" + by specifying the new configuration variable "dyndir" + -- niko, suggested by Marc Haber * return '404 not found' when DYNAMIC updates fail - - niko, suggested by Marc Haber + -- niko, suggested by Marc Haber * make errors in DYNAMIC updates appear in the web server error log -- niko * remove a quotemeta() call in Config::Grammar to allow metacharacters diff --git a/TODO b/TODO index 625350f..9c13ca2 100644 --- a/TODO +++ b/TODO @@ -41,8 +41,3 @@ - suggested by Leos Bitto, -* CONFIG - make the .adr (and .snmp) directory configurable - - suggested by Marc Haber, - - diff --git a/doc/smokeping_upgrade.pod b/doc/smokeping_upgrade.pod index 61277fc..df5013b 100644 --- a/doc/smokeping_upgrade.pod +++ b/doc/smokeping_upgrade.pod @@ -119,6 +119,17 @@ C variable in your configuration file. You'll then have to delete the old RRD file or somehow convert it to use the new parameters. The C command might be helpful here. +=item Configurable location for DYNAMIC-related files + +There is now a new configuration variable, C, that can be used +to specify the location of the DYNAMIC-related files (.adr and .snmp). +These files used to be kept under C along with the RRD files, +but since they need to be writable by the web server, it may be useful +to separate these. + +If C is not specified, Smokeping will use the C value +as the default. This should ensure that no existing setups will break. + =back In addition to this, some probes have had minor incompatible changes to 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 => < 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 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 = ); close D; - if ( open D, "<$target.snmp" ) { + if ( open D, "<$dynbase.snmp" ) { my $snmp = ; chomp($snmp); if ($snmp ne Smokeping::snmpget_ident $ip) { -- cgit v1.2.3-24-g4f1b