On Fri, Sep 21, 2001 at 03:02:35PM +0200, Patrick Rother wrote:
> When a new rrd files is created all values are undef and new values get
> added.
> I would like to dump all data to xml, replace all values within a given
> time range that are undef with zero, and reimport the data.
> 
> This looks quite easy to do in perl, but it's still some work to implement,
> so before reinventing the wheel I would like to ask if someone has done this
> before who could share the code.

$ cat thewheel.pl
#!/usr/bin/perl -w
use strict;

if (not defined $ARGV[0] or not $ARGV[0]) {
 print STDERR "Usage: $0 rrdfile\n\n";
 exit;
}
my ($file) = @ARGV;
die "rrdfile does not exists.\n" unless (-e $file);        
my $tmp = "zeroize.tmp.$$";
open (OUT, ">$tmp") or die;
open (IN, "rrdtool dump $file |") or die;
my $z = 0;
while (<IN>) {
 if ($z) {
  if (m#^(\s*<!--[^>]*--> <row><v> )NaN( </v><v> )NaN( </v></row>\n)#) {
   $_ = $1.'0'.$2.'0'.$3;
  } else {
   $z = 0;
  }
 } elsif (/^\s*<database>$/) {
  $z = 1;
 }
 print OUT $_;
}
close OUT;
close IN;
print `rrdtool restore $tmp $file -r 2>&1`;
unlink $tmp;
$ 


-- Binary/unsupported file stripped by Listar --
-- Err : No filename to use for decode, file stripped.
-- Type: application/pgp-signature


--
Unsubscribe mailto:[EMAIL PROTECTED]
Help        mailto:[EMAIL PROTECTED]
Archive     http://www.ee.ethz.ch/~slist/rrd-users
WebAdmin    http://www.ee.ethz.ch/~slist/lsg2.cgi

Reply via email to