1 | 1 | simandl | package syssnmp; |
2 | | | |
3 | | | use lib "../../../lib"; |
4 | | | use HotSaNICsnmp; |
5 | | | |
6 | | | sub version { |
7 | | | ($VERSION = '$Revision: 1.11 $') =~ s/.*(\d+\.\d+).*/$1/; |
8 | | | return "syssnmp.pm $VERSION"; |
9 | | | } |
10 | | | |
11 | | | sub do_snmp { |
12 | | | my $oid = '.1.3.6.1.2.1.2.2.1'; |
13 | | | # interfaces.ifTable.ifEntry.ifDesc |
14 | | | |
15 | 18 | simandl | my $suf_descr = '.1'; |
16 | 1 | simandl | # .ifDescr |
17 | | | my $suf_in = '.10'; |
18 | | | # .ifInOctets |
19 | | | my $suf_out = '.16'; |
20 | | | # .ifOutOctets |
21 | | | |
22 | | | my (%targets) = @_; |
23 | 18 | simandl | my (%snmpdev) = @_; |
24 | 1 | simandl | |
25 | | | foreach ( keys(%targets) ) { |
26 | | | my ($host, $com) = split /_/; |
27 | 18 | simandl | my ($res, $lastnic, %nics); |
28 | 1 | simandl | my $i = 0; |
29 | 18 | simandl | #pro jednotlive porty switche se vyberou max hodnoty a ulozi do pole %nics |
30 | 1 | simandl | for (@{$targets{$_}}) { |
31 | | | if($i == 0) { |
32 | | | $nics{$_} = 0; |
33 | | | $lastnic = $_; |
34 | | | $i++; |
35 | | | } else { |
36 | | | $nics{$lastnic} = $_; |
37 | | | $i = 0; |
38 | | | } |
39 | | | } |
40 | | | |
41 | | | my @query = ($oid.$suf_descr, $oid.$suf_in, $oid.$suf_out); |
42 | | | $res = HotSaNICsnmp::snmp_walk($host, $com, @query); |
43 | | | if(keys(%$res) == 0) { |
44 | 18 | simandl | |
45 | | | do_rrd($host."_".$_, "U", "U", $nics{$_}) foreach keys(%nics); |
46 | 1 | simandl | return undef; |
47 | | | } |
48 | 18 | simandl | my $koncovy = 200; |
49 | | | for ( my $i=1; $i < $koncovy; $i++) { |
50 | | | my $dev = $$res{$oid.$suf_descr.".".$i}; |
51 | | | my $devin = $$res{$oid.$suf_in.".".$i}; |
52 | | | my $devout = $$res{$oid.$suf_out.".".$i}; |
53 | | | if(defined($nics{$dev})) { |
54 | 1 | simandl | do_rrd($host."_".$dev, $$res{$oid.$suf_in.".".$i}, $$res{$oid.$suf_out.".".$i}, $nics{$dev}); |
55 | 18 | simandl | } |
56 | 1 | simandl | } |
57 | | | } |
58 | 18 | simandl | |
59 | 1 | simandl | } |
60 | | | |
61 | | | sub do_rrd { |
62 | | | my ($name, $in, $out, $max) = @_; |
63 | 18 | simandl | |
64 | 1 | simandl | if (! -e "rrd/$name.rrd" ) { |
65 | | | system("./makerrd","$name","$max") |
66 | | | } |
67 | | | |
68 | | | RRDs::update "rrd/$name.rrd",time.":".$in.":".$out; |
69 | | | if ($ERROR = RRDs::error) { print time,": ",$args{MODNAME},": unable to update `$name.rrd': $ERROR\n"; } |
70 | | | } |
71 | | | |
72 | | | 1; |