Open main menu

OpenVZ Virtuozzo Containers Wiki β

Changes

Net-SNMP subagent

272 bytes removed, 17:42, 6 March 2009
trivial whitespace fixes
<source lang="perl">
#!/usr/bin/perl
$program = $0;
@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;
}
${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
# $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 $catReq=$4;
my %vz;
print STDERR "Type:$typeReq, VzID: $vzidReq, Res: $resReq/$resName[$resReq], Cat: $catReq/$catName[$catReq]\n" if($debug);;
}
}
 
}
} 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 $catReq=$4;
my %vz;
print STDERR "Type:$typeReq, VzID: $vzidReq, Res: $resReq/$resName[$resReq], Cat: $catReq/$catName[$catReq]\n" if($debug);;
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]})) {
}
}
}
}
}
{
my $regoid = new NetSNMP::OID($OID); $agent->register($program, $regoid, \&handler);
}
 
 
#eof // nick