Send Netdot-devel mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        https://osl.uoregon.edu/mailman/listinfo/netdot-devel
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Netdot-devel digest..."


Today's Topics:

   1. [SCM] Netdot branch master updated.       netdot-1.0.4-71-g433965b
      ([email protected])
   2. [SCM] Netdot branch netdot-1.0 updated.
      netdot-1.0.4-72-g6d28893 ([email protected])
   3. [SCM] Netdot branch master updated.       netdot-1.0.4-74-g12c1bba
      ([email protected])
   4. [SCM] Netdot branch netdot-1.0 updated.
      netdot-1.0.4-74-g12c1bba ([email protected])


----------------------------------------------------------------------

Message: 1
Date: Mon, 20 May 2013 12:15:54 -0700
From: [email protected]
Subject: [Netdot-devel] [SCM] Netdot branch master updated.
        netdot-1.0.4-71-g433965b
To: [email protected]
Message-ID: <[email protected]>

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Netdot".

The branch, master has been updated
       via  433965b831be800fb25e4dfd54f0bcc9d92306e7 (commit)
      from  dfd8d058a733af369a234c7c98515f277a10065f (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
-----------------------------------------------------------------------

Summary of changes:
 lib/Netdot/Exporter.pm |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)


hooks/post-receive
-- 
Netdot


------------------------------

Message: 2
Date: Mon, 20 May 2013 12:47:07 -0700
From: [email protected]
Subject: [Netdot-devel] [SCM] Netdot branch netdot-1.0 updated.
        netdot-1.0.4-72-g6d28893
To: [email protected]
Message-ID: <[email protected]>

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Netdot".

The branch, netdot-1.0 has been updated
       via  6d288937ac31280afd4801292b76b9671b9faf8a (commit)
      from  433965b831be800fb25e4dfd54f0bcc9d92306e7 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 6d288937ac31280afd4801292b76b9671b9faf8a
Author: Carlos Vicente <[email protected]>
Date:   Mon May 20 15:46:57 2013 -0400

    Set subnet description from interface description

diff --git a/lib/Netdot/Model/Interface.pm b/lib/Netdot/Model/Interface.pm
index b0dfeb0..a025903 100644
--- a/lib/Netdot/Model/Interface.pm
+++ b/lib/Netdot/Model/Interface.pm
@@ -679,15 +679,21 @@ sub update_ip {
                
                # Skip validation for speed, since the block already exists
                $iargs{validate} = 0;
+               
+               # Add description from interface if not set
+               $iargs{description} = $self->description 
+                   if ( $subnetobj->description eq "" );
+
                $subnetobj->update(\%iargs); # Makes sure that the status is 
set to subnet
                
            }else{
                $logger->debug(sub{ sprintf("Subnet %s/%s does not exist.  
Inserting.", 
                                            $subnetaddr, $subnetprefix) });
                
-               $iargs{address} = $subnet_netaddr->addr;
-               $iargs{prefix}  = $subnet_netaddr->masklen;
-               $iargs{version} = $version;
+               $iargs{address}     = $subnet_netaddr->addr;
+               $iargs{prefix}      = $subnet_netaddr->masklen;
+               $iargs{version}     = $version;
+               $iargs{description} = $self->description;
                
                # Check if subnet should inherit device info
                if ( $args{subs_inherit} ){

-----------------------------------------------------------------------

Summary of changes:
 lib/Netdot/Model/Interface.pm |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)


hooks/post-receive
-- 
Netdot


------------------------------

Message: 3
Date: Tue, 21 May 2013 07:26:06 -0700
From: [email protected]
Subject: [Netdot-devel] [SCM] Netdot branch master updated.
        netdot-1.0.4-74-g12c1bba
To: [email protected]
Message-ID: <[email protected]>

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Netdot".

The branch, master has been updated
       via  12c1bbac8f47bc1a292369b154ae8860a6e1348e (commit)
       via  33f2092ede65f30dccca932c2d187db0aa9fcc00 (commit)
       via  6d288937ac31280afd4801292b76b9671b9faf8a (commit)
      from  433965b831be800fb25e4dfd54f0bcc9d92306e7 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 12c1bbac8f47bc1a292369b154ae8860a6e1348e
Merge: 6d28893 33f2092
Author: Carlos Vicente <[email protected]>
Date:   Tue May 21 10:25:28 2013 -0400

    Merge branch 'master' into netdot-1.0


commit 33f2092ede65f30dccca932c2d187db0aa9fcc00
Author: Carlos Vicente <[email protected]>
Date:   Tue May 21 10:25:08 2013 -0400

    Introduced optional, experimental support for SNMP Query Engine for faster 
asynchronous SNMP queries, as an alternative to process forking

diff --git a/etc/Default.conf b/etc/Default.conf
index db8d687..26ccaec 100644
--- a/etc/Default.conf
+++ b/etc/Default.conf
@@ -221,6 +221,9 @@ SNMP_MIB_DIRS            =>  [ 'allied', 'arista', 'aruba', 
'asante',
                               'hp', 'juniper', 'netscreen', 'net-snmp',
                               'nortel', 'rfc' ],
 
+# Experimental: use snmp-query-engine for SNMP queries
+## USE_SNMP_QUERY_ENGINE  => "127.0.0.1:7667",
+
 # Some versions of the SNMP perl module are broken.
 # Enable this flag if you know your module has been patched
 IGNORE_BUGGY_SNMP_CHECK  =>  0,
diff --git a/lib/Netdot/FakeSNMPSession.pm b/lib/Netdot/FakeSNMPSession.pm
new file mode 100644
index 0000000..a707e5a
--- /dev/null
+++ b/lib/Netdot/FakeSNMPSession.pm
@@ -0,0 +1,176 @@
+package Netdot::FakeSNMPSession;
+
+use strict;
+use warnings;
+use Carp;
+use Coro;
+use AnyEvent;
+use Net::SNMP::QueryEngine::AnyEvent;
+use Socket;
+use Data::Dump 'pp', 'dd';
+use SNMP;  # we use that for OID translation
+
+sub new
+{
+    my ($class, %p) = @_;
+    my $me = bless \%p, $class;
+    $me->_self_check;
+
+    my %setopt;
+    $setopt{version}         = $me->{Version};
+    $setopt{community}       = $me->{Community} || "public";
+    $setopt{timeout}         = int($me->{Timeout}/1000+0.5) if $me->{Timeout};
+    $setopt{retries}         = $me->{Retries} if $me->{Retries};
+    $setopt{max_repetitions} = $me->{BulkRepeaters} if $me->{BulkRepeaters};
+
+    # XXX Handle DestHost name resolution here.  Use AnyEvent::DNS for that.
+    #       kinda working method: $me->{ip} = inet_ntoa(scalar gethostbyname 
$p{DestHost});
+    $me->{ip} = $me->{DestHost};
+
+    my $callback = rouse_cb;
+    $me->{sqe}->setopt($me->{ip}, 161, \%setopt, $callback);
+    rouse_wait $callback;  # no reason to check for errors here
+
+    # $me->{debug_session} = SNMP::Session->new(%p);
+    $me;
+}
+
+sub _self_check
+{
+    my $me = shift;
+       my $class = ref($me) || $me;
+    for my $p (qw(sqe DestHost Version)) {
+       croak("$class:\:new: argument \"$p\" must be supplied") unless 
$me->{$p};
+    }
+    croak("$class:\:new: unsupported SNMP version: $me->{Version}")
+       unless $me->{Version} == 1 || $me->{Version} == 2;
+}
+
+sub DESTROY {}
+
+sub AUTOLOAD
+{
+    croak("IMPLEMENT ME: called $Netdot::FakeSNMPSession::AUTOLOAD");
+}
+
+sub getnext
+{
+    my $me = shift;
+    my $var = shift;
+    croak("IMPLEMENT ME: extra parameters to getnext(): " . pp(\@_)) if @_;
+    croak("IMPLEMENT ME: var is not a SNMP::Varbind: " . pp($var))
+       unless ref($var) && ref($var) eq "SNMP::Varbind";
+
+    if (@$var < 4) {
+       my $base = $var->[0];
+       $base = SNMP::translateObj($base) unless $base =~ /^[\d.]+$/;
+       $base =~ s/^\.//;
+       $base .= ".$var->[1]" if @$var >= 2;
+       my $callback = rouse_cb;
+       $me->{sqe}->gettable($me->{ip}, 161, $base, $callback);
+       my ($sqe, $ok, $res) = rouse_wait $callback;
+       # XXX error handling
+       my @answers;
+       for my $r (@$res) {
+           my $v = $r->[1];
+           $v = "NOSUCHOBJECT" if ref $v && $v->[0] eq "no-such-object";
+           next if ref $v;
+           my $idx = $r->[0];
+           $idx =~ s/^\.?\Q$base\E\.//;
+           $v = ".$v" if $v && $v =~ /^1\.3\.6(?:\.\d+)+$/;
+           push @answers, [$idx, $v];
+       }
+       $var->[4] = \@answers;
+    }
+    my $ans = shift @{$var->[4]};
+    $ans = ["", ""] unless $ans;
+    $var->[1] = $ans->[0];
+    $var->[2] = $ans->[1];
+    $var->[3] = "OCTETSTR"; # whatever
+    # print "returning $var->[0].$var->[1]=>$var->[2]\n";
+    return $ans->[1];
+}
+
+sub get
+{
+    my ($me, $v, $cb) = @_;
+
+    if (ref($v)) {
+       if (ref($v) eq "SNMP::Varbind") {
+           if (@$v == 1) {
+               $v = $v->[0];
+           }
+       }
+    }
+    croak("IMPLEMENT ME: GET var is a reference we cannot (for now) handle: " 
. pp($v))
+       if ref $v;
+
+    my $oid = $v;
+    $oid = SNMP::translateObj($oid) unless $oid =~ /^[\d.]+$/;
+    $oid =~ s/^\.//;
+
+    my $callback = rouse_cb;
+    $me->{sqe}->get($me->{ip}, 161, [$oid], $callback);
+    my ($sqe, $ok, $res) = rouse_wait $callback;
+    # print STDERR "SQE: $v/$oid: ", pp($res), "ok: ", pp($ok), "\n";
+
+    # XXX error handling MUST be implemented here
+
+    return unless $res && @$res;
+    my $ret = $res->[0][1];
+    $ret = "NOSUCHOBJECT" if ref $ret && $ret->[0] eq "no-such-object";
+    return if ref $ret;  # error in reply
+    $ret = "NOSUCHOBJECT" if !defined $ret && $me->{Version} == 1;
+
+    # SNMP::Info expects OIDs in a form ".a.b.c", while
+    # SQE returns OIDSs in "a.b.c" form, account for that:
+    $ret = ".$ret" if $ret && $ret =~ /^1\.3\.6(?:\.\d+)+$/;
+
+    return $ret;
+}
+
+sub bulkwalk
+{
+       my ($me, $non_repeaters, $max_repeaters, $vars) = @_;
+       croak "Internal: non-zero non-repeaters value not supported"
+               if $non_repeaters;
+       croak "Vars must be a reference"
+               unless ref $vars;
+       croak "Internal: only SNMP::Varbind vars are supported"
+               unless ref($vars) eq "SNMP::Varbind";
+               
+       my $oid = $vars->[0];
+       $oid = SNMP::translateObj($oid) unless $oid =~ /^[\d.]+$/;
+       $oid =~ s/^\.//;
+
+       #print "bulkwalk: $oid, R($max_repeaters)\n";
+       my $callback = rouse_cb;
+       # XXX non-default port
+       $me->{sqe}->gettable($me->{ip}, 161, $oid, $callback);
+       my ($sqe, $ok, $res) = rouse_wait $callback;
+       #print "Ahaha $sqe,$ok\n";
+
+       #my $real = $me->{debug_session}->bulkwalk($non_repeaters, 
$max_repeaters, $vars);
+       #print "Real thing:\n";
+       #dd $real;
+
+#print "GOT TABLE from $oid ($vars->[0])\n";
+       # XXX error handling
+       my @r;
+       for my $r (@$res) {
+               my $v = $r->[1];
+               $v = "NOSUCHOBJECT" if ref $v && $v->[0] eq "no-such-object";
+               next if ref $v;
+               my $idx = $r->[0];
+               $idx =~ s/^\.?\Q$oid\E\.//;
+
+               $v = ".$v" if $v && $v =~ /^1\.3\.6(?:\.\d+)+$/;
+               push @r, bless([ $vars->[0], $idx, $v, "OCTETSTR" ], 
"SNMP::Varbind");
+       }
+       #print "Unreal thing:\n";
+       #dd [bless(\@r, "SNMP::VarList")];
+
+       return (bless(\@r, "SNMP::VarList"));
+}
+
+1;
diff --git a/lib/Netdot/Model/Device.pm b/lib/Netdot/Model/Device.pm
index 4c0cc81..32a775b 100644
--- a/lib/Netdot/Model/Device.pm
+++ b/lib/Netdot/Model/Device.pm
@@ -846,7 +846,7 @@ sub get_snmp_info {
                                                                           
'sclass'      => $sinfo->class);
 
                                    return unless $vsinfo;
-  
+                                   
                                    $stp_p_info = $class->_exec_timeout( 
                                        $args{host}, 
                                        sub{  return 
$self->_get_stp_info(sinfo=>$vsinfo) } 
@@ -892,9 +892,9 @@ sub get_snmp_info {
                                                                       
'communities' => [$comm],
                                                                       
'version'     => $sinfo->snmp_ver,
                                                                       'sclass' 
     => $sinfo->class);
-                               
+
                                return unless $vsinfo;
-                               
+
                                my $stp_p_info = $class->_exec_timeout( 
                                    $args{host}, 
                                    sub{  return 
$self->_get_stp_info(sinfo=>$vsinfo) } );
@@ -1447,6 +1447,7 @@ sub discover {
                                                   auth_pass   => 
$argv{auth_pass},
                                                   priv_proto  => 
$argv{priv_proto},
                                                   priv_pass   => 
$argv{priv_pass},
+                                                  sqe         => $argv{sqe},
                    );
 
                return unless $sinfo;
@@ -1553,7 +1554,8 @@ sub discover {
     my %uargs;
     foreach my $field ( qw(communities version timeout retries 
                            sec_name sec_level auth_proto auth_pass priv_proto 
priv_pass
-                           add_subnets subs_inherit bgp_peers pretend do_info 
do_fwt do_arp timestamp) ){
+                           add_subnets subs_inherit bgp_peers pretend do_info 
do_fwt do_arp timestamp
+                          sqe) ){
        $uargs{$field} = $argv{$field} if defined ($argv{$field});
     }
     $uargs{session}       = $sinfo if $sinfo;
@@ -2729,6 +2731,7 @@ sub snmp_update {
                                          auth_pass   => $argv{auth_pass},
                                          priv_proto  => $argv{priv_proto},
                                          priv_pass   => $argv{priv_pass},
+                                         sqe         => $argv{sqe},
            );
 
        return unless $sinfo;
@@ -3759,7 +3762,7 @@ sub _validate_args {
            if ( defined $self ){
                if ( $self->id != $otherdev->id ){
                    my $msg = sprintf("%s: Existing device: %s uses S/N %s, MAC 
%s", 
-                                     $self->fqdn, $otherdev->fqdn, 
$asset->serial_number, 
+                                     $self->fqdn, $otherdev->fqdn, 
$asset->serial_number,
                                      $asset->physaddr);
                    if ( Netdot->config->get('ENFORCE_DEVICE_UNIQUENESS') ){
                        $self->throw_user($msg); 
@@ -3836,6 +3839,16 @@ sub _layer_active {
 #     my $session = Device->get_snmp_session(host=>$hostname, 
communities=>['public']);
 #
 
+sub _make_sinfo_object
+{
+    my ($self, $sclass, %sinfoargs) = @_;
+    if ($sinfoargs{sqe}) {
+       $sinfoargs{Session} = Netdot::FakeSNMPSession->new(%sinfoargs);
+       $logger->debug(sub{"Device::_make_sinfo_object: with SQE" });
+    }
+    return $sclass->new( %sinfoargs );
+}
+
 sub _get_snmp_session {
     my ($self, %argv) = @_;
 
@@ -3904,10 +3917,11 @@ sub _get_snmp_session {
        BulkWalk    => (defined $argv{bulkwalk}) ? $argv{bulkwalk} :  
$self->config->get('DEFAULT_SNMPBULK'),
        BulkRepeaters => $self->config->get('DEFAULT_SNMPBULK_MAX_REPEATERS'),
        MibDirs       => \@MIBDIRS,
+       sqe           => $argv{sqe},
        );
 
     # Turn off bulkwalk if we're using Net-SNMP 5.2.3 or 5.3.1.
-    if ( $sinfoargs{BulkWalk} == 1  && ($SNMP::VERSION eq '5.0203' || 
$SNMP::VERSION eq '5.0301') 
+    if ( !$sinfoargs{sqe} && $sinfoargs{BulkWalk} == 1  && ($SNMP::VERSION eq 
'5.0203' || $SNMP::VERSION eq '5.0301') 
        && !$self->config->get('IGNORE_BUGGY_SNMP_CHECK')) {
        $logger->info("Turning off bulkwalk due to buggy Net-SNMP 
$SNMP::VERSION");
        $sinfoargs{BulkWalk} = 0;
@@ -3946,7 +3960,7 @@ sub _get_snmp_session {
        $logger->debug(sub{ sprintf("Device::get_snmp_session: Trying SNMPv%d 
session with %s",
                                    $sinfoargs{Version}, $argv{host})});
        
-       $sinfo = $sclass->new( %sinfoargs );
+       $sinfo = $self->_make_sinfo_object($sclass, %sinfoargs);
 
        if ( defined $sinfo ){
            # Check for errors
@@ -3973,14 +3987,14 @@ sub _get_snmp_session {
            $logger->debug(sub{ sprintf("Device::_get_snmp_session: Trying 
SNMPv%d session with %s, ".
                                        "community %s",
                                        $sinfoargs{Version}, $argv{host}, 
$sinfoargs{Community})});
-           $sinfo = $sclass->new( %sinfoargs );
+           $sinfo = $self->_make_sinfo_object($sclass, %sinfoargs);
            
            # If v2 failed, try v1
            if ( !defined $sinfo && $sinfoargs{Version} == 2 ){
                $logger->debug(sub{ sprintf("Device::_get_snmp_session: %s: 
SNMPv%d failed. Trying SNMPv1", 
                                            $argv{host}, $sinfoargs{Version})});
                $sinfoargs{Version} = 1;
-               $sinfo = $sclass->new( %sinfoargs );
+               $sinfo = $self->_make_sinfo_object($sclass, %sinfoargs);
            }
            
            if ( defined $sinfo ){
@@ -4328,9 +4342,65 @@ sub _fork_end {
 #   Returns: 
 #     Device count
 #
+sub async (&@);
 sub _snmp_update_parallel {
     my ($class, %argv) = @_;
     $class->isa_class_method('_snmp_update_parallel');
+    my $use_sqe = Netdot->config->get('USE_SNMP_QUERY_ENGINE');
+    my $sqe;
+    if ($use_sqe && !$Netdot::Model::Device::_sqe_module_loaded) {
+       $logger->info("SQE is requested, trying to load relevant modules");
+       eval {
+           require Coro; Coro->import;
+           require AnyEvent; AnyEvent->import;
+           require Coro::AnyEvent; Coro::AnyEvent->import;
+           require Netdot::FakeSNMPSession; Netdot::FakeSNMPSession->import;
+           require Net::SNMP::QueryEngine::AnyEvent; 
Net::SNMP::QueryEngine::AnyEvent->import;
+           $Netdot::Model::Device::_sqe_module_loaded = 1;
+           $logger->info("SQE-related modules loaded succesfully");
+       };
+       unless ($Netdot::Model::Device::_sqe_module_loaded) {
+           $logger->info("Failure loading SQE-related modules, disabling SQE: 
$@");
+           $use_sqe = "";
+       }
+    }
+    if ($use_sqe) {
+       my @conn = split /:/, $use_sqe;
+       my $check_done = AnyEvent->condvar;
+       eval {
+           $sqe = Net::SNMP::QueryEngine::AnyEvent->new(connect => \@conn,
+               on_connect => sub { $check_done->send },
+               on_error   => sub { $sqe = undef; $check_done->send },
+           );
+           $check_done->recv;
+           if ($sqe) {
+               $sqe->info(sub { my ($h,$ok,$r) = @_; $sqe = undef unless $ok 
});
+               $sqe->wait;
+           }
+       };
+    }
+    if ($sqe) {
+       $logger->info("SQE is requested and available, using it for SNMP 
collection");
+       $logger->debug("$class\::_snmp_update_parallel: Loading dummy 
SNMP::Info object");
+       my $dummy = SNMP::Info->new( DestHost    => 'localhost',
+                                    Version     => 1,
+                                    AutoSpecify => 0,
+                                    Debug       => ( $logger->is_debug() )? 1 
: 0,
+                                    MibDirs     => \@MIBDIRS,
+                                  );
+       $class->_snmp_update_parallel_sqe(%argv, sqe => $sqe);
+    } else {
+       if ($use_sqe) {
+           $logger->info("SQE daemon is NOT available, using traditional 
method for SNMP collection");
+       } else {
+           $logger->info("Using traditional method for SNMP collection");
+       }
+       $class->_snmp_update_parallel_traditional(%argv);
+    }
+}
+
+sub _snmp_update_parallel_args_check {
+    my ($class, %argv) = @_;
 
     my ($hosts, $devs);
     if ( defined $argv{hosts} ){
@@ -4345,16 +4415,143 @@ sub _snmp_update_parallel {
        $class->throw_fatal("Model::Device::_snmp_update_parallel: Missing 
required parameters: ".
                            "hosts or devs");
     }
-    
+
     my %uargs;
     foreach my $field ( qw(version timeout retries sec_name sec_level 
auth_proto auth_pass 
                            priv_proto priv_pass add_subnets subs_inherit 
bgp_peers pretend 
-                           do_info do_fwt do_arp) ){
+                           do_info do_fwt do_arp sqe) ){
        $uargs{$field} = $argv{$field} if defined ($argv{$field});
     }
 
     $uargs{no_update_tree} = 1;
     $uargs{timestamp}      = $class->timestamp;
+
+    return ($hosts, $devs, %uargs);
+}
+
+sub _snmp_update_get_device_args {
+    my ($class, $dev, %args) = @_;
+
+    if ( $args{do_info} ){
+       unless ( $dev->canautoupdate ){
+           $logger->debug(sub{ sprintf("%s: Auto Update option off", 
$dev->fqdn) });
+           $args{do_info} = 0;
+       }
+    }
+    if ( $args{do_fwt} ){
+       unless ( $dev->collect_fwt ){
+           $logger->debug(sub{ sprintf("%s: Collect FWT option off", 
$dev->fqdn) });
+           $args{do_fwt} = 0;
+       }
+    }
+    if ( $args{do_arp} ){
+       unless ( $dev->collect_arp ){
+           $logger->debug(sub{ sprintf("%s: Collect ARP option off", 
$dev->fqdn) });
+           $args{do_arp} = 0;
+       }
+    }
+
+    return %args;
+}
+
+sub _snmp_update_parallel_sqe {
+    my ($class, %argv) = @_;
+    $class->isa_class_method('_snmp_update_parallel_sqe');
+
+    my ($hosts, $devs, %uargs) = 
$class->_snmp_update_parallel_args_check(%argv);
+    
+    my %do_devs;
+    
+    my $device_count = 0;
+    my $n_polling_devices = 0;
+    my $start = time;
+
+    if ( $devs ){
+       foreach my $dev ( @$devs ){
+           # Put in list
+           $do_devs{$dev->id} = $dev;
+       }
+    }elsif ( $hosts ){
+       foreach my $host ( keys %$hosts ){
+           # Give preference to the community associated with the host
+           if ( my $commstr = $hosts->{$host} ){
+               $uargs{communities} = [$commstr];
+           }else{
+               $uargs{communities} = $argv{communities};
+           }
+           # If the device exists in the DB, we add it to the list
+           my $dev;
+           if ( $dev = $class->search(name=>$host)->first ){
+               $do_devs{$dev->id} = $dev;
+               $logger->debug(sub{ sprintf("%s exists in DB.", $dev->fqdn) });
+           }else{
+               $device_count++;
+               $n_polling_devices++;
+               async {
+                   eval { $class->discover(name=> $host, %uargs); };
+                   if ( my $e = $@ ){
+                       $logger->error($e);
+                       exit 1;
+                   }
+                   $n_polling_devices--;
+               };
+           }
+       }
+    }
+    
+    # Go over list of existing devices
+    while ( my ($id, $dev) = each %do_devs ){
+
+       if ( my $regex = $argv{matching} ){
+           unless ( $dev->fqdn =~ /$regex/o ){
+               next;
+           }
+       }
+       # Make sure we don't launch a process unless necessary
+       if ( $dev->is_in_downtime() ){
+           $logger->debug(sub{ 
sprintf("Model::Device::_snmp_update_parallel_sqe: %s in downtime.  Skipping", 
$dev->fqdn) });
+           next;
+       }
+
+       my %args = $class->_snmp_update_get_device_args($dev, %uargs);
+       unless ( $args{do_info} || $args{do_fwt} || $args{do_arp} ){
+           next;
+       }
+
+       $device_count++;
+       $n_polling_devices++;
+       async {
+           eval { $dev->snmp_update(%args); };
+           if ( my $e = $@ ){
+               $logger->error($e);
+               exit 1;
+           }
+           $n_polling_devices--;
+       };
+    }
+
+    while ($n_polling_devices > 0) {
+       Coro::AnyEvent::idle_upto(5);
+       Coro::AnyEvent::sleep(0.05);
+    }
+
+    # Rebuild the IP tree if ARP caches were updated
+    if ( $argv{do_arp} ){
+       Ipblock->build_tree(4);
+       Ipblock->build_tree(6);
+    }
+    my $runtime = time - $start;
+    $class->_update_poll_stats($uargs{timestamp}, $runtime);
+    
+    return $device_count;
+}
+
+sub _snmp_update_parallel_traditional {
+    my ($class, %argv) = @_;
+    $class->isa_class_method('_snmp_update_parallel_traditional');
+
+    my ($hosts, $devs, %uargs) = 
$class->_snmp_update_parallel_args_check(%argv);
+    
     my %do_devs;
     
     my $device_count = 0;
@@ -4408,33 +4605,16 @@ sub _snmp_update_parallel {
        }
        # Make sure we don't launch a process unless necessary
        if ( $dev->is_in_downtime() ){
-           $logger->debug(sub{ sprintf("Model::Device::_snmp_update_parallel: 
%s in downtime. Skipping", 
+           $logger->debug(sub{ 
sprintf("Model::Device::_snmp_update_parallel_traditional: %s in downtime. 
Skipping", 
                                        $dev->fqdn) });
            next;
        }
-       my %args = %uargs;
 
-       if ( $args{do_info} ){
-           unless ( $dev->canautoupdate ){
-               $logger->debug(sub{ sprintf("%s: Auto Update option off", 
$dev->fqdn) });
-               $args{do_info} = 0;
-           }
-       }
-       if ( $args{do_fwt} ){
-           unless ( $dev->collect_fwt ){
-               $logger->debug(sub{ sprintf("%s: Collect FWT option off", 
$dev->fqdn) });
-               $args{do_fwt} = 0;
-           }
-       }
-       if ( $args{do_arp} ){
-           unless ( $dev->collect_arp ){
-               $logger->debug(sub{ sprintf("%s: Collect ARP option off", 
$dev->fqdn) });
-               $args{do_arp} = 0;
-           }
-       }
+       my %args = $class->_snmp_update_get_device_args($dev, %uargs);
        unless ( $args{do_info} || $args{do_fwt} || $args{do_arp} ){
            next;
        }
+
        $device_count++;
        # FORK
        $pm->start and next;
@@ -5759,24 +5939,24 @@ sub _update_interfaces {
        if ( $int_thold <= 0 || $int_thold >= 1 ){
            $self->throw_fatal('Incorrect value for IF_COUNT_THRESHOLD in 
config file');
        }
-       
+
        my %old_snmp_ifs;
        map { $old_snmp_ifs{$_->id} = $_ } 
        grep { $_->doc_status eq 'snmp' } values %oldifs;
-       
+
        my $ifs_old = scalar(keys(%old_snmp_ifs));
        my $ifs_new = scalar(keys(%{$info->{interface}}));
-       
+
        $logger->debug("$host: Old Ifs: $ifs_old, New Ifs: $ifs_new");
 
-       if ( ($ifs_old && !$ifs_new) || ($ifs_new && ($ifs_new < $ifs_old) && 
+       if ( ($ifs_old && !$ifs_new) || ($ifs_new && ($ifs_new < $ifs_old) &&
                                         ($ifs_new / $ifs_old) <= $int_thold) ){
            $logger->warn(sprintf("%s: new/old interface ratio: %.2f is below 
INT_COUNT_THRESHOLD".
                                  "Skipping interface update. Re-discover 
manually if needed.",
                                  $host, $ifs_new/$ifs_old));
            return;
        }
-       
+
        # Do the same for IP addresses
        my $ips_old = scalar(keys(%old_ips));
        my $ips_new = 0;
@@ -5787,17 +5967,16 @@ sub _update_interfaces {
                $ips_new++;
            }
        }
-       
+
        $logger->debug("$host: Old IPs: $ips_old, New IPs: $ips_new");
 
-       if ( ($ips_old && !$ips_new) || ($ips_new && ($ips_new < $ips_old) && 
+       if ( ($ips_old && !$ips_new) || ($ips_new && ($ips_new < $ips_old) &&
                                         ($ips_new / $ips_old) <= $int_thold) ){
            $logger->warn(sprintf("%s: new/old IP ratio: %.2f is below 
INT_COUNT_THRESHOLD".
                                  "Skipping interface update. Re-discover 
manually if needed.",
                                  $host, $ips_new/$ips_old));
            return;
        }
-       
     }
 
     # Index by interface name (ifDescr) and number (ifIndex)
@@ -5964,9 +6143,9 @@ sub _update_interfaces {
        }
 
        # Don't delete snmp_target address unless updating via UI
-       if ( $ENV{REMOTE_USER} eq 'netdot' && 
+       if ( $ENV{REMOTE_USER} eq 'netdot' &&
             $self->snmp_target->id == $obj->id ){
-           $logger->debug(sub{sprintf("%s: IP %s is snmp target. Skipping 
delete", 
+           $logger->debug(sub{sprintf("%s: IP %s is snmp target. Skipping 
delete",
                                       $host, $obj->address)});
            next;
        }

-----------------------------------------------------------------------

Summary of changes:
 etc/Default.conf              |    3 +
 lib/Netdot/FakeSNMPSession.pm |  176 +++++++++++++++++++++++++++
 lib/Netdot/Model/Device.pm    |  261 ++++++++++++++++++++++++++++++++++-------
 lib/Netdot/Model/Interface.pm |   12 ++-
 4 files changed, 408 insertions(+), 44 deletions(-)
 create mode 100644 lib/Netdot/FakeSNMPSession.pm


hooks/post-receive
-- 
Netdot


------------------------------

Message: 4
Date: Tue, 21 May 2013 07:27:02 -0700
From: [email protected]
Subject: [Netdot-devel] [SCM] Netdot branch netdot-1.0 updated.
        netdot-1.0.4-74-g12c1bba
To: [email protected]
Message-ID: <[email protected]>

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Netdot".

The branch, netdot-1.0 has been updated
       via  12c1bbac8f47bc1a292369b154ae8860a6e1348e (commit)
       via  33f2092ede65f30dccca932c2d187db0aa9fcc00 (commit)
      from  6d288937ac31280afd4801292b76b9671b9faf8a (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
-----------------------------------------------------------------------

Summary of changes:
 etc/Default.conf              |    3 +
 lib/Netdot/FakeSNMPSession.pm |  176 +++++++++++++++++++++++++++
 lib/Netdot/Model/Device.pm    |  261 ++++++++++++++++++++++++++++++++++-------
 3 files changed, 399 insertions(+), 41 deletions(-)
 create mode 100644 lib/Netdot/FakeSNMPSession.pm


hooks/post-receive
-- 
Netdot


------------------------------

_______________________________________________
Netdot-devel mailing list
[email protected]
https://osl.uoregon.edu/mailman/listinfo/netdot-devel


End of Netdot-devel Digest, Vol 74, Issue 11
********************************************

Reply via email to