jablonka.czprosek.czf

hotsanic

Subversion Repositories:
[/] [branches/] [HotSaNIC-0.5.0-pre6/] [modules/] [traffic/] [platform/] [syssnmp.pm] - Rev 30 Go to most recent revision

Compare with Previous - Blame - Download


package HotSaNICmod::syssnmp;

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

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


sub sample {
  my %args=@_;

  my $oid = '.1.3.6.1.2.1.2.2.1';     # interfaces.ifTable.ifEntry.ifDesc
  my $suf_descr = '.2';      # .ifDescr
  my $suf_in    = '.10';     # .ifInOctets
  my $suf_out   = '.16';     # .ifOutOctets

  my %maxin;
  my %maxout;
  my %devin;
  my %devout;
  my %sampletime;
  my %snmpdev;

  foreach my $entry (@{$args{DEV}}) {
    my ($host,$community,$item,$dbname,$name,$file,$description,$maxin,$maxout)=HotSaNICmod::common::get_names($entry);
    
    if ($host ne "") {
      my $max = $maxin;
      $max = $maxout if $maxin < $maxout;
      my @data = ($item, $max);
      if (defined $snmpdev{$host."_".$community}) { push @{$snmpdev{$host."_".$community}}, @data; }
      else { $snmpdev{$host."_".$community} = [ @data ] ; }
      $dbname{$host."_".$item}=$dbname;
      }
    }

  foreach (keys %snmpdev) {
    my ($host, $com) = split /_/;
    my $res;
    undef my %max;
  
    while (@{$snmpdev{$_}}) {
      my $name=shift @{$snmpdev{$_}};
      my $max=shift @{$snmpdev{$_}};
      $max{$name}=$max;
      }
  
    my @query = ($oid.$suf_descr, $oid.$suf_in, $oid.$suf_out);
    $res = HotSaNICsnmp::snmp_walk($host, $com, @query);

    if(keys(%$res) == 0) { HotSaNICmod::do_rrd($dbname{$host."_".$_}, $max{$_}, time, "U", "U") foreach keys(%max); }

    else {
      for ( my $i=1; defined($$res{$oid.$suf_descr.".".$i}); $i++) {
        my $dev = $$res{$oid.$suf_descr.".".$i};
        if(defined($max{$dev})) {
          HotSaNICmod::do_rrd($dbname{$host."_".$dev}, $max{$dev}, time, $$res{$oid.$suf_in.".".$i}, $$res{$oid.$suf_out.".".$i});
          }
        }
      }
    }
  }

1;


Powered by WebSVN 2.2.1