1 | 31 | simandl | package HotSaNICmod::OSdep; |
2 | | | |
3 | | | use lib "../../lib"; |
4 | | | use RRDs; |
5 | | | |
6 | | | eval { require "platform/syssnmp.pm"; }; |
7 | | | $NO_SNMP=1 if($@); |
8 | | | |
9 | | | sub version { |
10 | | | ($VERSION = '$Revision: 1.6 $') =~ s/.*(\d+\.\d+).*/$1/; |
11 | | | return "$^O.pm $VERSION"; |
12 | | | } |
13 | | | |
14 | | | sub sample { |
15 | | | my %args=@_; |
16 | | | |
17 | | | my %maxin; |
18 | | | my %maxout; |
19 | | | my %devin; |
20 | | | my %devout; |
21 | | | my %sampletime; |
22 | | | my %snmpdev; |
23 | | | |
24 | | | foreach (keys(%args)) { |
25 | | | if ( index($_,"DEV") >= 0) { |
26 | | | ($dev,$maxin,$maxout,$description)=split /,/,$args{$_}; |
27 | | | if ( index($dev,"SNMP\:") >= 0) { |
28 | | | (undef,$host,$community,$interface)=split /:/,$dev; |
29 | | | my $max = $maxin; |
30 | | | $max = $maxout if $maxin < $maxout; |
31 | | | my @data = ( $interface, $max); |
32 | | | if (defined $snmpdev{$host."_".$community}) { |
33 | | | push @{$snmpdev{$host."_".$community}}, @data; |
34 | | | } else { |
35 | | | $snmpdev{$host."_".$community} = [ @data ] ; |
36 | | | } |
37 | | | } else { |
38 | | | $dev =~ s/:/_/g; |
39 | | | $maxin{$dev}=$maxin; |
40 | | | $maxout{$dev}=$maxout; |
41 | | | $devin{$dev}="U"; |
42 | | | $devout{$dev}="U"; |
43 | | | $sampletime{$dev}=time; |
44 | | | } |
45 | | | } |
46 | | | } |
47 | | | |
48 | | | open(IN,"netstat -nib | grep Link |"); |
49 | | | while(<IN>) { |
50 | | | chomp; |
51 | | | @line = split; |
52 | | | $name = $line[0]; |
53 | | | $devin{$name} = $line[$#line-1]; |
54 | | | $devout{$name}= $line[$#line]; |
55 | | | $sampletime{$name}=time; |
56 | | | } |
57 | | | close(IN); |
58 | | | |
59 | | | # |
60 | | | # then query SNMP hosts and check interfaces |
61 | | | # |
62 | | | |
63 | | | syssnmp::do_snmp(%snmpdev); |
64 | | | |
65 | | | # |
66 | | | # save data |
67 | | | # |
68 | | | foreach $name (keys %maxin) { |
69 | | | |
70 | | | # build new database if needed |
71 | | | # |
72 | | | if (! -e "./rrd/$name.rrd" ) { |
73 | | | |
74 | | | # get max. transmission value |
75 | | | # |
76 | | | my $max=$maxin{$name}; |
77 | | | if ($max < $maxout{$name}) { $max=$maxout{$name} }; |
78 | | | |
79 | | | # if max-transmission is not set, assume 100 MBit. |
80 | | | # |
81 | | | if ($max == 0) { $max=12500000; } |
82 | | | system("./makerrd","$name","$max") |
83 | | | } |
84 | | | |
85 | | | # update database |
86 | | | RRDs::update "rrd/$name.rrd",$sampletime{$name}.":".$devin{$name}.":".$devout{$name}; |
87 | | | if ($ERROR = RRDs::error) { |
88 | | | print time,": ",$args{MODNAME},": unable to update `$name.rrd': $ERROR\n"; |
89 | | | } |
90 | | | } |
91 | | | } |
92 | | | |
93 | | | 1; |
94 | | | |