Debian Codegraph @

contrib/ovmrtg/ovcullfile

raw
1 #!/usr/local/bin/perl5
2 # -*- mode: Perl -*-
3 ##################################################################
4 # Remove old data from OV_DB files
5 ##################################################################
6 # Created by Laurie Gellatly <[email protected]>
7 # This reads an OV_DB file for the cut off and interface
8 # and calculates how many lines can be removed
9 #################################################################
10 #
11 # Distributed under the GNU copyleft
12 #
13 # $Id: ovcullfile,v 1.1.1.1 2002/02/26 10:16:36 oetiker Exp $
14 #
15 use strict;
16 use vars '$DEBUG';
17 my $ov_db = "/var/opt/OV/share/databases";
18 my $ovdb= $ov_db."/snmpCollect/";
19 my $DEBUG = 0;
20 my($days2keep, $interface, $io , $cutoff) ;
21 my($cnt, $data, $recno, $junk);
22 my @names = ( "IfInErrors", "IfOutErrors",
23 "IfInOctets", "IfOutOctets", "avgBusy5");
24 my @namext = (".err", "", ".cpu");
25 my ($val);
26 my $recsz = 24;
27 my $fsize = -1;
28 my $p = "',\$p'";
29 my $parms = '-F\\t \'{printf("%d\\t%d\\t%s\\t%lg\\n", $4, $5, $6, $3)}\'';
30 my @resu;
31
32 sub main {
33
34 my($extn) = "";
35 $days2keep = $ARGV[0];
36 $interface = $ARGV[1];
37 $io = $ARGV[2];
38 die <<USAGE unless (defined($days2keep) && defined($interface) && defined($io));
39
40 USAGE: ovcullfile '#days Interface# io&errs=1|cpu=0'
41
42 EXAMPLE: ovcullfile 30 4 1
43
44 Delete all data older than 30 days for
45 all interface 4 Input and Output Octets & Errors
46
47
48 USAGE
49 $cutoff = time - ( 3600 * 24 * $days2keep) ;
50 $extn = $namext[$io];
51 if ($io) {
52 get(2);
53 get(3);
54 get(0);
55 get(1);
56 } else {
57 get(4);
58 }
59 }
60
61 main;
62 exit(0);
63
64 sub get {
65 my ($ind) = @_;
66 my ($starttime, $entime, $IPAdd1, $IPAdd2, $IPAdd3, $IPAdd4, $cnt, $val) ;
67 my ($file) = $ovdb.$names[$ind].".".$interface;
68 open (RAWIN , $file) or die "Could not open $file";
69 my ($junk, $junk, $junk, $junk, $junk, $junk, $junk, $cfsize) = stat $file;
70 binmode(RAWIN);
71 my ($notfound) = (($cfsize / $recsz) - 1)> -1;
72 if (($fsize == $cfsize) && ($recno > 1)){
73 seek(RAWIN,($recno - 2) * $recsz, 0);
74 $notfound = ($recsz == read(RAWIN, $data, $recsz));
75 ($starttime, $entime, $IPAdd1, $IPAdd2, $IPAdd3, $IPAdd4, $cnt, $val) =
76 unpack("LLCCCCLd",$data);
77 if ($cutoff < $entime) {
78 seek(RAWIN, 0, 0);
79 $recno = 1;
80 }
81 } else {
82 $fsize = $cfsize;
83 $recno = 1;
84 }
85 while ($notfound){
86 # Read from the beginning of file
87 $notfound = ($recsz == read(RAWIN, $data, $recsz));
88 ($starttime, $entime, $IPAdd1, $IPAdd2, $IPAdd3, $IPAdd4, $cnt, $val) =
89 unpack("LLCCCCLd",$data);
90 if ($cutoff < $entime) {
91 $notfound = 0;
92 } else {
93 $recno++;
94 }
95 }
96 close (RAWIN);
97 if ($recno > 1){
98 @resu = `snmpColDump -tTI $file | sed -n $recno$p |
99 awk $parms |
100 snmpColDump -r - $file`
101 # wc -l`
102 }
103 return ($recno);
104 }