A script to parse your RRD and import it into cacti

Templates, scripts for templates, scripts and requests for templates.

Moderators: Developers, Moderators

Post Reply
yid
Cacti User
Posts: 83
Joined: Sat Apr 20, 2002 8:26 pm

A script to parse your RRD and import it into cacti

Post by yid »

http://www.birch.net/~spiegela/import_rrd_cacti

Right now what this script does is takes as argument your rrd filename(s) (without absolute path). Then it takes both the RRAs, and DSs using "rrdtool info" (well the perl libs anyway) into a hash.

Then checks for an existing RRA, if it doesn't exist inserts the new one.
Then checks for the existing DS, if it doesn't exist inserts the new one. Then RRD filename minus the ".rrd" is the parent DS, and the sources in the file are the children. It supports undefined Min/Max (after you change the field in the DB from *integer to char).
Then checks for existing links fromthe DS to the RRA, if they don't exist, it inserts them.

It doesn't, however, create the links from the RRA to the CFs, but I figure that's very little manual effort.

import_rrd_cacti is written in perl, and requires the following modules:
RRDs (from http://www.rrdtool.org)
DBI
DBD::mysql

It requires that you specify the username, password, and the directory in which the rrd files reside at the top of the script. Also it assumes that your database name is "cacti". If not you can change it where the script says $dbh->connect (near the bottom).

I haven't cleaned it up, or tested it thouroughly, but it works just fine on all of my rrds.

Anyway let me know what you think, or if you have any ideas/suggestions.

Aaron
Last edited by yid on Wed May 01, 2002 5:18 pm, edited 1 time in total.
yid
Cacti User
Posts: 83
Joined: Sat Apr 20, 2002 8:26 pm

Post by yid »

I've found one bug myself so far. For some reason cacti doesn't like it when your RRAIDs don't begin with and ID of 1, and I don't know yet how to make sure when I insert into the DB that it starts with 1.

Not too hard to change with phpMyAdmin, but I'll have to fix that...
khemir
Posts: 27
Joined: Sun May 12, 2002 12:56 am
Location: Guadalajara, Jalisco, Mexico
Contact:

Sintaxis

Post by khemir »

Hi....

How run the script...?? how is the sintaxis..??

this i do:

perl clon.pl

and return the prompt......... :cry:
Define ternura...
Guest

Post by Guest »

supply the rrd filenames without absolute paths as arguments.

import_cacti.pl filename.rrd filename2.rrd ...
khemir
Posts: 27
Joined: Sun May 12, 2002 12:56 am
Location: Guadalajara, Jalisco, Mexico
Contact:

Stpe errror

Post by khemir »

Hi...
i am triying this:

decadente# perl clon.pl igdew068_disco_c.rrd igdew069_disco_c.rrd
DBD::mysql::st execute failed: Column 'Step' cannot be null at clon.pl line 99.
Can't execute SQL statement: Column 'Step' cannot be null

any idea thanks
Define ternura...
yid
Cacti User
Posts: 83
Joined: Sat Apr 20, 2002 8:26 pm

Post by yid »

hmmm. Can't see why you would get that error.

I'm setting $step as a global variable in the "get_rrd_info" subroutine from the rrds::info hash (if that means anything to you).

I haven't been able to replicate it, and I know I was lazy using global vars and all.

Try this for me, please (if you don't mind):

You should have the Data::Dumper perl module installed, so try putting

Code: Select all

 print Dumper($info);
at the end of the get_rrd_info subroutine, and send me the output (you can send that to me in email if you like, we don't need the whole world seeing your rrd info, spiegela@birch.net). To make it easy, you can put that line just before

Code: Select all

return(\%ds, \%rra);
I know my little script is clumsy, and pretty dorky. I promise I'll clean it up and put some gonads on it, but I must balance open source, a job, and even a family life (geez). Hopefully my boss'll give me more time to work on it later.

Send me that output, though, and we'll see why $step isn't getting through. Oh, also if you like, you can make the script even dorkier, and set $step right before the sth_ins_parent statement handle. Just insert

Code: Select all

$step=<your step in secs>; 


right before:

Code: Select all

        my $sth_ins_parent = $dbh->prepare("
                INSERT into rrd_ds
                ( `Name`, `Active`, `DSPath`, `Heartbeat`, `Step`, `IsParent` )
                values ( " . $dbh->quote($rrdname) . ", 1,  " . $dbh->quote($rrdpath) . ", 100, " . $dbh->quote($step) . ", 1 )
        ");
Let me know how it goes, whatever you decide to do. And let me know if this thing helps.

Aaron
yid
Cacti User
Posts: 83
Joined: Sat Apr 20, 2002 8:26 pm

Post by yid »

Made some minor bug fixes. Haven't had time yet to dig in and make it more efficient, tho. Still there at:
http://www.birch.net/~spiegela/import_rrd_cacti
Stoo
Posts: 1
Joined: Sun Dec 19, 2004 9:34 pm

Does anyone have a copy of import_rrd_cacti ?

Post by Stoo »

I am looking for a script to migrate an existing MRTG/RRD installation to Cacti. This seems to have been done and posted at an extinct locatiion:
http://www.birch.net/~spiegela/import_rrd_cacti

Does anyone have this script? Can you attach it to this forum.
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests