I'm not familiar with POE::Component::SNMP, but I have a question. How many @reachable_hosts do you have?

 $heap->{pending} = scalar(@reachable_hosts)-1;

If you have 1 reachable host, then $heap->{pending} = 0.

 if (--$heap->{pending} == 0) {
   $kernel->post( $alias => 'finish' );
 }

$heap->{pending} would be decremented to -1, and 'finish' would never occur?

If @reachable_hosts > 1, then "finish" occurs before the last host reports? That sounds as if that could lose a host.

--
Rocco Caputo - rcap...@pobox.com


On Oct 28, 2010, at 06:36, Rehan Azher wrote:

OK I enabled the  debug option

and this is what i got in the end :

No response from remote host "100.2.33.254"
debug: [187] POE::Component::SNMP::close_snmp_session: calling
__clear_pending
debug: [604] POE::Component::SNMP::Dispatcher::__clear_pending(): start debug: [615] POE::Component::SNMP::Dispatcher::__clear_pending(): clearing 0
pending requests
debug: [313] POE::Component::SNMP::Dispatcher::_unwatch_socket(): [152]
refcount 0, unselect
debug: [645] POE::Component::SNMP::Dispatcher::__clear_pending(): done

and here it hangs.


Best Regards,


--
Rehan Azher
Cell: +65 92967887
LinkedIn: http://www.linkedin.com/in/rehanazher


On Thu, Oct 28, 2010 at 11:03 AM, Rehan Azher <rehan.az...@gmail.com> wrote:

Hi Experts,

I am new to POE, and to be on true end do not have more perl experience except some small scripts. Now I am trying to POLL one Subnet Range using
POE::Component::SNMP. Results  are displayed but at the end when
$heap->{pending}=0 it dosent seems to exit the snmp_handler sub .


Following is my code:

POE::Session->create( inline_states =>
                           { _start       => \&_start_subnet_system,
snmp_handler => \&snmp_subnet_system_handler,
                           }
                     );
                     sub _start_subnet_system {
                       my ($kernel, $heap) = @_[KERNEL, HEAP];
                       foreach my $address (@reachable_hosts) {
                           POE::Component::SNMP->create( alias =>
"$address",
                             hostname  => "$address",
# if you have seperate community strings for
each host
                             # build a hash (@addresses becomes
%addresses)and
# associate them that way and then set it
here.
                             community =>
$snmp_settings[$temp_loop]{'community_string'},
                             version
=>$snmp_settings[$temp_loop]{'snmp_version'},
                             timeout
=>$snmp_settings[$temp_loop]{'timeout'},
                             retries
=>$snmp_settings[$temp_loop]{'retries'},
                             # debug => 0x0A,
                           );
                           $kernel->post( $address => walk     =>
snmp_handler =>  -baseoid        => $system_oid);
# If you are polling for N oids, this next line
must reflect that, otherwise
# it will stop after the first OID and not try
any of the others.
$heap->{pending} = scalar(@reachable_hosts)-1;
                       }
                   }
                   $poe_kernel->run();
                   print "Total Discovered Hosts:
$discovered_host_count\n";
                   print "Total Not Discovered Hosts:
$not_discovered_host_count\n";
sub snmp_subnet_system_handler {
   my ($kernel, $heap, $request, $response) = @_[KERNEL, HEAP, ARG0,
ARG1];
   my ($alias, $host, $cmd, @args) = @$request;
   my ($results, @callback_args)   = @$response;
   if (ref $results) {
         $discovered_host_count++;
   } else {
       $not_discovered_host_count++;
   }
    if (--$heap->{pending} == 0) {
*          $kernel->post( $alias => 'finish' );*
   }
}

Where:

@reachable_hosts contains all hosts which are reachable via ICMP Ping. @snmp_settings is a hash of SNMP Settings need to be apploed , tested and
printed all the values it has all valued required.
$system_oid = '.1.3.6.1.2.1.1'

In fact this is a modified version of this code:

http://www.gdd.net/index.php/Asynchronous_SNMP_poller_%28Perl%29

Above code also hangs at this point *$kernel->post( $alias => 'finish' );*

Can Any pone pelase help on this.


Best Regards,


--
Rehan Azher
Cell: +65 92967887
LinkedIn: http://www.linkedin.com/in/rehanazher



Reply via email to