jablonka.czprosek.czf

hotsanic

Subversion Repositories:
[/] [trunk/] [modules/] [traffic/] [platform/] [syssnmp.pm] - Blame information for rev 22

 

Line No. Rev Author Line
11simandlpackage syssnmp;
2 
3use lib "../../../lib";
4use HotSaNICsnmp;
5 
6sub version {
7 ($VERSION = '$Revision: 1.11 $') =~ s/.*(\d+\.\d+).*/$1/;
8 return "syssnmp.pm $VERSION";
9 }
10 
11sub do_snmp {
1222simandl #my $oid = '.1.3.6.1.2.1.2.2.1';
13 my $oid = '.1.3.6.1.2.1.31.1.1.1';
141simandl # interfaces.ifTable.ifEntry.ifDesc
15 
1618simandl my $suf_descr = '.1';
171simandl # .ifDescr
1822simandl my $suf_in = '.6';
191simandl # .ifInOctets
2022simandl my $suf_out = '.10';
211simandl # .ifOutOctets
22 
23 my (%targets) = @_;
2418simandl my (%snmpdev) = @_;
251simandl 
26 foreach ( keys(%targets) ) {
27 my ($host, $com) = split /_/;
2818simandl my ($res, $lastnic, %nics);
291simandl my $i = 0;
3018simandl #pro jednotlive porty switche se vyberou max hodnoty a ulozi do pole %nics
311simandl for (@{$targets{$_}}) {
32 if($i == 0) {
33 $nics{$_} = 0;
34 $lastnic = $_;
35 $i++;
36 } else {
37 $nics{$lastnic} = $_;
38 $i = 0;
39 }
40 }
41 
42 my @query = ($oid.$suf_descr, $oid.$suf_in, $oid.$suf_out);
43 $res = HotSaNICsnmp::snmp_walk($host, $com, @query);
44 if(keys(%$res) == 0) {
4522simandl print "vytvarim pro $_ ... $nics{$_}";
4618simandl do_rrd($host."_".$_, "U", "U", $nics{$_}) foreach keys(%nics);
471simandl return undef;
48 }
4922simandl #ciselne porty
50 my $koncovy = 600;
5118simandl for ( my $i=1; $i < $koncovy; $i++) {
52 my $dev = $$res{$oid.$suf_descr.".".$i};
53 my $devin = $$res{$oid.$suf_in.".".$i};
54 my $devout = $$res{$oid.$suf_out.".".$i};
55 if(defined($nics{$dev})) {
561simandl do_rrd($host."_".$dev, $$res{$oid.$suf_in.".".$i}, $$res{$oid.$suf_out.".".$i}, $nics{$dev});
5718simandl }
581simandl }
5922simandl #jmenne porty
60 for ( my $i=1; defined($$res{$oid.$suf_descr.".".$i}); $i++) {
61 my $dev = $$res{$oid.$suf_descr.".".$i};
62 print "1 mam tu $dev";
63 if(defined($nics{$dev})) {
64 do_rrd($host."_".$dev, $$res{$oid.$suf_in.".".$i}, $$res{$oid.$suf_out.".".$i}, $nics{$dev});
65 }
66 }
671simandl }
6818simandl 
691simandl}
70 
71sub do_rrd {
72 my ($name, $in, $out, $max) = @_;
7322simandl $name =~ s/\//-/g;
741simandl if (! -e "rrd/$name.rrd" ) {
75 system("./makerrd","$name","$max")
76 }
77 
78 RRDs::update "rrd/$name.rrd",time.":".$in.":".$out;
79 if ($ERROR = RRDs::error) { print time,": ",$args{MODNAME},": unable to update `$name.rrd': $ERROR\n"; }
80}
81 
821;

Powered by WebSVN 2.2.1