diff options
author | Niko Tyni <ntyni@iki.fi> | 2005-09-04 13:34:08 +0200 |
---|---|---|
committer | Niko Tyni <ntyni@iki.fi> | 2005-09-04 13:34:08 +0200 |
commit | 3946df708ae20686c8453eb55be934103daf2f7e (patch) | |
tree | 68e64811e0f13e97ddd3f5b399ea78bfe964e9bb | |
parent | 733f5ee3d4aad0c1a21d796d5a36baa82389e199 (diff) | |
download | smokeping-3946df708ae20686c8453eb55be934103daf2f7e.tar.gz smokeping-3946df708ae20686c8453eb55be934103daf2f7e.tar.xz |
* 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"
-rw-r--r-- | CHANGES | 5 | ||||
-rw-r--r-- | TODO | 5 | ||||
-rw-r--r-- | doc/smokeping_upgrade.pod | 11 | ||||
-rw-r--r-- | lib/Smokeping.pm | 25 | ||||
-rw-r--r-- | lib/Smokeping/probes/base.pm | 33 |
5 files changed, 63 insertions, 16 deletions
@@ -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 <mh+smokeping-users *zugschlus.de> * return '404 not found' when DYNAMIC updates fail - - niko, suggested by Marc Haber <mh+smokeping-users *zugschlus.de> + -- niko, suggested by Marc Haber <mh+smokeping-users *zugschlus.de> * make errors in DYNAMIC updates appear in the web server error log -- niko * remove a quotemeta() call in Config::Grammar to allow metacharacters @@ -41,8 +41,3 @@ - suggested by Leos Bitto, <http://lists.ee.ethz.ch/smokeping-users/msg01632.html> -* CONFIG - make the .adr (and .snmp) directory configurable - - suggested by Marc Haber, - <http://lists.ee.ethz.ch/smokeping-users/msg01644.html> - 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<pings> 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<rrdtune> command might be helpful here. +=item Configurable location for DYNAMIC-related files + +There is now a new configuration variable, C<dyndir>, that can be used +to specify the location of the DYNAMIC-related files (.adr and .snmp). +These files used to be kept under C<datadir> 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<dyndir> is not specified, Smokeping will use the C<datadir> 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 => <<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) { |