Editing Net-SNMP subagent
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 7: | Line 7: | ||
<source lang="perl"> | <source lang="perl"> | ||
− | #!/usr/bin/perl | + | #!/usr/bin/perl |
$program = $0; | $program = $0; | ||
Line 22: | Line 22: | ||
@catIndex{@catName} = (0..$#catName); | @catIndex{@catName} = (0..$#catName); | ||
− | sub handler { | + | sub handler { |
− | my ($handler, $reg_info, $request_info, $requests) = @_; | + | my ($handler, $reg_info, $request_info, $requests) = @_; |
open(UB,"<$source"); | open(UB,"<$source"); | ||
while(<UB>){ | 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; | + | $vid=$1; |
− | $beancounters{$vid}=\%vmachine ; | + | $beancounters{$vid}=\%vmachine ; |
− | + | ${beancounters{$vid}{0}}="www"; | |
open(CONF,"</etc/vz/conf/$vid.conf"); | open(CONF,"</etc/vz/conf/$vid.conf"); | ||
my $name=$vid; | my $name=$vid; | ||
Line 41: | Line 41: | ||
} | } | ||
${beancounters{$vid}{0}}=$name; | ${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); | 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 $myOID = new NetSNMP::OID($OID); | my $myOID = new NetSNMP::OID($OID); | ||
#1.3.6.1.4.1.2021.51.ctcount = 5 | #1.3.6.1.4.1.2021.51.ctcount = 5 | ||
Line 74: | Line 75: | ||
# $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);; | print STDERR $reqOID." MODE_GET\n" if($debug);; | ||
− | + | if($reqOID == $myOID+".0"){ | |
$request->setValue(ASN_INTEGER, scalar keys (%beancounters)); | $request->setValue(ASN_INTEGER, scalar keys (%beancounters)); | ||
} elsif($reqOID =~ /$myOID\.([0-9]+)[\.]?([0-9]+)?[\.]?([0-9]+)?[\.]?([0-9]+)?/) { | } elsif($reqOID =~ /$myOID\.([0-9]+)[\.]?([0-9]+)?[\.]?([0-9]+)?[\.]?([0-9]+)?/) { | ||
Line 85: | Line 86: | ||
my $catReq=$4; | my $catReq=$4; | ||
my %vz; | 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);; | ||
Line 132: | Line 134: | ||
} | } | ||
} | } | ||
+ | |||
+ | |||
} | } | ||
} elsif ($reqMode == MODE_GETNEXT) { | } elsif ($reqMode == MODE_GETNEXT) { | ||
print STDERR $reqOID." MODE_GETNEXT\n" if($debug); | print STDERR $reqOID." MODE_GETNEXT\n" if($debug); | ||
− | + | if($reqOID < $myOID+".0"){ | |
− | + | $request->setOID($OID.".0"); | |
$request->setValue(ASN_INTEGER, scalar keys (%beancounters)); | $request->setValue(ASN_INTEGER, scalar keys (%beancounters)); | ||
} elsif($reqOID =~ /$myOID\.([0-9]+)[\.]?([0-9]+)?[\.]?([0-9]+)?[\.]?([0-9]+)?$/) { | } elsif($reqOID =~ /$myOID\.([0-9]+)[\.]?([0-9]+)?[\.]?([0-9]+)?[\.]?([0-9]+)?$/) { | ||
Line 145: | Line 149: | ||
my $catReq=$4; | my $catReq=$4; | ||
my %vz; | 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);; | ||
Line 163: | Line 167: | ||
if(!defined($resReq) && defined(${vz{0}})) { | if(!defined($resReq) && defined(${vz{0}})) { | ||
− | + | $request->setOID($myOID.".1.".$vzidReq.".0"); | |
$request->setValue(ASN_OCTET_STR, "".${vz{0}}); | $request->setValue(ASN_OCTET_STR, "".${vz{0}}); | ||
} elsif(!defined($catReq) && defined(${vz{$resReq}[0]})) { | } elsif(!defined($catReq) && defined(${vz{$resReq}[0]})) { | ||
− | + | $request->setOID($myOID.".1.".$vzidReq.".".$resReq.".0"); | |
$request->setValue(ASN_INTEGER, ${vz{$resReq}[0]}); | $request->setValue(ASN_INTEGER, ${vz{$resReq}[0]}); | ||
} elsif($catReq< $#catName && defined(${vz{$resReq}[$catReq]})) { | } elsif($catReq< $#catName && defined(${vz{$resReq}[$catReq]})) { | ||
Line 198: | Line 202: | ||
} | } | ||
} | } | ||
− | + | } | |
} | } | ||
− | } | + | } |
{ | { | ||
− | + | my $regoid = new NetSNMP::OID($OID); | |
− | + | $agent->register($program, $regoid, \&handler); | |
} | } | ||
+ | |||
+ | |||
#eof // nick | #eof // nick | ||
Line 218: | Line 224: | ||
perl $source = '/proc/user_beancounters'; | perl $source = '/proc/user_beancounters'; | ||
perl do "/etc/snmp/snmpagent.pl"; | perl do "/etc/snmp/snmpagent.pl"; | ||
− | |||
− | |||
− | |||
− |