jablonka.czprosek.czf

hotsanic

Subversion Repositories:
[/] [branches/] [HotSaNIC-0.5.0-pre6/] [tools/] [rrdtool_add_ds.pl] - Blame information for rev 36

 

Line No. Rev Author Line
11simandl#! /usr/bin/perl
2 
3# add_ds.pl, program to add datasources to an existing RRD
4#
5# Copyright (C) 2000 Selena M. Brewington
6# fixed 30-JUL-2003 by Taylor A. Steil
7# verified working with rrdtool version 1.1.x
8#
9# This program is free software; you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation; either version 2 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program; if not, write to the Free Software
21# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 
23use strict;
24 
25my $ds = shift || die "need number of additional datasources desired";
26if ($ds eq '-h') {
27 &Usage;
28 exit 0;
29 }
30 
31my $default_val = shift || 'NaN';
32my $type = shift || 'GAUGE';
33my $heartbeat = shift || '1800';
34my $rrdmin = shift || '0';
35my $rrdmax = shift || 'NaN';
36 
37my $cdp_prep_start = '<cdp_prep>';
38my $cdp_prep_end = '</cdp_prep>';
39 
40my $row_end = '</row>';
41my $name = '<name>';
42my $name_end = '</name>';
43my $ds_end = '</ds>';
44 
45my $field = '<v> ' . $default_val . ' </v>';
46 
47my $found_ds = 0;
48my $num_sources = 0;
49my $last;
50my $fields = " ";
51my $datasource;
52my $record;
53my $x;
54my $dsData;
55 
56while (<STDIN>) {
57 
58 if (/$cdp_prep_start/) {
59 $record = 1;
60 }
61 elsif ($record) {
62 if (/$ds_end/) {
63 $dsData .= $_;
64 $record = 0;
65 }
66 else {
67 my $line = $_;
68 if ($line =~ s/(<minimal_heartbeat>)(.*?)(<\/minimal_heartbeat>)/$1 $2 $3/) {}
69 elsif ($line =~ s/(<min>)(.*?)(<\/min>)/$1 $rrdmin $3/) {}
70 elsif ($line =~ s/(<max>)(.*?)(<\/max>)/$1 $rrdmax $3/) {}
71 elsif ($line =~ s/(<last_ds>)(.*?)(<\/last_ds>)/$1 UNKN $3/) {}
72 elsif ($line =~ s/(<value>)(.*?)(<\/value>)/$1 $default_val $3/) {}
73 elsif ($line =~ s/(<unknown_sec>)(.*?)(<\/unknown_sec>)/$1 $default_val $3/) {}
74 elsif ($line =~ s/(<primary_value>)(.*?)(<\/primary_value>)/$1 $default_val $3/) {}
75 elsif ($line =~ s/(<secondary_value>)(.*?)(<\/secondary_value>)/$1 $default_val $3/) {}
76 elsif ($line =~ s/(<intercept>)(.*?)(<\/intercept>)/$1 $default_val $3/) {}
77 elsif ($line =~ s/(<last_intercept>)(.*?)(<\/last_intercept>)/$1 $default_val $3/) {}
78 elsif ($line =~ s/(<slope>)(.*?)(<\/slope>)/$1 $default_val $3/) {}
79 elsif ($line =~ s/(<last_slope>)(.*?)(<\/last_slope>)/$1 $default_val $3/) {}
80 elsif ($line =~ s/(<nan_count>)(.*?)(<\/nan_count>)/$1 $default_val $3/) {}
81 elsif ($line =~ s/(<last_nan_count>)(.*?)(<\/last_nan_count>)/$1 $default_val $3/) {}
82 elsif ($line =~ s/(<seasonal>)(.*?)(<\/seasonal>)/$1 $default_val $3/) {}
83 elsif ($line =~ s/(<last_seasonal>)(.*?)(<\/last_seasonal>)/$1 $default_val $3/) {}
84 elsif ($line =~ s/(<init_flag>)(.*?)(<\/init_flag>)/$1 $default_val $3/) {}
85 elsif ($line =~ s/(<history>)(.*?)(<\/history>)/$1 $default_val $3/) {}
86 elsif ($line =~ s/(<unknown_datapoints>)(.*?)(<\/unknown_datapoints>)/$1 $default_val $3/) {}
87 elsif ($line =~ s/(<\w+>)(.*?)(<\/\w+>)/$1 $default_val $3/) {}
88 $dsData .= $line;
89 }
90 }
91 
92 if (($_ =~ s/$row_end$/$fields$row_end/) && $found_ds) {
93 # need to hit <ds> types first, if we don't, we're screwed
94 print $_;
95 }
96 elsif (/$cdp_prep_end/) {
97 print $dsData x $ds;
98 print $_;
99 $dsData = '';
100 }
101 elsif (/$name_end$/) {
102 ($datasource) = /$name (\w+)/;
103 $found_ds++;
104 print $_;
105 }
106 elsif (/Round Robin Archives/) {
107 # print out additional datasource definitions
108 ($num_sources) = ($datasource =~ /(\d+)/);
109 for ($x = $num_sources+1; $x < $num_sources+$ds+1; $x++) {
110 $fields .= $field;
111 print "\n\t<ds>\n";
112 print "\t\t<name> ds$x <\/name>\n";
113 print "\t\t<type> $type <\/type>\n";
114 print "\t\t<minimal_heartbeat> $heartbeat <\/minimal_heartbeat>\n";
115 print "\t\t<min> $rrdmin <\/min>\n";
116 print "\t\t<max> $rrdmax <\/max>\n\n";
117 print "\t\t<!-- PDP Status -->\n";
118 print "\t\t<last_ds> NaN <\/last_ds>\n";
119 print "\t\t<value> 0.0000000000e+00 <\/value>\n";
120 print "\t\t<unknown_sec> NaN <\/unknown_sec>\n";
121 print "\t<\/ds>\n\n";
122 }
123 print $_;
124 }
125 else { print $_; }
126 $last = $_;
127 }
128 
129 
130sub Usage {
131 print "rrdtool_add_ds.pl <add'l ds> [default_val] [type] [heartbeat] [rrdmin] [rrdmax] < file.xml\n";
132 print "\t<add'l ds>\tnumber of additional datasources\n";
133 print "\t[default_val]\tdefault value to be entered in add'l fields\n";
134 print "\t[type]\ttype of datasource (i.e. COUNTER, GAUGE...)\n";
135 print "\t[heatbeat]\tlength of time in seconds before RRD thinks your DS is dead\n";
136 print "\t[rrdmin]\tminimum value allowed for each datasource\n";
137 print "\t[rrdmax]\tmax value allowed for each datasource\n\n";
138 print "\tOptions are read in order, so if you want to change the\n";
139 print "\tdefault heartbeat, you need to specify the default_val and\n";
140 print "\ttype as well, etc.\n";
141 print "\n\tOutput goes to STDOUT.\n";
142 }
143 

Powered by WebSVN 2.2.1