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 | 22 | simandl | #my $oid = '.1.3.6.1.2.1.2.2.1'; |
13 | | | my $oid = '.1.3.6.1.2.1.31.1.1.1'; |
14 | 1 | simandl | # interfaces.ifTable.ifEntry.ifDesc |
15 | | | |
16 | 18 | simandl | my $suf_descr = '.1'; |
17 | 1 | simandl | # .ifDescr |
18 | 22 | simandl | my $suf_in = '.6'; |
19 | 1 | simandl | # .ifInOctets |
20 | 22 | simandl | my $suf_out = '.10'; |
21 | 1 | simandl | # .ifOutOctets |
22 | | | |
23 | | | my (%targets) = @_; |
24 | 18 | simandl | my (%snmpdev) = @_; |
25 | 1 | simandl | |
26 | | | foreach ( keys(%targets) ) { |
27 | | | my ($host, $com) = split /_/; |
28 | 18 | simandl | my ($res, $lastnic, %nics); |
29 | 1 | simandl | my $i = 0; |
30 | 18 | simandl | #pro jednotlive porty switche se vyberou max hodnoty a ulozi do pole %nics |
31 | 1 | simandl | 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) { |
45 | 22 | simandl | print "vytvarim pro $_ ... $nics{$_}"; |
46 | 18 | simandl | do_rrd($host."_".$_, "U", "U", $nics{$_}) foreach keys(%nics); |
47 | 1 | simandl | return undef; |
48 | | | } |
49 | 22 | simandl | #ciselne porty |
50 | | | my $koncovy = 600; |
51 | 18 | simandl | 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})) { |
56 | 1 | simandl | do_rrd($host."_".$dev, $$res{$oid.$suf_in.".".$i}, $$res{$oid.$suf_out.".".$i}, $nics{$dev}); |
57 | 18 | simandl | } |
58 | 1 | simandl | } |
59 | 22 | simandl | #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 | | | } |
67 | 1 | simandl | } |
68 | 18 | simandl | |
69 | 1 | simandl | } |
70 | | | |
71 | | | sub do_rrd { |
72 | | | my ($name, $in, $out, $max) = @_; |
73 | 22 | simandl | $name =~ s/\//-/g; |
74 | 1 | simandl | 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 | | | |
82 | | | 1; |