Hello, i asked this question before but didn't get much progress on it. can you see what is wrong here?

i am using snmp and alarm together to timeout a snmp query( to printer ) in mod_perl environment. 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


In reply to alarm problem with snmp query by Qiang

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.