#! @PERL@ # add_ds.pl, program to add datasources to an existing RRD # # Copyright (C) 2000 Selena M. Brewington # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. use strict; my $ds = shift || die "need number of additional datasources desired"; if ($ds eq '-h') { &Usage; exit 0; } my $default_val = shift || 'NaN'; my $type = shift || 'COUNTER'; my $heartbeat = shift || '1800'; my $rrdmin = shift || 'NaN'; my $rrdmax = shift || 'NaN'; my $cdp_prep_end = ''; my $row_end = ''; my $name = ''; my $name_end = ''; my $field = ' ' . $default_val . ' '; my $found_ds = 0; my $num_sources = 0; my $last; my $fields = " "; my $datasource; my $x; while () { if (($_ =~ s/$row_end$/$fields$row_end/) && $found_ds) { # need to hit types first, if we don't, we're screwed print $_; } elsif (/$cdp_prep_end/) { print "\t\t\t NaN 0 \n" x $ds; print $_; } elsif (/$name_end$/) { ($datasource) = /$name (\w+)/; $found_ds++; print $_; } elsif (/Round Robin Archives/) { # print out additional datasource definitions ($num_sources) = ($datasource =~ /(\d+)/); for ($x = $num_sources+1; $x < $num_sources+$ds+1; $x++) { $fields .= $field; print "\n\t\n"; print "\t\t ds$x <\/name>\n"; print "\t\t $type <\/type>\n"; print "\t\t $heartbeat <\/minimal_heartbeat>\n"; print "\t\t $rrdmin <\/min>\n"; print "\t\t $rrdmax <\/max>\n\n"; print "\t\t\n"; print "\t\t NaN <\/last_ds>\n"; print "\t\t NaN <\/value>\n"; print "\t\t NaN <\/unknown_sec>\n"; print "\t<\/ds>\n\n"; } print $_; } else { print $_; } $last = $_; } sub Usage { print "add-ds.pl [default_val] [type] [heartbeat] [rrdmin] [rrdmax] < file.xml\n"; print "\t\tnumber of additional datasources\n"; print "\t[default_val]\tdefault value to be entered in add'l fields\n"; print "\t[type]\ttype of datasource (i.e. COUNTER, GAUGE...)\n"; print "\t[heatbeat]\tlength of time in seconds before RRD thinks your DS is dead\n"; print "\t[rrdmin]\tminimum value allowed for each datasource\n"; print "\t[rrdmax]\tmax value allowed for each datasource\n\n"; print "\tOptions are read in order, so if you want to change the\n"; print "\tdefault heartbeat, you need to specify the default_val and\n"; print "\ttype as well, etc.\n"; print "\n\tOutput goes to STDOUT.\n"; }