Difference between revisions of "Net-SNMP subagent"

From OpenVZ Virtuozzo Containers Wiki
Jump to: navigation, search
(New page: Here is snmp subagent to export UBC via SNMP protocol. Author - n1ckname === /etc/snmp/snmpagent.pl === #!/usr/bin/perl $program = $0; use NetSNMP::OID (':all'); use Net...)
 
(+source tag, License)
Line 1: Line 1:
 
Here is snmp subagent to export UBC via SNMP protocol.
 
Here is snmp subagent to export UBC via SNMP protocol.
  
Author - n1ckname
+
Author - n1ckname. License: GNU GPL v2.
  
  
 
=== /etc/snmp/snmpagent.pl ===
 
=== /etc/snmp/snmpagent.pl ===
  
  #!/usr/bin/perl  
+
<source lang="perl">
 
+
#!/usr/bin/perl  
  $program = $0;
+
 
 
+
$program = $0;
  use NetSNMP::OID (':all');
+
 
  use NetSNMP::agent (':all');
+
use NetSNMP::OID (':all');
  use NetSNMP::ASN (':all');
+
use NetSNMP::agent (':all');
  use Data::Dumper;
+
use NetSNMP::ASN (':all');
  my $debug = 0;
+
use Data::Dumper;
  my @resName=qw(name vmguarpages tcpsndbuf othersockbuf physpages numfile numtcpsock numpty numsiginfo tcprcvbuf dcachesize numiptent numothersock privvmpages kmemsize numflock shmpages lockedpages dummy numproc oomguarpages dgramrcvbuf);
+
my $debug = 0;
  my @catName=qw(held maxheld barrier limit failcnt);
+
my @resName=qw(name vmguarpages tcpsndbuf othersockbuf physpages numfile numtcpsock numpty numsiginfo tcprcvbuf dcachesize numiptent numothersock privvmpages kmemsize numflock shmpages lockedpages dummy numproc oomguarpages dgramrcvbuf);
  my %resIndex,%catIndex;
+
my @catName=qw(held maxheld barrier limit failcnt);
  @resIndex{@resName} = (0..$#resName);
+
my %resIndex,%catIndex;
  @catIndex{@catName} = (0..$#catName);
+
@resIndex{@resName} = (0..$#resName);
 
+
@catIndex{@catName} = (0..$#catName);
  sub handler {  
+
 
      my ($handler, $reg_info, $request_info, $requests) = @_;  
+
sub handler {  
      open(UB,"<$source");
+
    my ($handler, $reg_info, $request_info, $requests) = @_;  
      while(<UB>){
+
    open(UB,"<$source");
          my %vmachine;
+
    while(<UB>){
          if ( /\D*(\d+):[\s\t]+([a-z]+)[\t\s]+(\d+)[\t\s]+(\d+)[\t\s]+(\d+)[\t\s]+(\d+)[\t\s]+(\d+).*/ ){  
+
        my %vmachine;
      $vid=$1;  
+
        if ( /\D*(\d+):[\s\t]+([a-z]+)[\t\s]+(\d+)[\t\s]+(\d+)[\t\s]+(\d+)[\t\s]+(\d+)[\t\s]+(\d+).*/ ){  
      $beancounters{$vid}=\%vmachine ;  
+
    $vid=$1;  
              ${beancounters{$vid}{0}}="www";
+
    $beancounters{$vid}=\%vmachine ;  
      open(CONF,"</etc/vz/conf/$vid.conf");
+
            ${beancounters{$vid}{0}}="www";
      my $name=$vid;
+
    open(CONF,"</etc/vz/conf/$vid.conf");
      while(<CONF>) {
+
    my $name=$vid;
  if(/NAME[\s\t]?=[\s\t]?["]?([^"]+)["]?/)  {
+
    while(<CONF>) {
      $name=$1;
+
if(/NAME[\s\t]?=[\s\t]?["]?([^"]+)["]?/)  {
      last;
+
    $name=$1;
      #"
+
    last;
  }
+
    #"
      }
+
}
      ${beancounters{$vid}{0}}=$name;
+
    }
              $resource=$2 ;
+
    ${beancounters{$vid}{0}}=$name;
              $held=$3 ;
+
            $resource=$2 ;
              $maxheld=$4 ;
+
            $held=$3 ;
              $barrier=$5 ;
+
            $maxheld=$4 ;
              $limit=$6 ;
+
            $barrier=$5 ;
              $failcnt=$7 ;
+
            $limit=$6 ;
              ${beancounters{$vid}}{${resIndex{$resource}}}=[$held , $maxheld , $barrier , $limit ,$failcnt ];
+
            $failcnt=$7 ;
 
+
            ${beancounters{$vid}}{${resIndex{$resource}}}=[$held , $maxheld , $barrier , $limit ,$failcnt ];
  }
+
 
          if ( /^[\W\d]+([a-z]+)[\t\s]+(\d+)[\t\s]+(\d+)[\t\s]+(\d+)[\t\s]+(\d+)[\t\s]+(\d+).*/ ) {
+
}
                  $resource=$1 ;
+
        if ( /^[\W\d]+([a-z]+)[\t\s]+(\d+)[\t\s]+(\d+)[\t\s]+(\d+)[\t\s]+(\d+)[\t\s]+(\d+).*/ ) {
                  $held=$2 ;
+
                $resource=$1 ;
                  $maxheld=$3 ;
+
                $held=$2 ;
                  $barrier=$4 ;
+
                $maxheld=$3 ;
                  $limit=$5 ;
+
                $barrier=$4 ;
                  $failcnt=$6 ;
+
                $limit=$5 ;
                  ${beancounters{$vid}}{${resIndex{$resource}}}=[$held , $maxheld , $barrier , $limit ,$failcnt ];
+
                $failcnt=$6 ;
          }
+
                ${beancounters{$vid}}{${resIndex{$resource}}}=[$held , $maxheld , $barrier , $limit ,$failcnt ];
      }
+
        }
      close(UB);
+
    }
 
+
    close(UB);
      for ( my $request = $requests; $request; $request = $request->next() ) {
+
 
     
+
    for ( my $request = $requests; $request; $request = $request->next() ) {
          my $reqOID = $request->getOID();
+
   
          my $reqMode = $request_info->getMode();
+
        my $reqOID = $request->getOID();
  my $myOID = new NetSNMP::OID($OID);
+
        my $reqMode = $request_info->getMode();
  #1.3.6.1.4.1.2021.51.ctcount = 5
+
my $myOID = new NetSNMP::OID($OID);
  #1.3.6.1.4.1.2021.51.ct.101.name = www
+
#1.3.6.1.4.1.2021.51.ctcount = 5
  #1.3.6.1.4.1.2021.51.ct.101.kmemsize.held = 458584
+
#1.3.6.1.4.1.2021.51.ct.101.name = www
  #1.3.6.1.4.1.2021.51.ct.101.kmemsize.maxheld = 1490364
+
#1.3.6.1.4.1.2021.51.ct.101.kmemsize.held = 458584
  #1.3.6.1.4.1.2021.51.ct.101.kmemsize.barrier = 11055923
+
#1.3.6.1.4.1.2021.51.ct.101.kmemsize.maxheld = 1490364
 
+
#1.3.6.1.4.1.2021.51.ct.101.kmemsize.barrier = 11055923
  # $request->setValue(ASN_INTEGER, scalar keys (%beancounters));
+
 
 
+
# $request->setValue(ASN_INTEGER, scalar keys (%beancounters));
          if ($reqMode == MODE_GET) {
+
 
      print STDERR $reqOID." MODE_GET\n" if($debug);;
+
        if ($reqMode == MODE_GET) {
          if($reqOID == $myOID+".0"){
+
    print STDERR $reqOID." MODE_GET\n" if($debug);;
  $request->setValue(ASN_INTEGER, scalar keys (%beancounters));
+
        if($reqOID == $myOID+".0"){
      } elsif($reqOID =~ /$myOID\.([0-9]+)[\.]?([0-9]+)?[\.]?([0-9]+)?[\.]?([0-9]+)?/) {
+
$request->setValue(ASN_INTEGER, scalar keys (%beancounters));
 
+
    } elsif($reqOID =~ /$myOID\.([0-9]+)[\.]?([0-9]+)?[\.]?([0-9]+)?[\.]?([0-9]+)?/) {
  my $typeReq=$1;
+
 
  my $vzidReq=$2;
+
my $typeReq=$1;
  my $resReq=$3;
+
my $vzidReq=$2;
  my $catReq=$4;
+
my $resReq=$3;
  my %vz;
+
my $catReq=$4;
 
+
my %vz;
 
+
  print STDERR "Type:$typeReq, VzID: $vzidReq, Res: $resReq/$resName[$resReq], Cat: $catReq/$catName[$catReq]\n" if($debug);;
+
 
 
+
print STDERR "Type:$typeReq, VzID: $vzidReq, Res: $resReq/$resName[$resReq], Cat: $catReq/$catName[$catReq]\n" if($debug);;
  if(!$vzidReq) {
+
 
      foreach $vzid (sort keys %beancounters) {
+
if(!$vzidReq) {
  $vzidReq=$vzid;
+
    foreach $vzid (sort keys %beancounters) {
  last;
+
$vzidReq=$vzid;
      }
+
last;
  }
+
    }
  if(!$vzidReq || !exists(${beancounters{$vzidReq}})) {
+
}
      $request->setError($request_info,SNMP_ERR_NOSUCHNAME);
+
if(!$vzidReq || !exists(${beancounters{$vzidReq}})) {
      last;
+
    $request->setError($request_info,SNMP_ERR_NOSUCHNAME);
  }
+
    last;
 
+
}
  %vz=%{${beancounters{$vzidReq}}};
+
 
 
+
%vz=%{${beancounters{$vzidReq}}};
  if((!defined($resReq) or $resReq == 0) && defined(${vz{0}})) {
+
 
      $request->setValue(ASN_OCTET_STR, "".${vz{0}});
+
if((!defined($resReq) or $resReq == 0) && defined(${vz{0}})) {
  } elsif(!defined($catReq) && defined(${vz{$resReq}[0]})) {
+
    $request->setValue(ASN_OCTET_STR, "".${vz{0}});
      $request->setValue(ASN_INTEGER, ${vz{$resReq}[0]});
+
} elsif(!defined($catReq) && defined(${vz{$resReq}[0]})) {
 
+
    $request->setValue(ASN_INTEGER, ${vz{$resReq}[0]});
  } elsif($catReq< $#catName && defined(${vz{$resReq}[$catReq]})) {
+
 
      if(9223372036854775807 == ${vz{$resReq}[$catReq+1]}) {
+
} elsif($catReq< $#catName && defined(${vz{$resReq}[$catReq]})) {
  $request->setValue(ASN_INTEGER,-1);
+
    if(9223372036854775807 == ${vz{$resReq}[$catReq+1]}) {
      } else {
+
$request->setValue(ASN_INTEGER,-1);
  $request->setValue(ASN_INTEGER,${vz{$resReq}[$catReq+1]});
+
    } else {
      }
+
$request->setValue(ASN_INTEGER,${vz{$resReq}[$catReq+1]});
  } elsif($resReq<scalar keys %vz && defined(${vz{$resReq+1}[0]})) {
+
    }
      if(9223372036854775807 == ${vz{$resReq}[$catReq+1]}) {
+
} elsif($resReq<scalar keys %vz && defined(${vz{$resReq+1}[0]})) {
  $request->setValue(ASN_INTEGER,-1);
+
    if(9223372036854775807 == ${vz{$resReq}[$catReq+1]}) {
      } else {
+
$request->setValue(ASN_INTEGER,-1);
  $request->setValue(ASN_INTEGER, ${vz{$resReq+1}[0]});
+
    } else {
      }
+
$request->setValue(ASN_INTEGER, ${vz{$resReq+1}[0]});
  } else  {
+
    }
      my $finish=1;
+
} else  {
      foreach $vzid (sort keys %beancounters) {
+
    my $finish=1;
  if($vzid > $vzidReq) {
+
    foreach $vzid (sort keys %beancounters) {
      %vz=%{${beancounters{$vzid}}};
+
if($vzid > $vzidReq) {
      $vzidReq=$vzid;
+
    %vz=%{${beancounters{$vzid}}};
      $finish=0;
+
    $vzidReq=$vzid;
      last;
+
    $finish=0;
  }
+
    last;
      }
+
}
      if(!$finish)  {
+
    }
  $request->setValue(ASN_INTEGER, "".${vz{0}});
+
    if(!$finish)  {
      }
+
$request->setValue(ASN_INTEGER, "".${vz{0}});
  }
+
    }
     
+
}
 
+
   
      }
+
 
 
+
    }
  } elsif ($reqMode == MODE_GETNEXT) {
+
 
      print STDERR $reqOID." MODE_GETNEXT\n" if($debug);
+
} elsif ($reqMode == MODE_GETNEXT) {
          if($reqOID < $myOID+".0"){
+
    print STDERR $reqOID." MODE_GETNEXT\n" if($debug);
      $request->setOID($OID.".0");
+
        if($reqOID < $myOID+".0"){
  $request->setValue(ASN_INTEGER, scalar keys (%beancounters));
+
    $request->setOID($OID.".0");
      } elsif($reqOID =~ /$myOID\.([0-9]+)[\.]?([0-9]+)?[\.]?([0-9]+)?[\.]?([0-9]+)?$/) {
+
$request->setValue(ASN_INTEGER, scalar keys (%beancounters));
  my $typeReq=$1;
+
    } elsif($reqOID =~ /$myOID\.([0-9]+)[\.]?([0-9]+)?[\.]?([0-9]+)?[\.]?([0-9]+)?$/) {
  my $vzidReq=$2;
+
my $typeReq=$1;
  my $resReq=$3;
+
my $vzidReq=$2;
  my $catReq=$4;
+
my $resReq=$3;
  my %vz;
+
my $catReq=$4;
 
+
my %vz;
  print STDERR "Type:$typeReq, VzID: $vzidReq, Res: $resReq/$resName[$resReq], Cat: $catReq/$catName[$catReq]\n" if($debug);;
+
 
+
print STDERR "Type:$typeReq, VzID: $vzidReq, Res: $resReq/$resName[$resReq], Cat: $catReq/$catName[$catReq]\n" if($debug);;
  if(!$vzidReq) {
+
 
      foreach $vzid (sort keys %beancounters) {
+
if(!$vzidReq) {
  $vzidReq=$vzid;
+
    foreach $vzid (sort keys %beancounters) {
  last;
+
$vzidReq=$vzid;
      }
+
last;
  }
+
    }
  if(!$vzidReq || !exists(${beancounters{$vzidReq}})) {
+
}
      $request->setError($request_info,SNMP_ERR_NOSUCHNAME);
+
if(!$vzidReq || !exists(${beancounters{$vzidReq}})) {
      last;
+
    $request->setError($request_info,SNMP_ERR_NOSUCHNAME);
  }
+
    last;
 
+
}
 
+
 
  %vz=%{${beancounters{$vzidReq}}};
+
 
 
+
%vz=%{${beancounters{$vzidReq}}};
  if(!defined($resReq) && defined(${vz{0}})) {
+
 
          $request->setOID($myOID.".1.".$vzidReq.".0");
+
if(!defined($resReq) && defined(${vz{0}})) {
      $request->setValue(ASN_OCTET_STR, "".${vz{0}});
+
        $request->setOID($myOID.".1.".$vzidReq.".0");
  } elsif(!defined($catReq) && defined(${vz{$resReq}[0]})) {
+
    $request->setValue(ASN_OCTET_STR, "".${vz{0}});
          $request->setOID($myOID.".1.".$vzidReq.".".$resReq.".0");
+
} elsif(!defined($catReq) && defined(${vz{$resReq}[0]})) {
      $request->setValue(ASN_INTEGER, ${vz{$resReq}[0]});
+
        $request->setOID($myOID.".1.".$vzidReq.".".$resReq.".0");
  } elsif($catReq< $#catName && defined(${vz{$resReq}[$catReq]})) {
+
    $request->setValue(ASN_INTEGER, ${vz{$resReq}[0]});
      $request->setOID($myOID.".1.".$vzidReq.".".$resReq.".".($catReq+1));
+
} elsif($catReq< $#catName && defined(${vz{$resReq}[$catReq]})) {
      if(9223372036854775807 == ${vz{$resReq}[$catReq+1]}) {
+
    $request->setOID($myOID.".1.".$vzidReq.".".$resReq.".".($catReq+1));
  $request->setValue(ASN_INTEGER,-1);
+
    if(9223372036854775807 == ${vz{$resReq}[$catReq+1]}) {
      } else {
+
$request->setValue(ASN_INTEGER,-1);
  $request->setValue(ASN_INTEGER,${vz{$resReq}[$catReq+1]});
+
    } else {
      }
+
$request->setValue(ASN_INTEGER,${vz{$resReq}[$catReq+1]});
  } elsif($resReq<scalar keys %vz && defined(${vz{$resReq+1}[0]})) {
+
    }
      $request->setOID($myOID.".1.".$vzidReq.".".($resReq+1).".0");
+
} elsif($resReq<scalar keys %vz && defined(${vz{$resReq+1}[0]})) {
      if(9223372036854775807 == ${vz{$resReq}[$catReq+1]}) {
+
    $request->setOID($myOID.".1.".$vzidReq.".".($resReq+1).".0");
  $request->setValue(ASN_INTEGER,-1);
+
    if(9223372036854775807 == ${vz{$resReq}[$catReq+1]}) {
      } else {
+
$request->setValue(ASN_INTEGER,-1);
  $request->setValue(ASN_INTEGER, ${vz{$resReq+1}[0]});
+
    } else {
      }
+
$request->setValue(ASN_INTEGER, ${vz{$resReq+1}[0]});
  } else  {
+
    }
      my $finish=1;
+
} else  {
      foreach $vzid (sort keys %beancounters) {
+
    my $finish=1;
  if($vzid > $vzidReq) {
+
    foreach $vzid (sort keys %beancounters) {
      %vz=%{${beancounters{$vzid}}};
+
if($vzid > $vzidReq) {
      $vzidReq=$vzid;
+
    %vz=%{${beancounters{$vzid}}};
      $finish=0;
+
    $vzidReq=$vzid;
      last;
+
    $finish=0;
  }
+
    last;
      }
+
}
      if(!$finish)  {
+
    }
  $request->setOID($myOID.".1.".$vzidReq.".0.0");
+
    if(!$finish)  {
  $request->setValue(ASN_OCTET_STR, ${vz{0}});
+
$request->setOID($myOID.".1.".$vzidReq.".0.0");
      }
+
$request->setValue(ASN_OCTET_STR, ${vz{0}});
  }
+
    }
      }
+
}
          }
+
    }
      }
+
        }
  }  
+
    }
 
+
}  
  {
+
 
          my $regoid = new NetSNMP::OID($OID);  
+
{
          $agent->register($program, $regoid, \&handler);
+
        my $regoid = new NetSNMP::OID($OID);  
  }
+
        $agent->register($program, $regoid, \&handler);
 
+
}
 
+
 
 
+
 
  #eof // nick
+
 
 
+
#eof // nick
 +
</source>
 
=== /etc/snmp/snmpd.conf ===
 
=== /etc/snmp/snmpd.conf ===
  

Revision as of 17:33, 6 March 2009

Here is snmp subagent to export UBC via SNMP protocol.

Author - n1ckname. License: GNU GPL v2.


/etc/snmp/snmpagent.pl

#!/usr/bin/perl 

$program = $0;

use NetSNMP::OID (':all');
use NetSNMP::agent (':all');
use NetSNMP::ASN (':all');
use Data::Dumper;
my $debug = 0;
my @resName=qw(name vmguarpages tcpsndbuf othersockbuf physpages numfile numtcpsock numpty numsiginfo tcprcvbuf dcachesize numiptent numothersock privvmpages kmemsize numflock shmpages lockedpages dummy numproc oomguarpages dgramrcvbuf);
my @catName=qw(held maxheld barrier limit failcnt);
my %resIndex,%catIndex;
@resIndex{@resName} = (0..$#resName);
@catIndex{@catName} = (0..$#catName);

sub handler { 
    my ($handler, $reg_info, $request_info, $requests) = @_; 
    open(UB,"<$source");
    while(<UB>){
        my %vmachine;
        if ( /\D*(\d+):[\s\t]+([a-z]+)[\t\s]+(\d+)[\t\s]+(\d+)[\t\s]+(\d+)[\t\s]+(\d+)[\t\s]+(\d+).*/ ){ 
	    $vid=$1; 
	    $beancounters{$vid}=\%vmachine ; 
            ${beancounters{$vid}{0}}="www";
	    open(CONF,"</etc/vz/conf/$vid.conf");
	    my $name=$vid;
	    while(<CONF>) {
		if(/NAME[\s\t]?=[\s\t]?["]?([^"]+)["]?/)  {
		    $name=$1;
		    last;
		    #"
		}
	    }
	    ${beancounters{$vid}{0}}=$name;
            $resource=$2 ;
            $held=$3 ;
            $maxheld=$4 ;
            $barrier=$5 ;
            $limit=$6 ;
            $failcnt=$7 ;
            ${beancounters{$vid}}{${resIndex{$resource}}}=[$held , $maxheld , $barrier , $limit ,$failcnt ];

	}
        if ( /^[\W\d]+([a-z]+)[\t\s]+(\d+)[\t\s]+(\d+)[\t\s]+(\d+)[\t\s]+(\d+)[\t\s]+(\d+).*/ ) {
                $resource=$1 ;
                $held=$2 ;
                $maxheld=$3 ;
                $barrier=$4 ;
                $limit=$5 ;
                $failcnt=$6 ;
                ${beancounters{$vid}}{${resIndex{$resource}}}=[$held , $maxheld , $barrier , $limit ,$failcnt ];
        }
    }
    close(UB);

    for ( my $request = $requests; $request; $request = $request->next() ) {
    
        my $reqOID = $request->getOID();
        my $reqMode = $request_info->getMode();
	my $myOID = new NetSNMP::OID($OID);
#1.3.6.1.4.1.2021.51.ctcount = 5
#1.3.6.1.4.1.2021.51.ct.101.name = www
#1.3.6.1.4.1.2021.51.ct.101.kmemsize.held = 458584
#1.3.6.1.4.1.2021.51.ct.101.kmemsize.maxheld = 1490364
#1.3.6.1.4.1.2021.51.ct.101.kmemsize.barrier = 11055923

#		$request->setValue(ASN_INTEGER, scalar keys (%beancounters));

        if ($reqMode == MODE_GET) {
	    print STDERR $reqOID." MODE_GET\n" if($debug);;
    	    if($reqOID == $myOID+".0"){
		$request->setValue(ASN_INTEGER, scalar keys (%beancounters));
	    } elsif($reqOID =~ /$myOID\.([0-9]+)[\.]?([0-9]+)?[\.]?([0-9]+)?[\.]?([0-9]+)?/) {

		my $typeReq=$1;
		my $vzidReq=$2;
		my $resReq=$3;
		my $catReq=$4;
		my %vz;
		

		print STDERR "Type:$typeReq, VzID: $vzidReq, Res: $resReq/$resName[$resReq], Cat: $catReq/$catName[$catReq]\n" if($debug);;

		if(!$vzidReq) {
		    foreach $vzid (sort keys %beancounters) {
			$vzidReq=$vzid;
			last;
		    }
		}
		if(!$vzidReq || !exists(${beancounters{$vzidReq}})) {
		    $request->setError($request_info,SNMP_ERR_NOSUCHNAME);
		    last;
		}

		%vz=%{${beancounters{$vzidReq}}};

		if((!defined($resReq) or $resReq == 0) && defined(${vz{0}})) {
		    $request->setValue(ASN_OCTET_STR, "".${vz{0}});
		} elsif(!defined($catReq) && defined(${vz{$resReq}[0]})) {
		    $request->setValue(ASN_INTEGER, ${vz{$resReq}[0]});

		} elsif($catReq< $#catName && defined(${vz{$resReq}[$catReq]})) {
		    if(9223372036854775807 == ${vz{$resReq}[$catReq+1]}) {
			$request->setValue(ASN_INTEGER,-1);
		    } else {
			$request->setValue(ASN_INTEGER,${vz{$resReq}[$catReq+1]});
		    }
		} elsif($resReq<scalar keys %vz && defined(${vz{$resReq+1}[0]})) {
		    if(9223372036854775807 == ${vz{$resReq}[$catReq+1]}) {
			$request->setValue(ASN_INTEGER,-1);
		    } else {
			$request->setValue(ASN_INTEGER, ${vz{$resReq+1}[0]});
		    }
		} else  {
		    my $finish=1;
		    foreach $vzid (sort keys %beancounters) {
			if($vzid > $vzidReq) {
			    %vz=%{${beancounters{$vzid}}};
			    $vzidReq=$vzid;
			    $finish=0;
			    last;
			}
		    }
		    if(!$finish)  {
			$request->setValue(ASN_INTEGER, "".${vz{0}});
		    }
		}
    		

	    }

	} elsif ($reqMode == MODE_GETNEXT) {
	    print STDERR $reqOID." MODE_GETNEXT\n" if($debug);
    	    if($reqOID < $myOID+".0"){
    		$request->setOID($OID.".0");
		$request->setValue(ASN_INTEGER, scalar keys (%beancounters));
	    } elsif($reqOID =~ /$myOID\.([0-9]+)[\.]?([0-9]+)?[\.]?([0-9]+)?[\.]?([0-9]+)?$/) {
		my $typeReq=$1;
		my $vzidReq=$2;
		my $resReq=$3;
		my $catReq=$4;
		my %vz;
		
		print STDERR "Type:$typeReq, VzID: $vzidReq, Res: $resReq/$resName[$resReq], Cat: $catReq/$catName[$catReq]\n" if($debug);;

		if(!$vzidReq) {
		    foreach $vzid (sort keys %beancounters) {
			$vzidReq=$vzid;
			last;
		    }
		}
		if(!$vzidReq || !exists(${beancounters{$vzidReq}})) {
		    $request->setError($request_info,SNMP_ERR_NOSUCHNAME);
		    last;
		}


		%vz=%{${beancounters{$vzidReq}}};

		if(!defined($resReq) && defined(${vz{0}})) {
    		    $request->setOID($myOID.".1.".$vzidReq.".0");
		    $request->setValue(ASN_OCTET_STR, "".${vz{0}});
		} elsif(!defined($catReq) && defined(${vz{$resReq}[0]})) {
    		    $request->setOID($myOID.".1.".$vzidReq.".".$resReq.".0");
		    $request->setValue(ASN_INTEGER, ${vz{$resReq}[0]});
		} elsif($catReq< $#catName && defined(${vz{$resReq}[$catReq]})) {
		    $request->setOID($myOID.".1.".$vzidReq.".".$resReq.".".($catReq+1));
		    if(9223372036854775807 == ${vz{$resReq}[$catReq+1]}) {
			$request->setValue(ASN_INTEGER,-1);
		    } else {
			$request->setValue(ASN_INTEGER,${vz{$resReq}[$catReq+1]});
		    }
		} elsif($resReq<scalar keys %vz && defined(${vz{$resReq+1}[0]})) {
		    $request->setOID($myOID.".1.".$vzidReq.".".($resReq+1).".0");
		    if(9223372036854775807 == ${vz{$resReq}[$catReq+1]}) {
			$request->setValue(ASN_INTEGER,-1);
		    } else {
			$request->setValue(ASN_INTEGER, ${vz{$resReq+1}[0]});
		    }
		} else  {
		    my $finish=1;
		    foreach $vzid (sort keys %beancounters) {
			if($vzid > $vzidReq) {
			    %vz=%{${beancounters{$vzid}}};
			    $vzidReq=$vzid;
			    $finish=0;
			    last;
			}
		    }
		    if(!$finish)  {
			$request->setOID($myOID.".1.".$vzidReq.".0.0");
			$request->setValue(ASN_OCTET_STR, ${vz{0}});
		    }
		}
	    }
        }
    }
} 

{
        my $regoid = new NetSNMP::OID($OID); 
        $agent->register($program, $regoid, \&handler);
}



#eof // nick

/etc/snmp/snmpd.conf

 rouser my_username priv
 createUser my_username MD5 my_password DES
 perl $OID = '.1.3.6.1.4.1.2021.51'; 
 perl $debugging = '1';
 perl $verbose = '1';
 perl $source = '/proc/user_beancounters'; 
 perl do "/etc/snmp/snmpagent.pl";