jablonka.czprosek.czf

hotsanic

Subversion Repositories:
[/] [trunk/] [modules/] [packets/] [platform/] [syssnmp.pm] - Rev 36 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 {
        #counter64 oid
        my $oid = '.1.3.6.1.2.1.31.1.1.1';
        my $suf_descr = '.1';
        my $suf_in    = '.6';
        my $suf_out   = '.10';
        my (%targets) = @_;

        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;
                        }
                } # for targets

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

                #pokud nic nedostaneme tak se dosadi undef
                if(keys(%$res) == 0) {
                        do_rrd($host."_".$_, "U", "U", $nics{$_}) foreach keys(%nics);
                        return undef;   
                } # if 

                #projdeme vysledek a zapiseme do databaze
                foreach ( keys(%$res) ) {
                    my @oidnums = split(/\./, $_);
                    #pokud je to descr tak vyzvedneme jmeno dev a jdem na zapis
                    if($oidnums[11]==1) {
                        my $dev = $$res{$_};
                        my $i = $oidnums[12];
                        #pokud dev existuje jdemem na zapis
                        if(defined($nics{$dev})) {
                                do_rrd($host."_".$dev, $$res{$oid.$suf_in.".".$i}, $$res{$oid.$suf_out.".".$i}, $nics{$dev});
                        } # if defined
                    } # if oidnums
                } # foreach res
        } # foreach targets
} # do_snmp

sub do_rrd {
        my ($name, $in, $out, $max) = @_;
        $name =~ s/\//-/g;
        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