[rrd-users] Script for restore/dump values from different rrd databases

Shipley, Rob rshipley at state.mt.us
Thu Feb 7 17:23:34 MET 2002


Here is a script that may help provide a way to get values from one rrd
database to another. rrdtool users have asked about how to do this. i.e.
migrating from one frontend to another. 
_________________Start____________________________
#!c:\perl\bin\perl -w
#Written Feb-6-2002 -RJ Shipley
#This is to help spark ideas in the rrdtool community
#Is useful if migrating from one rrdtool frontend to another
#i.e: I am using this script to dump values from Cricket to MRTG or
visaversa.
#It does take a while to write the file, but it works
#Not totally adept at perl, so please advise if other way
#Will be looking at XML-Twig in the future - fast XML parser
#Please use as you wish, but if you change, let me know so I can clean it
up.
#This script will take two xml files, a main xml and one with values you
want to import
#The intent is to get the values from another rrd if your existing rrd
database has
# a bunch of NaN values.
#As is, it must have the same number and order of DS'es but that's it. 
#It does determine pdp and cf but not the number of values per row.
#You WILL have to modify to match your xml files that have varying DS'es 
#This script uses regular expressions for both source/target xml dumped
files.
#Make sure that the search string is the same in both rrdtool dumps. 
#usage <script> <file to import into> <file with values> <tmp file with
results>
# Run a rrdtool restore on the <tmp file with results>
#This script is distributed without warranty of any kind, modify and use at
own risk
#Verify data before restoring over existing rrd databases!
#uncomment line "print "value:$vcf,$vpdp,$vds0,$vds1
->main:$mcf,$mpdp,$mds0,$mds1\n";" to verify data
$target = $ARGV[0];
$getvalues = $ARGV[1];
$tmpfile = $ARGV[2];
$mpdp = "undef";
$mcf = "undef";
$vcf = "unknown";
$vpdp = "unknown";
$noval = 'NaN';
open (MAIN, $target)|| die "cannot open the main target file.\n";
open (TMP, ">$tmpfile")|| die "cannot open temp write file.\n";
#Loop through the xml file from the main rrd file you want values imported
into
while (<MAIN>)
{
$mainin = $_;
if ($mainin =~ m/<cf>\s(.*?)\s<\/cf>/){$mcf = $1;};
if ($mainin =~ m/<pdp_per_row>\s(.*?)\s<\/pdp_per_row>/){$mpdp = $1;}; 
#Change the following line if your main xml has different DSes
if ($mainin =~
m/^\t\t\t<!--\s(.*?)\s(.*?)\s\w*\s\w*\s\w*\s-->\s<row><v>\s(.*?)\s<\/v><v>\s
(.*?)\s<\/v><\/row>$/)
{
($mdate,$mtime,$mds0,$mds1)=($1,$2,$3,$4); if(($mds0 eq $noval) || ($mds1 eq
$noval))
{
open (VALUES, $getvalues)|| die "cannot open file for new values.\n";
while (<VALUES>)
{
$valuein = $_;
if ($valuein =~ m/<cf>\s(.*?)\s<\/cf>/){$vcf = $1;}
if ($valuein =~ m/<pdp_per_row>\s(.*?)\s<\/pdp_per_row>/){$vpdp = $1;}
if (($vcf eq $mcf) && ($vpdp eq $mpdp))
{
if ($valuein =~
m/^\t\t\t<!--\s$mdate\s$mtime\s\w*\s\w*\s\w*\s-->\s<row><v>\s(.*?)\s<\/v><v>
\s(.*?)\s<\/v><\/row>$/)
{ ($vds0,$vds1)=($1,$2); 
if(($vds0 ne $noval) && ($vds1 ne $noval)){
$mainin = $valuein;
#Uncomment the following line to write STDOUT data to see values being
replaced
#print "value:$vcf,$vpdp,$vds0,$vds1 ->main:$mcf,$mpdp,$mds0,$mds1\n";
}
}
}
}
close(VALUES);
}}print TMP $mainin;
}
close(MAIN);
____________________End_________________________

--
Unsubscribe mailto:rrd-users-request at list.ee.ethz.ch?subject=unsubscribe
Help        mailto:rrd-users-request at list.ee.ethz.ch?subject=help
Archive     http://www.ee.ethz.ch/~slist/rrd-users
WebAdmin    http://www.ee.ethz.ch/~slist/lsg2.cgi



More information about the rrd-users mailing list