1 | 31 | 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 | | | #counter64 oid |
13 | | | my $oid = '.1.3.6.1.2.1.31.1.1.1'; |
14 | | | my $suf_descr = '.1'; |
15 | | | my $suf_in = '.6'; |
16 | | | my $suf_out = '.10'; |
17 | | | my (%targets) = @_; |
18 | | | |
19 | | | foreach ( keys(%targets) ) { |
20 | | | my ($host, $com) = split /_/; |
21 | | | my ($res, $lastnic, %nics); |
22 | | | my $i = 0; |
23 | | | #pro jednotlive porty switche se vyberou max hodnoty a ulozi do pole %nics |
24 | | | for (@{$targets{$_}}) { |
25 | | | if($i == 0) { |
26 | | | $nics{$_} = 0; |
27 | | | $lastnic = $_; |
28 | | | $i++; |
29 | | | } else { |
30 | | | $nics{$lastnic} = $_; |
31 | | | $i = 0; |
32 | | | } |
33 | | | } # for targets |
34 | | | |
35 | | | my @query = ($oid.$suf_descr, $oid.$suf_in, $oid.$suf_out); |
36 | | | $res = HotSaNICsnmp::snmp_walk($host, $com, @query); |
37 | | | |
38 | | | #pokud nic nedostaneme tak se dosadi undef |
39 | | | if(keys(%$res) == 0) { |
40 | | | do_rrd($host."_".$_, "U", "U", $nics{$_}) foreach keys(%nics); |
41 | | | return undef; |
42 | | | } # 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 | | | if(defined($nics{$dev})) { |
53 | | | do_rrd($host."_".$dev, $$res{$oid.$suf_in.".".$i}, $$res{$oid.$suf_out.".".$i}, $nics{$dev}); |
54 | | | } # if defined |
55 | | | } # if oidnums |
56 | | | } # foreach res |
57 | | | } # foreach targets |
58 | | | } # do_snmp |
59 | | | |
60 | | | sub do_rrd { |
61 | | | my ($name, $in, $out, $max) = @_; |
62 | | | $name =~ s/\//-/g; |
63 | | | 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; |