jablonka.czprosek.czf

hotsanic

Subversion Repositories:
[/] [trunk/] [modules/] [traffic/] [platform/] [syssnmp.pm] - Rev 21 Go to most recent revision

Compare with Previous - Blame - Download


package syssnmp;

use lib "../../../lib";
use HotSaNICsnmp;

sub version {
        ($VERSION = '$Revision: 1.11 $') =~ s/.*(\d+\.\d+).*/$1/;
        return "syssnmp.pm $VERSION";
        }

sub do_snmp {
        my $oid = '.1.3.6.1.2.1.2.2.1';
              # interfaces.ifTable.ifEntry.ifDesc

        my $suf_descr = '.1';
                    # .ifDescr
        my $suf_in    = '.10';
                    # .ifInOctets
        my $suf_out   = '.16';
                    # .ifOutOctets

        my (%targets) = @_;
        my (%snmpdev) = @_;

        foreach ( keys(%targets) ) {
                my ($host, $com) = split /_/;
                my ($res, $lastnic, %nics);     
                my $i = 0;
                #pro jednotlive porty switche se vyberou max hodnoty a ulozi do pole %nics
                for (@{$targets{$_}}) {
                        if($i == 0) {
                                $nics{$_} = 0;
                                $lastnic = $_;
                                $i++;
                        } else {
                                $nics{$lastnic} = $_;
                                $i = 0;
                        }
                }

                my @query = ($oid.$suf_descr, $oid.$suf_in, $oid.$suf_out);
                $res = HotSaNICsnmp::snmp_walk($host, $com, @query);
                if(keys(%$res) == 0) {

                        do_rrd($host."_".$_, "U", "U", $nics{$_}) foreach keys(%nics);
                        return undef;   
                }
                my $koncovy = 200;
                for ( my $i=1; $i < $koncovy; $i++) {
                        my $dev = $$res{$oid.$suf_descr.".".$i};
                        my $devin = $$res{$oid.$suf_in.".".$i};
                        my $devout = $$res{$oid.$suf_out.".".$i};
                        if(defined($nics{$dev})) {
                                do_rrd($host."_".$dev, $$res{$oid.$suf_in.".".$i}, $$res{$oid.$suf_out.".".$i}, $nics{$dev});
                        }
                }
        }

}

sub do_rrd {
        my ($name, $in, $out, $max) = @_;

        if (! -e "rrd/$name.rrd" ) {
                system("./makerrd","$name","$max")
        }

        RRDs::update "rrd/$name.rrd",time.":".$in.":".$out;
        if ($ERROR = RRDs::error) { print time,": ",$args{MODNAME},": unable to update `$name.rrd': $ERROR\n"; }
}

1;

Powered by WebSVN 2.2.1