jablonka.czprosek.czf

hotsanic

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

Compare with Previous - Blame - Download


package HotSaNICmod::syssnmp;

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

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

sub sample {
  my %args=@_;

  my $oid = '.1.3.6.1.4.1.2021.9.1';   # enterprises.ucdavis.dskTable.dskEntry
  my $suf_device = '.3.';   # .dskDevice
  my $suf_total = '.6.';    # .dskTotal
  my $suf_used = '.8.';     # .dskUsed
                
  if (@{$args{DRIVE}} > 0) {
    undef my %devmax;
    undef my %devuse;
    undef my %devyes;
    undef my %devsnmp;

# check which drives should be sampled
#
    foreach my $entry (@{$args{DRIVE}}) {
      my ($host,$community,$item,$dbname,$name,$file,$description)=HotSaNICmod::common::get_names($entry);
      if ($host ne "") {
        my $key = "$host"."_$community";
        if (defined($devsnmp{$key})) { push @{$devsnmp{$key}}, $item; }
        else {$devsnmp{$key} = [ $item ]; }
        }
      }

# Begin SNMP conversation here
  foreach $remote ( keys(%devsnmp) ) {
    my ($host, $com) = split "_", $remote;

    my $res = HotSaNICsnmp::snmp_walk($host, $com, ($oid));

    if(keys(%$res) == 0) {
      foreach my $dev (@{$devsnmp{$remote}}) {
        $devyes{$host."_".$dev} = 1;
        $devmax{$host."_".$dev} = "U";
        $devuse{$host."_".$dev} = "U";
        }
      }
    else {
      for (my $i=1; defined($$res{$oid.$suf_device.$i}); $i++) { 
        my $dev = $$res{$oid.$suf_device.$i};

        for (@{$devsnmp{$remote}}) {
          if($_ eq $dev) {
            my $total  = $$res{$oid.$suf_total.$i};
            my $used   = $$res{$oid.$suf_used.$i};

            $devyes{$host."_".$dev} = 1;
            $devmax{$host."_".$dev} = $total*1024;
            $devuse{$host."_".$dev} = $used *1024;
            } 
          }
        }
      }
    }

# End SNMP conversation here

# here begins the evaluation of all sampled data:
#
    foreach $name (keys %devmax) {
      
# check if the device shall really be sampled
#
      if ( defined($devyes{$name}) ) {
        (my $rrdname = $name) =~ s/(\/|:)/_/g;
        HotSaNICmod::do_rrd($rrdname,"U",time,$devmax{$name},$devuse{$name});
        }
      }
    }
  }

1;


Powered by WebSVN 2.2.1