1 #!/usr/local/bin/perl -w
2 #From: Brian K. West <brian@bkw.org>
3 #
4 # snmpwalks all nas boxen specified in the configuration file,
5 # tallies the number of connect speeds, and returns a percentage
6 # of various data sets in the form:
7 #
8 # N:blah:blah:blah:blah:blah:blah
9 #
10 # requires a configuration file specified by $naslist
11 # config file format is:
12 # nas name:community
13 # i.e.
14 # pm1-stigler:communitystring
15 #
16 #
17 # mad propz to teep
18 # Need to redo graphing but hey it works..
19 #
20 use lib qw( /usr/local/rrdtool-1.0.8/lib/perl ../lib/perl );
21 use RRDs;
22 use strict;
24 my($totlines) = 248; # Total Ports
25 my($workdir) = "/export/home/brian/public_html"; # Directory where you want
26 the images copied too
27 my($uptime) = `uptime`; # Uptime is printed on graph
28 my($rrd) = "overall.rrd"; # RRD file name
29 my($target) = "overall"; # Target name(Used for Images)
30 my($option) = "GAUGE"; # This can get COUNTER, GAUGE
31 my($naslist) = "./nas.dat"; # path and name of configuration file
32 my($domain) = "cwis.net"; # your domain name (used for snmpwalk)
33 my($path_to_snmpwalk) = "/usr/local/bin"; # no trailing slash
35 # speed ranges are totally dynamic
36 # ranges are range[x] to ((range[x+1]) - 1)
37 # i.e. 1 to 14399, 14400 to 28799, 28800 to 33599, et al
38 #
41 my(@speed_range) = qw(1 14400 28800 33600 40000 43000 45000 50000 65000);
43 ### nothing else should need configured below this line ###
44 my($cpyfiles);
45 my($ERROR);
46 my($rrdata);
47 my($filetest);
49 $filetest = stat($rrd);
50 if(!$filetest) {
51 RRDs::create ($rrd, "--step",300,
52 "DS:a:$option:600:0:100",
53 "DS:b:$option:600:0:100",
54 "DS:c:$option:600:0:100",
55 "DS:d:$option:600:0:100",
56 "DS:e:$option:600:0:100",
57 "DS:f:$option:600:0:100",
58 "DS:g:$option:600:0:100",
59 "DS:h:$option:600:0:100",
60 "DS:i:$option:600:0:100",
61 "DS:j:$option:600:0:100",
62 "RRA:AVERAGE:0.5:1:600",
63 "RRA:AVERAGE:0.5:6:700",
64 "RRA:AVERAGE:0.5:24:775",
65 "RRA:AVERAGE:0.5:288:797",
66 "RRA:MAX:0.5:1:600 ",
67 "RRA:MAX:0.5:6:700 ",
68 "RRA:MAX:0.5:24:775",
69 "RRA:MAX:0.5:288:797")
70 ;
72 my $ERROR = RRDs::error;
73 die "$0: unable to create `$rrd': $ERROR\n" if $ERROR;
74 }
76 my($num_ranges) = 0;
77 $num_ranges = @speed_range;
78 my(%speeds);
80 open(NASLIST, "<$naslist");
81 my($line);
82 my($foo) = 0;
83 my(@nases);
84 my(%comms);
85 my(@raw_data);
86 my($line_count) = 0;
88 while(defined ($line = <NASLIST>)) {
89 chop $line;
90 my($nas,$community) = split(/:/,$line);
91 $nases[$foo++] = $nas;
92 $comms{$nas} = $community;
93 }
95 my($speed_list);
96 foreach $speed_list (@speed_range) {
97 $speeds{$speed_list} = 0;
98 }
99 undef($speed_list);
101 my(@data,$cnt);
103 foreach $cnt (0 .. $#nases) {
104 my($nas) = $nases[$cnt];
105 @data = `$path_to_snmpwalk/snmpwalk -v 1 $nas.$domain $comms{$nas}
106 interfaces.ifTable.ifEntry.ifSpeed`;
109 my($blah);
110 foreach $blah (@data) {
111 my($a);
112 chomp $blah;
113 (undef,$a) = split(/:/,$blah);
114 $a =~ s/ file://g;
115 if($a > 1 && $a < 65000) {
116 $raw_data[$line_count++] = $a;
117 }
118 }
120 }
122 my($foo3) = 0;
123 my($foo2);
124 foreach $foo2 (@raw_data) {
125 chomp $foo2;
126 my($carrier);
127 ($carrier = $foo2) =~ s/ file://g;
128 my($test);
129 my($i) = 0;
130 foreach $i (0 .. $num_ranges) {
131 if($i+1 < $num_ranges && ($carrier >= $speed_range[$i] && $carrier <=
132 (($speed_range[$i+1])-1)))
133 {
134 $speeds{$speed_range[$i]}++;
135 $foo3++;
137 }
139 }
140 }
142 my($total,$num) = 0;
143 my($key,$value);
144 $rrdata = "N";
145 #print "N";
146 foreach $key (sort keys %speeds) {
147 $num = $speeds{$key};
148 $total = ($num/$line_count)*100;
149 $total = sprintf("%3.2f",$total);
150 $rrdata .=":$total";
151 }
152 #print "$rrdata";
153 my($utilization);
154 $utilization = ($foo3/$totlines)*100;
155 $utilization = sprintf("%3.2f",$utilization);
156 $rrdata .=":$utilization";
157 close(NASLIST);
159 RRDs::update $rrd, "$rrdata";
160 if ($ERROR = RRDs::error) {
161 die "$0: unable to update `$rrd': $ERROR\n";
162 };
164 RRDs::graph "$target-day.gif",
165 "--start", " -86400",
166 "--title", "Modem Carrier Stats.(Daily) - $target",
167 "--rigid",
168 "--width=600",
169 "--height=250",
170 "--upper-limit","100",
171 "--lower-limit","0",
172 "--vertical-label","Percent(%)",
173 "DEF:a=$rrd:a:AVERAGE",
174 "DEF:b=$rrd:b:AVERAGE",
175 "DEF:c=$rrd:c:AVERAGE",
176 "DEF:d=$rrd:d:AVERAGE",
177 "DEF:e=$rrd:e:AVERAGE",
178 "DEF:f=$rrd:f:AVERAGE",
179 "DEF:g=$rrd:g:AVERAGE",
180 "DEF:h=$rrd:h:AVERAGE",
181 "DEF:j=$rrd:j:AVERAGE",
182 "AREA:a#FFFF00: 1-14399",
183 "GPRINT:a:LAST:Current \\: %8.2lf %s",
184 "GPRINT:a:AVERAGE:Avg \\: %8.2lf %s",
185 "GPRINT:a:MIN:Min \\: %8.2lf %s",
186 "GPRINT:a:MAX:Max \\: %8.2lf %s\\n",
187 "STACK:b#C0C0C0:14400-28799",
188 "GPRINT:b:LAST:Current \\: %8.2lf %s",
189 "GPRINT:b:AVERAGE:Avg \\: %8.2lf %s",
190 "GPRINT:b:MIN:Min \\: %8.2lf %s",
191 "GPRINT:b:MAX:Max \\: %8.2lf %s\\n",
192 "STACK:c#FF7E6C:28800-33599",
193 "GPRINT:c:LAST:Current \\: %8.2lf %s",
194 "GPRINT:c:AVERAGE:Avg \\: %8.2lf %s",
195 "GPRINT:c:MIN:Min \\: %8.2lf %s",
196 "GPRINT:c:MAX:Max \\: %8.2lf %s\\n",
197 "STACK:d#6DC8FE:33600-39999",
198 "GPRINT:d:LAST:Current \\: %8.2lf %s",
199 "GPRINT:d:AVERAGE:Avg \\: %8.2lf %s",
200 "GPRINT:d:MIN:Min \\: %8.2lf %s",
201 "GPRINT:d:MAX:Max \\: %8.2lf %s\\n",
202 "STACK:e#00FF00:40000-42999",
203 "GPRINT:e:LAST:Current \\: %8.2lf %s",
204 "GPRINT:e:AVERAGE:Avg \\: %8.2lf %s",
205 "GPRINT:e:MIN:Min \\: %8.2lf %s",
206 "GPRINT:e:MAX:Max \\: %8.2lf %s\\n",
207 "STACK:f#FF00FF:43000-44999",
208 "GPRINT:f:LAST:Current \\: %8.2lf %s",
209 "GPRINT:f:AVERAGE:Avg \\: %8.2lf %s",
210 "GPRINT:f:MIN:Min \\: %8.2lf %s",
211 "GPRINT:f:MAX:Max \\: %8.2lf %s\\n",
212 "STACK:g#FF0000:45000-49999",
213 "GPRINT:g:LAST:Current \\: %8.2lf %s",
214 "GPRINT:g:AVERAGE:Avg \\: %8.2lf %s",
215 "GPRINT:g:MIN:Min \\: %8.2lf %s",
216 "GPRINT:g:MAX:Max \\: %8.2lf %s\\n",
217 "STACK:h#4444FF:50000-65000",
218 "GPRINT:h:LAST:Current \\: %8.2lf %s",
219 "GPRINT:h:AVERAGE:Avg \\: %8.2lf %s",
220 "GPRINT:h:MIN:Min \\: %8.2lf %s",
221 "GPRINT:h:MAX:Max \\: %8.2lf %s\\n",
222 "LINE1:j#000000:Utilization",
223 "GPRINT:j:LAST:Current \\: %8.2lf %s",
224 "GPRINT:j:AVERAGE:Avg \\: %8.2lf %s",
225 "GPRINT:j:MIN:Min \\: %8.2lf %s",
226 "GPRINT:j:MAX:Max \\: %8.2lf %s\\n",
227 "COMMENT:\\n",
228 "COMMENT: Graph Shows Percent of
229 user connected at X Speed.\\n",
230 "COMMENT:\\n",
231 "COMMENT: $uptime",
232 ;
233 if ($ERROR = RRDs::error) {
234 print "ERROR: $ERROR\n";
235 };
236 RRDs::graph "$target-week.gif",
237 "--start", " -604800",
238 "--title", "Modem Carrier Stats.(Weekly) - $target",
239 "--rigid",
240 "--width=600",
241 "--height=250",
242 "--upper-limit","100",
243 "--lower-limit","0",
244 "--vertical-label","Percent(%)",
245 "DEF:a=$rrd:a:AVERAGE",
246 "DEF:b=$rrd:b:AVERAGE",
247 "DEF:c=$rrd:c:AVERAGE",
248 "DEF:d=$rrd:d:AVERAGE",
249 "DEF:e=$rrd:e:AVERAGE",
250 "DEF:f=$rrd:f:AVERAGE",
251 "DEF:g=$rrd:g:AVERAGE",
252 "DEF:h=$rrd:h:AVERAGE",
253 "DEF:j=$rrd:j:AVERAGE",
254 "AREA:a#FFFF00: 1-14399",
255 "GPRINT:a:AVERAGE:Avg \\: %8.2lf %s",
256 "GPRINT:a:MIN:Min \\: %8.2lf %s",
257 "GPRINT:a:MAX:Max \\: %8.2lf %s\\n",
258 "STACK:b#C0C0C0:14400-28799",
259 "GPRINT:b:AVERAGE:Avg \\: %8.2lf %s",
260 "GPRINT:b:MIN:Min \\: %8.2lf %s",
261 "GPRINT:b:MAX:Max \\: %8.2lf %s\\n",
262 "STACK:c#FF7E6C:28800-33599",
263 "GPRINT:c:AVERAGE:Avg \\: %8.2lf %s",
264 "GPRINT:c:MIN:Min \\: %8.2lf %s",
265 "GPRINT:c:MAX:Max \\: %8.2lf %s\\n",
266 "STACK:d#6DC8FE:33600-39999",
267 "GPRINT:d:AVERAGE:Avg \\: %8.2lf %s",
268 "GPRINT:d:MIN:Min \\: %8.2lf %s",
269 "GPRINT:d:MAX:Max \\: %8.2lf %s\\n",
270 "STACK:e#00FF00:40000-42999",
271 "GPRINT:e:AVERAGE:Avg \\: %8.2lf %s",
272 "GPRINT:e:MIN:Min \\: %8.2lf %s",
273 "GPRINT:e:MAX:Max \\: %8.2lf %s\\n",
274 "STACK:f#FF00FF:43000-44999",
275 "GPRINT:f:AVERAGE:Avg \\: %8.2lf %s",
276 "GPRINT:f:MIN:Min \\: %8.2lf %s",
277 "GPRINT:f:MAX:Max \\: %8.2lf %s\\n",
278 "STACK:g#FF0000:45000-49999",
279 "GPRINT:g:AVERAGE:Avg \\: %8.2lf %s",
280 "GPRINT:g:MIN:Min \\: %8.2lf %s",
281 "GPRINT:g:MAX:Max \\: %8.2lf %s\\n",
282 "STACK:h#4444FF:50000-65000",
283 "GPRINT:h:AVERAGE:Avg \\: %8.2lf %s",
284 "GPRINT:h:MIN:Min \\: %8.2lf %s",
285 "GPRINT:h:MAX:Max \\: %8.2lf %s\\n",
286 "LINE1:j#000000:Utilization",
287 "GPRINT:j:AVERAGE:Avg \\: %8.2lf %s",
288 "GPRINT:j:MIN:Min \\: %8.2lf %s",
289 "GPRINT:j:MAX:Max \\: %8.2lf %s\\n",
290 "COMMENT:\\n",
291 "COMMENT: Graph Shows Percent of
292 user connected at X Speed.\\n",
293 "COMMENT:\\n",
294 "COMMENT: $uptime",
295 ;
296 if ($ERROR = RRDs::error) {
297 print "ERROR: $ERROR\n";
298 };
299 RRDs::graph "$target-month.gif",
300 "--start", " -2600640",
301 "--title", "Modem Carrier Stats.(Monthly) - $target",
302 "--rigid",
303 "--width=600",
304 "--height=250",
305 "--upper-limit","100",
306 "--lower-limit","0",
307 "--vertical-label","Percent(%)",
308 "DEF:a=$rrd:a:AVERAGE",
309 "DEF:b=$rrd:b:AVERAGE",
310 "DEF:c=$rrd:c:AVERAGE",
311 "DEF:d=$rrd:d:AVERAGE",
312 "DEF:e=$rrd:e:AVERAGE",
313 "DEF:f=$rrd:f:AVERAGE",
314 "DEF:g=$rrd:g:AVERAGE",
315 "DEF:h=$rrd:h:AVERAGE",
316 "DEF:j=$rrd:j:AVERAGE",
317 "AREA:a#FFFF00: 1-14399",
318 "GPRINT:a:AVERAGE:Avg \\: %8.2lf %s",
319 "GPRINT:a:MIN:Min \\: %8.2lf %s",
320 "GPRINT:a:MAX:Max \\: %8.2lf %s\\n",
321 "STACK:b#C0C0C0:14400-28799",
322 "GPRINT:b:AVERAGE:Avg \\: %8.2lf %s",
323 "GPRINT:b:MIN:Min \\: %8.2lf %s",
324 "GPRINT:b:MAX:Max \\: %8.2lf %s\\n",
325 "STACK:c#FF7E6C:28800-33599",
326 "GPRINT:c:AVERAGE:Avg \\: %8.2lf %s",
327 "GPRINT:c:MIN:Min \\: %8.2lf %s",
328 "GPRINT:c:MAX:Max \\: %8.2lf %s\\n",
329 "STACK:d#6DC8FE:33600-39999",
330 "GPRINT:d:AVERAGE:Avg \\: %8.2lf %s",
331 "GPRINT:d:MIN:Min \\: %8.2lf %s",
332 "GPRINT:d:MAX:Max \\: %8.2lf %s\\n",
333 "STACK:e#00FF00:40000-42999",
334 "GPRINT:e:AVERAGE:Avg \\: %8.2lf %s",
335 "GPRINT:e:MIN:Min \\: %8.2lf %s",
336 "GPRINT:e:MAX:Max \\: %8.2lf %s\\n",
337 "STACK:f#FF00FF:43000-44999",
338 "GPRINT:f:AVERAGE:Avg \\: %8.2lf %s",
339 "GPRINT:f:MIN:Min \\: %8.2lf %s",
340 "GPRINT:f:MAX:Max \\: %8.2lf %s\\n",
341 "STACK:g#FF0000:45000-49999",
342 "GPRINT:g:AVERAGE:Avg \\: %8.2lf %s",
343 "GPRINT:g:MIN:Min \\: %8.2lf %s",
344 "GPRINT:g:MAX:Max \\: %8.2lf %s\\n",
345 "STACK:h#4444FF:50000-65000",
346 "GPRINT:h:AVERAGE:Avg \\: %8.2lf %s",
347 "GPRINT:h:MIN:Min \\: %8.2lf %s",
348 "GPRINT:h:MAX:Max \\: %8.2lf %s\\n",
349 "LINE1:j#000000:Utilization",
350 "GPRINT:j:AVERAGE:Avg \\: %8.2lf %s",
351 "GPRINT:j:MIN:Min \\: %8.2lf %s",
352 "GPRINT:j:MAX:Max \\: %8.2lf %s\\n",
353 "COMMENT:\\n",
354 "COMMENT: Graph Shows Percent of
355 user connected at X Speed.\\n",
356 "COMMENT:\\n",
357 "COMMENT: $uptime",
358 ;
359 if ($ERROR = RRDs::error) {
360 print "ERROR: $ERROR\n";
361 };
362 RRDs::graph "$target-year.gif",
363 "--start", " -31557600",
364 "--title", "Modem Carrier Stats.(Yearly) - $target",
365 "--rigid",
366 "--width=600",
367 "--height=250",
368 "--upper-limit","100",
369 "--lower-limit","0",
370 "--vertical-label","Percent(%)",
371 "DEF:a=$rrd:a:AVERAGE",
372 "DEF:b=$rrd:b:AVERAGE",
373 "DEF:c=$rrd:c:AVERAGE",
374 "DEF:d=$rrd:d:AVERAGE",
375 "DEF:e=$rrd:e:AVERAGE",
376 "DEF:f=$rrd:f:AVERAGE",
377 "DEF:g=$rrd:g:AVERAGE",
378 "DEF:h=$rrd:h:AVERAGE",
379 "DEF:j=$rrd:j:AVERAGE",
380 "AREA:a#FFFF00: 1-14399",
381 "GPRINT:a:AVERAGE:Avg \\: %8.2lf %s",
382 "GPRINT:a:MIN:Min \\: %8.2lf %s",
383 "GPRINT:a:MAX:Max \\: %8.2lf %s\\n",
384 "STACK:b#C0C0C0:14400-28799",
385 "GPRINT:b:AVERAGE:Avg \\: %8.2lf %s",
386 "GPRINT:b:MIN:Min \\: %8.2lf %s",
387 "GPRINT:b:MAX:Max \\: %8.2lf %s\\n",
388 "STACK:c#FF7E6C:28800-33599",
389 "GPRINT:c:AVERAGE:Avg \\: %8.2lf %s",
390 "GPRINT:c:MIN:Min \\: %8.2lf %s",
391 "GPRINT:c:MAX:Max \\: %8.2lf %s\\n",
392 "STACK:d#6DC8FE:33600-39999",
393 "GPRINT:d:AVERAGE:Avg \\: %8.2lf %s",
394 "GPRINT:d:MIN:Min \\: %8.2lf %s",
395 "GPRINT:d:MAX:Max \\: %8.2lf %s\\n",
396 "STACK:e#00FF00:40000-42999",
397 "GPRINT:e:AVERAGE:Avg \\: %8.2lf %s",
398 "GPRINT:e:MIN:Min \\: %8.2lf %s",
399 "GPRINT:e:MAX:Max \\: %8.2lf %s\\n",
400 "STACK:f#FF00FF:43000-44999",
401 "GPRINT:f:AVERAGE:Avg \\: %8.2lf %s",
402 "GPRINT:f:MIN:Min \\: %8.2lf %s",
403 "GPRINT:f:MAX:Max \\: %8.2lf %s\\n",
404 "STACK:g#FF0000:45000-49999",
405 "GPRINT:g:AVERAGE:Avg \\: %8.2lf %s",
406 "GPRINT:g:MIN:Min \\: %8.2lf %s",
407 "GPRINT:g:MAX:Max \\: %8.2lf %s\\n",
408 "STACK:h#4444FF:50000-65000",
409 "GPRINT:h:AVERAGE:Avg \\: %8.2lf %s",
410 "GPRINT:h:MIN:Min \\: %8.2lf %s",
411 "GPRINT:h:MAX:Max \\: %8.2lf %s\\n",
412 "LINE1:j#000000:Utilization",
413 "GPRINT:j:AVERAGE:Avg \\: %8.2lf %s",
414 "GPRINT:j:MIN:Min \\: %8.2lf %s",
415 "GPRINT:j:MAX:Max \\: %8.2lf %s\\n",
416 "COMMENT:\\n",
417 "COMMENT: Graph Shows Percent of
418 user connected at X Speed.\\n",
419 "COMMENT:\\n",
420 "COMMENT: $uptime",
421 ;
422 if ($ERROR = RRDs::error) {
423 print "ERROR: $ERROR\n";
424 };
427 $cpyfiles = `cp -f *.gif $workdir`;
428 exit;