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 | 23 | simandl | #counter64 oid |
13 | 22 | simandl | my $oid = '.1.3.6.1.2.1.31.1.1.1'; |
14 | 18 | simandl | my $suf_descr = '.1'; |
15 | 22 | simandl | my $suf_in = '.6'; |
16 | | | my $suf_out = '.10'; |
17 | 1 | simandl | my (%targets) = @_; |
18 | | | |
19 | | | foreach ( keys(%targets) ) { |
20 | | | my ($host, $com) = split /_/; |
21 | 18 | simandl | my ($res, $lastnic, %nics); |
22 | 1 | simandl | my $i = 0; |
23 | 18 | simandl | #pro jednotlive porty switche se vyberou max hodnoty a ulozi do pole %nics |
24 | 1 | simandl | for (@{$targets{$_}}) { |
25 | | | if($i == 0) { |
26 | | | $nics{$_} = 0; |
27 | | | $lastnic = $_; |
28 | | | $i++; |
29 | | | } else { |
30 | | | $nics{$lastnic} = $_; |
31 | | | $i = 0; |
32 | | | } |
33 | 23 | simandl | } # for targets |
34 | 1 | simandl | |
35 | | | my @query = ($oid.$suf_descr, $oid.$suf_in, $oid.$suf_out); |
36 | | | $res = HotSaNICsnmp::snmp_walk($host, $com, @query); |
37 | 23 | simandl | |
38 | | | #pokud nic nedostaneme tak se dosadi undef |
39 | 1 | simandl | if(keys(%$res) == 0) { |
40 | 18 | simandl | do_rrd($host."_".$_, "U", "U", $nics{$_}) foreach keys(%nics); |
41 | 1 | simandl | return undef; |
42 | 23 | simandl | } # if |
43 | | | |
44 | | | #projdeme vysledek a zapiseme do databaze |
45 | | | foreach ( keys(%$res) ) { |
46 | | | my @oidnums = split(/\./, $_); |
47 | | | #pokud je to descr tak vyzvedneme jmeno dev a jdem na zapis |
48 | | | if($oidnums[11]==1) { |
49 | | | my $dev = $$res{$_}; |
50 | | | my $i = $oidnums[12]; |
51 | | | #pokud dev existuje jdemem na zapis |
52 | 22 | simandl | if(defined($nics{$dev})) { |
53 | | | do_rrd($host."_".$dev, $$res{$oid.$suf_in.".".$i}, $$res{$oid.$suf_out.".".$i}, $nics{$dev}); |
54 | 23 | simandl | } # if defined |
55 | | | } # if oidnums |
56 | | | } # foreach res |
57 | | | } # foreach targets |
58 | | | } # do_snmp |
59 | 18 | simandl | |
60 | 1 | simandl | sub do_rrd { |
61 | | | my ($name, $in, $out, $max) = @_; |
62 | 22 | simandl | $name =~ s/\//-/g; |
63 | 1 | simandl | if (! -e "rrd/$name.rrd" ) { |
64 | | | system("./makerrd","$name","$max") |
65 | | | } |
66 | | | |
67 | | | RRDs::update "rrd/$name.rrd",time.":".$in.":".$out; |
68 | | | if ($ERROR = RRDs::error) { print time,": ",$args{MODNAME},": unable to update `$name.rrd': $ERROR\n"; } |
69 | | | } |
70 | | | |
71 | | | 1; |