You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by "James.Q.L" <sh...@yahoo.com> on 2004/03/12 00:44:45 UTC
snmp session and alarm
Hello,
i am using snmp and alarm together to timeout a snmp query( to printer ). however, once a timeout
happens with an alarm, the next snmp query with a different snmp session always inherit the
previous failed snmp query result. i also use the timeout property in snmp, but it doesn't seem to
do anything.
anyway here is code.
{
foreach $pr_section_name (values %{$config}) {
my $pr_name = $pr_section_name->{pr_name};
next unless $pr_name;
$pr_names{$pr_name}="";
next if $get_pr_names == 1;
my $cmnt = $pr_section_name->{cmnt};
my $ip = $pr_section_name->{ip};
my $lcd_mib_1 = $pr_section_name->{lcd_mib_1};
my $lcd_mib_2 = $pr_section_name->{lcd_mib_2};
my ($session, $error) = Net::SNMP->session(
-hostname => $ip,
-community => chomp($cmnt),
-port => 161,
-timeout => 5,
);
if (!defined($session)) {
print STDERR $error;
next;
}
my $pr_status = &_snmp_query($session,$status_mib) if $status_mib;
my $pr_lcd_msg = &_snmp_query($session,$lcd_msg_mib) if $lcd_msg_mib;
my $lcd_msg_1 = &_snmp_query($session,$lcd_mib_1) if $lcd_mib_1;
my $lcd_msg_2 = &_snmp_query($session,$lcd_mib_2) if $lcd_mib_2;
}
}
# snmp query
sub _snmp_query {
my ($s,$mib) = @_;
my $result;
# printer status
eval {
local $SIG{ALRM} = sub { die "alarm\n" };
alarm 2;
$result = $s->get_request(
-varbindlist => [$mib]
);
alarm 0;
};
if ($@) {
return unless $@ eq "alarm\n";
} else {
return lc($result->{$mib});
}
}
regards,
Qiang
__________________________________
Do you Yahoo!?
Yahoo! Search - Find what you�re looking for faster
http://search.yahoo.com
--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html
Re: snmp session and alarm
Posted by "James.Q.L" <sh...@yahoo.com>.
--- Stas Bekman <st...@stason.org> wrote:
> James.Q.L wrote:
> > my apology.
> >
> > i was thinking that was a problem with mod_perl somewhere in my code since the same snmp query
> > result is the same as the next one.
>
> It's possible, but you haven't even mentioned that you were running mod_perl
> ;). Have you tried running that code as a standalone program and it worked
> just fine?
>
turns out the problem is not related to mod_perl. i didn't set -retrives for the snmp session, so
it tries one more time when the first one failed. set -retrives to 0 fix it.
Qiang.
__________________________________
Do you Yahoo!?
Yahoo! Search - Find what you�re looking for faster
http://search.yahoo.com
--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html
Re: snmp session and alarm
Posted by Stas Bekman <st...@stason.org>.
James.Q.L wrote:
> my apology.
>
> i was thinking that was a problem with mod_perl somewhere in my code since the same snmp query
> result is the same as the next one.
It's possible, but you haven't even mentioned that you were running mod_perl
;). Have you tried running that code as a standalone program and it worked
just fine?
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html
Re: snmp session and alarm
Posted by "James.Q.L" <sh...@yahoo.com>.
my apology.
i was thinking that was a problem with mod_perl somewhere in my code since the same snmp query
result is the same as the next one.
Qiang
--- Stas Bekman <st...@stason.org> wrote:
> James.Q.L wrote:
> > Hello,
> >
> > i am using snmp and alarm together to timeout a snmp query( to printer ).
>
> are you sure you wanted to send this to the modperl list?
>
> Please find an appropriate list at: http://lists.perl.org/
>
> thanks.
> __________________________________________________________________
> Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
> http://stason.org/ mod_perl Guide ---> http://perl.apache.org
> mailto:stas@stason.org http://use.perl.org http://apacheweek.com
> http://modperlbook.org http://apache.org http://ticketmaster.com
__________________________________
Do you Yahoo!?
Yahoo! Search - Find what you�re looking for faster
http://search.yahoo.com
--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html
Re: snmp session and alarm
Posted by Stas Bekman <st...@stason.org>.
James.Q.L wrote:
> Hello,
>
> i am using snmp and alarm together to timeout a snmp query( to printer ).
are you sure you wanted to send this to the modperl list?
Please find an appropriate list at: http://lists.perl.org/
thanks.
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html