jablonka.czprosek.czf

hotsanic

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

 

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 {
12 my $oid = '.1.3.6.1.2.1.2.2.1';
13 # interfaces.ifTable.ifEntry.ifDesc
14 
15 my $suf_descr = '.2';
16 # .ifDescr
17 my $suf_in = '.10';
18 # .ifInOctets
19 my $suf_out = '.16';
20 # .ifOutOctets
21 
22 my (%targets) = @_;
23 
24 foreach ( keys(%targets) ) {
25# print "1 $_\n";
26 my ($host, $com) = split /_/;
27 my ($res, $lastnic, @nics);
28 
29 my $i = 0;
30 my $switch = 0;
31 my $portnum = "none";
32 for (@{$targets{$_}}) {
33 my (undef, $portnum) = split /port/;
34 
35 if ("port$portnum" eq $_) {
36# print "Je to switch\n";
37 $switch = 1;
38 $port = $portnum;
39 if($i == 0) {
40 $nics{$_} = 0;
41 $lastnic = $port;
42 $i++;
43 } else {
44 $nics{$lastnic} = $_;
45 $i = 0;
46 }
47 } else {
48 if($i == 0) {
49 $nics{$_} = 0;
50 $lastnic = $_;
51 $i++;
52 } else {
53 $nics{$lastnic} = $_;
54 $i = 0;
55 }
56 }
57 }
58# print "2 $_ a $port\n";
59# print "3 $host a $com b $lastnic c $nics{$dev}\n";
60 
61 my @query = ($oid.$suf_descr, $oid.$suf_in, $oid.$suf_out);
62# print "4 @query\n";
63 $res = HotSaNICsnmp::snmp_walk($host, $com, @query);
64# print "5 $res\n";
65 
66 #pokud nejsou vysledky tak se zapise do databaze Undef stav
67 if(keys(%$res) == 0) {
68# print "tady to je kdyz nejni spojeni tak se do rrd da undef";
69 if ($switch == 1) {
70 do_rrd($host."_port".$_, "U", "U", $nics{$_}) foreach keys(%nics);
71 } else {
72 do_rrd($host."_".$_, "U", "U", $nics{$_}) foreach keys(%nics);
73 }
74 return undef;
75 }
76 
77 $necodef = defined($$res{$oid.$suf_descr.".".$i});
78# print "5a $necodef\n";
79 #jedem na prohledani vsech ifaces a pokud souhlasi tak se pise do rrd
80 for ( my $i=1; defined($$res{$oid.$suf_descr.".".$i}); $i++) {
81 if ($switch == 1) {
82 #toto je cast pro switch a jde se na rrd pokud souhlasi poradi portu
83 #jmeno iface se neda pro rozpoznani pouzit protoze je pro vsechny stejne
84 my $dev = $$res{$oid.$suf_descr.".".$i};
85# print "5b $dev\n";
86 if(defined($nics{$i})) {
87# print "5b $nics{$i}\n";
88 do_rrd($host."_port".$i, $$res{$oid.$suf_in.".".$i}, $$res{$oid.$suf_out.".".$i}, $nics{$i});
89 }
90 } else {
91 #zde rozpoznavame podle jmena iface
92 my $dev = $$res{$oid.$suf_descr.".".$i};
93 if(defined($nics{$dev})) {
94 do_rrd($host."_".$dev, $$res{$oid.$suf_in.".".$i}, $$res{$oid.$suf_out.".".$i}, $nics{$dev});
95 }
96 }
97 }
98 }
99}
100 
101sub do_rrd {
102 my ($name, $in, $out, $max) = @_;
103#print "mam tu $max";
104 if (! -e "rrd/$name.rrd" ) {
105 system("./makerrd","$name","$max")
106 }
107 
108 RRDs::update "rrd/$name.rrd",time.":".$in.":".$out;
109 if ($ERROR = RRDs::error) { print time,": ",$args{MODNAME},": unable to update `$name.rrd': $ERROR\n"; }
110}
111 
1121;

Powered by WebSVN 2.2.1