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.6-55-g3f415fa
      ([email protected])
   2. [SCM] Netdot branch netdot-1.0 updated.
      netdot-1.0.6-55-g3f415fa ([email protected])
   3. [SCM] Netdot branch anton created.        netdot-1.0.4-82-g2c41e4d
      ([email protected])
   4. [SCM] Netdot branch fix-1790 created.
      netdot-1.0.6-39-g47e9b76 ([email protected])
   5. [SCM] Netdot branch subnetvlan created.
      netdot-1.0.6-49-g0e914f8 ([email protected])
   6. [SCM] Netdot branch update_device_api created.
      netdot-1.0.6-53-g49af8c2 ([email protected])


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

Message: 1
Date: Thu, 18 Sep 2014 11:28:07 -0700
From: [email protected]
Subject: [Netdot-devel] [SCM] Netdot branch master updated.
        netdot-1.0.6-55-g3f415fa
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  3f415fabc24a2c0a6dd24bc0218952d9dfbeec0a (commit)
       via  dca676d54d912c28a7a3e9c332a881053f1f583c (commit)
       via  abc05ca93c3b226c059fcb2c1db55a0dd33927da (commit)
       via  6ab81402729190993515602632ee2ff7d2bae1a4 (commit)
       via  73acf42b64bb9112b347c92c2cf2035243d33ed0 (commit)
       via  7bdfac87c87d2b130771929d770efd569d57971a (commit)
      from  0e914f8c16a63a1cba587e9e79c815a93bc1cb76 (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 3f415fabc24a2c0a6dd24bc0218952d9dfbeec0a
Author: Carlos Vicente <[email protected]>
Date:   Thu Sep 18 14:27:40 2014 -0400

    Fix incorrect use of config variable in ASN class

diff --git a/lib/Netdot/Model/ASN.pm b/lib/Netdot/Model/ASN.pm
index 660a2f0..e8223aa 100644
--- a/lib/Netdot/Model/ASN.pm
+++ b/lib/Netdot/Model/ASN.pm
@@ -101,8 +101,8 @@ sub _validate {
     }
 
     if ( my $rir = $args->{rir} ){
-       my $re = $self->config->get('VALID_RIR_REGEX');
-       unless ( $rir =~ /$re/ ){
+       my $valid_rirs = $self->config->get('VALID_RIRS');
+       unless ( exists $valid_rirs->{$rir} ){
            $self->throw_user("Invalid RIR: $rir");
        }
     }

commit dca676d54d912c28a7a3e9c332a881053f1f583c
Author: Carlos Vicente <[email protected]>
Date:   Wed Sep 17 14:36:30 2014 -0400

    Added .gitignore

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..ce8369e
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,10 @@
+*~
+
+# Most of these are produced by install
+# We don't want them in the repo
+.prefix
+bin/oui.txt
+etc/Site.conf*
+etc/schema*
+upgrade/error.log
+var/pollstats.rrd

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

Summary of changes:
 .gitignore                    | 10 ++++++++++
 htdocs/management/device.html |  5 +++++
 lib/DBUTIL.pm                 |  6 ++++--
 lib/Netdot/Model/ASN.pm       |  4 ++--
 lib/Netdot/Model/Vlan.pm      |  3 ---
 5 files changed, 21 insertions(+), 7 deletions(-)
 create mode 100644 .gitignore


hooks/post-receive
-- 
Netdot


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

Message: 2
Date: Thu, 18 Sep 2014 11:28:38 -0700
From: [email protected]
Subject: [Netdot-devel] [SCM] Netdot branch netdot-1.0 updated.
        netdot-1.0.6-55-g3f415fa
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  3f415fabc24a2c0a6dd24bc0218952d9dfbeec0a (commit)
       via  dca676d54d912c28a7a3e9c332a881053f1f583c (commit)
      from  abc05ca93c3b226c059fcb2c1db55a0dd33927da (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:
 .gitignore              | 10 ++++++++++
 lib/Netdot/Model/ASN.pm |  4 ++--
 2 files changed, 12 insertions(+), 2 deletions(-)
 create mode 100644 .gitignore


hooks/post-receive
-- 
Netdot


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

Message: 3
Date: Thu, 18 Sep 2014 11:28:38 -0700
From: [email protected]
Subject: [Netdot-devel] [SCM] Netdot branch anton created.
        netdot-1.0.4-82-g2c41e4d
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, anton has been created
        at  2c41e4dee567f35ea389301bc9c057e5251f20ee (commit)

- Log -----------------------------------------------------------------
commit 2c41e4dee567f35ea389301bc9c057e5251f20ee
Merge: 7f61581 433965b
Author: Anton Berezin <[email protected]>
Date:   Mon May 20 21:47:35 2013 +0200

    Merge remote-tracking branch 'upstream/master'


commit 7f61581e28e0edd7532b154a9367ab0f926fb1a5
Merge: 14a2842 dfd8d05
Author: Anton Berezin <[email protected]>
Date:   Sun May 19 20:26:51 2013 +0200

    Merge remote-tracking branch 'upstream/master'


commit 14a284256138ea7fac86c425725e12e0cb0b1495
Author: Anton Berezin <[email protected]>
Date:   Wed May 15 21:42:24 2013 +0200

    Catch all REST exceptions.
    
    This fixes issue 1738.

diff --git a/htdocs/rest/autohandler b/htdocs/rest/autohandler
index fd56292..2c82232 100644
--- a/htdocs/rest/autohandler
+++ b/htdocs/rest/autohandler
@@ -19,6 +19,16 @@ if ( $DEBUG ){
     print "user: ", $user, "<br>";
     print "manager: ", $manager, "<br>";
 }
-$m->call_next(user=>$user, manager=>$manager);
+
+eval {
+    $m->call_next(user=>$user, manager=>$manager);
+};
+
+my $e;
+if ( $e = Netdot::Util::Exception->caught('Netdot::Util::Exception::REST') ){
+    $m->clear_and_abort($e->code);
+}elsif ( $e = $@ ){
+    die $e;
+}
 
 </%init>

commit b02e04a538ba0bb1f7771709924753ac9848bbd0
Author: Anton Berezin <[email protected]>
Date:   Mon May 13 22:15:30 2013 +0200

    Strip \r's when importing a zone.
    
    This fixes issue 1729.

diff --git a/lib/Netdot/Model/Zone.pm b/lib/Netdot/Model/Zone.pm
index 685b8ef..1141038 100644
--- a/lib/Netdot/Model/Zone.pm
+++ b/lib/Netdot/Model/Zone.pm
@@ -650,7 +650,9 @@ sub import_records {
 
     if ( $argv{text } ){
        eval {
-           $rrs = Net::DNS::ZoneFile::Fast::parse(text=>$argv{text}, 
origin=>$domain);
+           my $zone_content = $argv{text};
+           $zone_content =~ s/\r\n/\n/g;
+           $rrs = Net::DNS::ZoneFile::Fast::parse(text=>$zone_content, 
origin=>$domain);
        };
        if ( my $e = $@ ){
            $self->throw_user("Error parsing Zone data: $e")

commit b21c6de5c20dbd29008267d7b9e717a6e72fa813
Author: Anton Berezin <[email protected]>
Date:   Mon May 13 22:00:26 2013 +0200

    Require NetAddr::IP 4.042 or more recent.
    
    This fixes issue 1722.

diff --git a/bin/perldeps.pl b/bin/perldeps.pl
index ab66aae..87f90cd 100755
--- a/bin/perldeps.pl
+++ b/bin/perldeps.pl
@@ -42,7 +42,7 @@ my @DEPS = (
     {cpan=>'SQL::Translator', apt=>'libsql-translator-perl', 
rpm=>'perl-SQL-Translator'},
     {cpan=>'SNMP::Info 2.06', apt=>'libsnmp-info-perl', rpm=>'perl-SNMP-Info'},
     {apt=>'netdisco-mibs-installer'},
-    {cpan=>'NetAddr::IP', apt=>'libnetaddr-ip-perl', rpm=>'perl-NetAddr-IP'},
+    {cpan=>'NetAddr::IP 4.042', apt=>'libnetaddr-ip-perl', 
rpm=>'perl-NetAddr-IP'},
     {cpan=>'Apache2::AuthCookie', apt=>'libapache2-authcookie-perl', rpm=>''},
     {cpan=>'Apache2::SiteControl', apt=>'libapache2-sitecontrol-perl', 
rpm=>''},
     {cpan=>'Log::Dispatch', apt=>'liblog-dispatch-perl', 
rpm=>'perl-Log-Dispatch'},

commit 205ff125687b4e9ed83eb46e774cd4333b68ae67
Merge: e4ee2e4 ca6e8bc
Author: Anton Berezin <[email protected]>
Date:   Mon May 13 21:57:00 2013 +0200

    Merge remote-tracking branch 'upstream/master'


commit e4ee2e416eecd4f0ffc5d0937b0feee5fa6819a3
Merge: 3a9a9bd a31d685
Author: Anton Berezin <[email protected]>
Date:   Thu Jan 24 20:24:21 2013 +0100

    Merge branch 'master' of git://github.com/cvicente/Netdot


commit 3a9a9bde45a1dae5e524629d415b1bfbfc2e5bbe
Author: Anton Berezin <[email protected]>
Date:   Mon Jan 21 23:26:37 2013 +0100

    Implement getnext() for SNMP::Info and SNMPv1.
    
    Also: make all SQE-related modules optional.  They
    are not loaded unless USE_SNMP_QUERY_ENGINE is specified
    in the configuration.
    
    Moreover, when one of the modules used by SQE is missing or cannot be
    loaded, this is handled as if SQE daemon was not available and thus
    a standard ForkManager-based SNMP querying is done.

diff --git a/lib/Netdot/FakeSNMPSession.pm b/lib/Netdot/FakeSNMPSession.pm
index 962e34f..a707e5a 100644
--- a/lib/Netdot/FakeSNMPSession.pm
+++ b/lib/Netdot/FakeSNMPSession.pm
@@ -31,13 +31,14 @@ sub new
     $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;
+       my $class = ref($me) || $me;
     for my $p (qw(sqe DestHost Version)) {
        croak("$class:\:new: argument \"$p\" must be supplied") unless 
$me->{$p};
     }
@@ -52,6 +53,44 @@ 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) = @_;
@@ -64,7 +103,7 @@ sub get
        }
     }
     croak("IMPLEMENT ME: GET var is a reference we cannot (for now) handle: " 
. pp($v))
-       if ref $v;
+       if ref $v;
 
     my $oid = $v;
     $oid = SNMP::translateObj($oid) unless $oid =~ /^[\d.]+$/;
@@ -73,17 +112,19 @@ sub get
     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";
+    $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 =~ /^1\.3\.6(?:\.\d+)+$/;
+    $ret = ".$ret" if $ret && $ret =~ /^1\.3\.6(?:\.\d+)+$/;
 
     return $ret;
 }
@@ -123,7 +164,7 @@ sub bulkwalk
                my $idx = $r->[0];
                $idx =~ s/^\.?\Q$oid\E\.//;
 
-               $v = ".$v" if $v =~ /^1\.3\.6(?:\.\d+)+$/;
+               $v = ".$v" if $v && $v =~ /^1\.3\.6(?:\.\d+)+$/;
                push @r, bless([ $vars->[0], $idx, $v, "OCTETSTR" ], 
"SNMP::Varbind");
        }
        #print "Unreal thing:\n";
diff --git a/lib/Netdot/Model/Device.pm b/lib/Netdot/Model/Device.pm
index 54526ae..0a6f4bd 100644
--- a/lib/Netdot/Model/Device.pm
+++ b/lib/Netdot/Model/Device.pm
@@ -3,16 +3,11 @@ package Netdot::Model::Device;
 use base 'Netdot::Model';
 use warnings;
 use strict;
-use Coro;
-use AnyEvent;
-use Coro::AnyEvent;
 use SNMP::Info;
 use Netdot::Util::DNS;
 use Netdot::Topology;
 use Parallel::ForkManager;
 use Data::Dumper;
-use Netdot::FakeSNMPSession;
-use Net::SNMP::QueryEngine::AnyEvent;
 
 =head1 NAME
 
@@ -851,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) } 
@@ -897,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) } );
@@ -3753,7 +3748,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); 
@@ -4333,11 +4328,28 @@ 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;
@@ -4365,7 +4377,7 @@ sub _snmp_update_parallel {
        $class->_snmp_update_parallel_sqe(%argv, sqe => $sqe);
     } else {
        if ($use_sqe) {
-           $logger->info("SQE is NOT available, using traditional method for 
SNMP collection");
+           $logger->info("SQE daemon is NOT available, using traditional 
method for SNMP collection");
        } else {
            $logger->info("Using traditional method for SNMP collection");
        }
@@ -5911,24 +5923,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;
@@ -5939,17 +5951,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)
@@ -6116,9 +6127,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;
        }

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


hooks/post-receive
-- 
Netdot


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

Message: 4
Date: Thu, 18 Sep 2014 11:28:38 -0700
From: [email protected]
Subject: [Netdot-devel] [SCM] Netdot branch fix-1790 created.
        netdot-1.0.6-39-g47e9b76
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, fix-1790 has been created
        at  47e9b763c4162ecfb4f0bec68b0c7d61beb2ad23 (commit)

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


hooks/post-receive
-- 
Netdot


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

Message: 5
Date: Thu, 18 Sep 2014 11:28:38 -0700
From: [email protected]
Subject: [Netdot-devel] [SCM] Netdot branch subnetvlan created.
        netdot-1.0.6-49-g0e914f8
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, subnetvlan has been created
        at  0e914f8c16a63a1cba587e9e79c815a93bc1cb76 (commit)

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


hooks/post-receive
-- 
Netdot


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

Message: 6
Date: Thu, 18 Sep 2014 11:28:39 -0700
From: [email protected]
Subject: [Netdot-devel] [SCM] Netdot branch update_device_api created.
        netdot-1.0.6-53-g49af8c2
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, update_device_api has been created
        at  49af8c2967ee7b19a5fcf816501013b4dbb6b719 (commit)

- Log -----------------------------------------------------------------
commit 49af8c2967ee7b19a5fcf816501013b4dbb6b719
Author: Carlos Vicente <[email protected]>
Date:   Thu Aug 28 16:20:53 2014 -0400

    Forgot to add new file

diff --git a/htdocs/rest/updatedev b/htdocs/rest/updatedev
new file mode 100644
index 0000000..185d6cc
--- /dev/null
+++ b/htdocs/rest/updatedev
@@ -0,0 +1,54 @@
+<%doc>
+Discover devices via REST
+</%doc>
+<%args>
+$user                    # Should be assigned by autohandler
+$manager                 # Should be assigned by autohandler
+$name                    # Device name
+$info                    # Device information (serialized)
+</%args>
+<%init>
+my $DEBUG = 0;
+print '%ARGS is  <pre>', Dumper(%ARGS), '</pre><br>' if $DEBUG;
+
+use Apache2::Const -compile => qw(FORBIDDEN OK NOT_FOUND HTTP_BAD_REQUEST);
+
+use Data::Dumper;
+
+use Netdot::REST;
+my $rest = Netdot::REST->new(user=>$user, manager=>$manager);
+$rest->request($r);
+
+# Get relevant HTTP headers from request object
+my $headers = $rest->{request}->headers_in;
+
+# Deal with Accept header
+$rest->check_accept_header($headers->{Accept}) if ( $headers->{Accept} );
+
+my $method = $rest->{request}->method;
+my $req_args = $method eq 'POST' ? 
+    sprintf("%s", join(" ", Dumper(%ARGS))) : $rest->{request}->args;
+
+my $logger = Netdot->log->get_logger("Netdot::REST");
+$logger->info(sprintf("/rest/updatedev: %s request with args: %s from %s 
(%s)", 
+                     $method, 
+                     $req_args,
+                     $rest->{request}->connection->remote_ip, 
+                     $headers->{'User-Agent'}
+             ));
+
+my $user_type = $user->getAttribute('USER_TYPE');
+
+</%init>
+<%perl>
+    
+my $dinfo;
+if ( $method eq 'POST' ){
+    $dinfo = $rest->read_serialized($info);
+    my $obj = Device->discover(name=>$name, info=>$dinfo);
+
+    my $o = $rest->get(obj=>$obj);
+    $rest->print_serialized($o);
+}
+
+</%perl>

commit a377c6fac01f748bb6714b03f36654b8f78aafd8
Author: Carlos Vicente <[email protected]>
Date:   Thu Aug 28 16:09:50 2014 -0400

    First draft of new rest/updatedev resource for entering device information 
via REST

diff --git a/htdocs/Makefile b/htdocs/Makefile
index 4768128..2e5b8a6 100644
--- a/htdocs/Makefile
+++ b/htdocs/Makefile
@@ -5,7 +5,7 @@ include $(SRCROOT)/etc/utility-Makefile
 
 NDIR =  cable_plant css generic help img img/graphs java_script management 
contacts operations reports export user_management user_help masondata/obj 
masondata/cache rest
 
-FILES := `find . -name "*" | egrep 
".*(host.*|handler|\.?html|\.css|\.png|\.gif|\.js|\.ico)$$" | sed -e 's/\.\///'`
+FILES := `find . -name "*" | egrep 
".*(rest\/.*|handler|\.?html|\.css|\.png|\.gif|\.js|\.ico)$$" | sed -e 
's/\.\///'`
 
 all: wipedir dir
        $(substitute)
diff --git a/htdocs/rest/host b/htdocs/rest/host
index d156249..a189622 100644
--- a/htdocs/rest/host
+++ b/htdocs/rest/host
@@ -167,7 +167,7 @@ if ( $method eq 'GET' ){
        push @{$ret{Ipblock}}, $o;
     }  
 
-    $rest->print_formatted(\%ret);
+    $rest->print_serialized(\%ret);
 
 }elsif ( $method eq 'POST' ){
     if ( $rrid ){
@@ -204,7 +204,7 @@ if ( $method eq 'GET' ){
            $rest->throw(code=>Apache2::Const::HTTP_BAD_REQUEST, 
                         msg=>'Bad request: $e'); 
        }
-       $rest->print_formatted($rest->get(obj=>$rr, depth=>0));
+       $rest->print_serialized($rest->get(obj=>$rr, depth=>0));
 
     }elsif ( $ipid ){
        # We're updating
@@ -251,7 +251,7 @@ if ( $method eq 'GET' ){
                
            }
        }
-       $rest->print_formatted($rest->get(obj=>$ipb, depth=>0));
+       $rest->print_serialized($rest->get(obj=>$ipb, depth=>0));
 
     }else{
        # No rrid or ipid means We're adding a new host
@@ -355,7 +355,7 @@ if ( $method eq 'GET' ){
            $rest->throw(code=>Apache2::Const::HTTP_BAD_REQUEST, 
                         msg=>"Bad request: $e"); 
        }
-       $rest->print_formatted($rest->get(obj=>$rr, depth=>0));
+       $rest->print_serialized($rest->get(obj=>$rr, depth=>0));
     }
 }elsif ( $method eq 'DELETE' ){
     
diff --git a/htdocs/rest/host_contacts b/htdocs/rest/host_contacts
index 01ddefd..fa3b30d 100644
--- a/htdocs/rest/host_contacts
+++ b/htdocs/rest/host_contacts
@@ -101,6 +101,6 @@ if ( $ip ){
 }
 
 $m->clear_buffer;
-$rest->print_formatted(\%res) if %res;
+$rest->print_serialized(\%res) if %res;
 
 </%perl>
diff --git a/lib/Netdot/Model/Device.pm b/lib/Netdot/Model/Device.pm
index bc26718..4ee87fd 100644
--- a/lib/Netdot/Model/Device.pm
+++ b/lib/Netdot/Model/Device.pm
@@ -1516,27 +1516,35 @@ sub discover {
        my $main_ip = $argv{main_ip} || $class->_get_main_ip($info);
        my $host    = $main_ip || $name;
        my $newname = $class->assign_name(host=>$host, 
sysname=>$info->{sysname});
-
-       my %devtmp = (snmp_managed  => 1,
-                     snmp_polling  => 1,
-                     canautoupdate => 1,
-                     # These following two could have changed in 
get_snmp_session
-                     # so we grab them from %info instead of directly from 
%argv
-                     community     => $info->{community},
-                     snmp_version  => $info->{snmp_version},
-                     );
-
-       if ( defined $devtmp{snmp_version} && $devtmp{snmp_version} == 3 ){
-           my %arg2field = (sec_name   => 'snmp_securityname',
-                            sec_level  => 'snmp_securitylevel',
-                            auth_proto => 'snmp_authprotocol',
-                            auth_pass  => 'snmp_authkey',
-                            priv_proto => 'snmp_privprotocol',
-                            priv_pass  => 'snmp_privkey',
+       
+       
+       my %devtmp; # Store new Device values here
+
+       if ( $info->{snmp_version} ) {
+           # Means we probably discovered this using SNMP
+
+           # Set some default stuff
+           %devtmp = (snmp_managed  => 1,
+                      snmp_polling  => 1,
+                      canautoupdate => 1,
+                      # These following two could have changed in 
get_snmp_session
+                      # so we grab them from %info instead of directly from 
%argv
+                      community     => $info->{community},
+                      snmp_version  => $info->{snmp_version},
                );
-
-           foreach my $arg ( keys %arg2field ){
-               $devtmp{$arg2field{$arg}} = $argv{$arg} if defined $argv{$arg};
+           
+           if ( defined $devtmp{snmp_version} && $devtmp{snmp_version} == 3 ){
+               my %arg2field = (sec_name   => 'snmp_securityname',
+                                sec_level  => 'snmp_securitylevel',
+                                auth_proto => 'snmp_authprotocol',
+                                auth_pass  => 'snmp_authkey',
+                                priv_proto => 'snmp_privprotocol',
+                                priv_pass  => 'snmp_privkey',
+                   );
+               
+               foreach my $arg ( keys %arg2field ){
+                   $devtmp{$arg2field{$arg}} = $argv{$arg} if defined 
$argv{$arg};
+               }
            }
        }
 
@@ -1613,7 +1621,7 @@ sub discover {
 
     # Update Device with SNMP info obtained
     $dev->snmp_update(%uargs);
-    
+  
     return $dev;
 }
 
@@ -2958,7 +2966,7 @@ sub info_update {
        return; 
     }
     unless ( ref($info) eq 'HASH' ){
-       $self->throw_fatal("Model::Device::info_update: Invalid SNMP data 
structure");
+       $self->throw_fatal("Model::Device::info_update: Invalid info data 
structure");
     }
 
     # Pretend works by turning off autocommit in the DB handle and rolling back
diff --git a/lib/Netdot/REST.pm b/lib/Netdot/REST.pm
index 655e12b..938de95 100644
--- a/lib/Netdot/REST.pm
+++ b/lib/Netdot/REST.pm
@@ -4,7 +4,7 @@ use base qw( Netdot );
 use Netdot::Model;
 use XML::Simple;
 use Data::Dumper;
-use Apache2::Const -compile => qw(FORBIDDEN HTTP_UNAUTHORIZED OK NOT_FOUND 
+use Apache2::Const -compile => qw(HTTP_FORBIDDEN HTTP_UNAUTHORIZED OK 
NOT_FOUND 
                                   HTTP_BAD_REQUEST HTTP_NOT_ACCEPTABLE);
 use strict;
 
@@ -155,11 +155,11 @@ sub handle_resource {
                    }
                    $get_args{linked_from} = $argv{linked_from};
                    my $o = $self->get(%get_args);
-                   $self->print_formatted($o);
+                   $self->print_serialized($o);
 
                }elsif ( $self->{request}->method eq 'POST' ){
                    my $o = $self->post(table=>$table, id=>$id, %argv);
-                   $self->print_formatted($o);
+                   $self->print_serialized($o);
 
                }elsif ( $self->{request}->method eq 'DELETE' ){
                    $self->delete(table=>$table, id=>$id);
@@ -170,7 +170,7 @@ sub handle_resource {
                    my $m = $table->meta_data();
                    my %meta = %$m;
                    delete $meta{meta};
-                   $self->print_formatted(\%meta);
+                   $self->print_serialized(\%meta);
                }
            }else{
                # Invalid ID
@@ -203,7 +203,7 @@ sub handle_resource {
                        $get_args{linked_from} = $linked_from if defined( 
$linked_from );
                        push @objs, $self->get(%get_args);
                    }
-                   $self->print_formatted({$table=>\@objs});
+                   $self->print_serialized({$table=>\@objs});
                }else{
                    $self->throw(code=>Apache2::Const::NOT_FOUND, msg=>"Not 
found"); 
                }
@@ -211,7 +211,7 @@ sub handle_resource {
            }elsif ( $self->{request}->method eq 'POST' ){
                # A lack of id means we're inserting a new object
                my $o = $self->post(table=>$table, %argv);
-               $self->print_formatted($o);
+               $self->print_serialized($o);
            }
        }
     }else{
@@ -471,17 +471,19 @@ sub media_type {
 
 ##################################################################
 
-=head2 print_formatted - Print formatted data to stdout
+=head2 print_serialized - Print serialized data to stdout
+
+  Format is determined by the media type set in the request
 
   Arguments: 
     hashref with data to format
   Returns:
-    formatted data
+    serialized data (XML, etc)
   Examples:
-    $rest->print_formatted(\%hash);
+    $rest->print_serialized(\%hash);
 =cut
 
-sub print_formatted {
+sub print_serialized {
     my ($self, $data) = @_;
     
     $self->throw_fatal("Missing required arguments") 
@@ -490,14 +492,7 @@ sub print_formatted {
     my $mtype = $self->{media_type} || 'xml';
     
     if ( $mtype eq 'xml' ){
-       unless ( $self->{xs} ){
-           # Instantiate the XML::Simple class
-           $self->{xs} = XML::Simple->new(
-               ForceArray => 1,
-               XMLDecl    => 1, 
-               KeyAttr    => 'id',
-               );
-       }
+       $self->_load_xml_lib();
        my $xml = $self->{xs}->XMLout($data);
        $self->{request}->content_type(q{text/xml; charset=utf-8});
 
@@ -507,6 +502,34 @@ sub print_formatted {
 
 ##################################################################
 
+=head2 read_serialized - Read serialized data
+
+  Format is determined by the media type set in the request
+
+  Arguments: 
+    String with serialized data (XML, etc)
+  Returns:
+    Hashref
+  Examples:
+    my $data = $rest->read_serialized($string);
+=cut
+
+sub read_serialized {
+    my ($self, $string) = @_;
+    
+    $self->throw_fatal("Missing required arguments") 
+       unless ( $string );
+    
+    my $mtype = $self->{media_type} || 'xml';
+    
+    if ( $mtype eq 'xml' ){
+       $self->_load_xml_lib();
+       $self->{xs}->XMLin($string);
+    }
+}
+
+##################################################################
+
 =head2 check_accept_header - Sets and validates media_type and version
 
   Arguments: 
@@ -568,6 +591,7 @@ sub throw {
 #
 ##################################################################
 
+##################################################################
 # _get_linked_from - Get list of objects that point to us
 #    
 #     Arguments:
@@ -602,13 +626,37 @@ sub _get_linked_from{
 }
 
 
+##################################################################
+# _load_xml_lib - Load XML library
+#    
+#  Instantiates XML::Simple class if needed
+#
+#     Arguments:
+#        none
+#     Returns:
+#        Nothing
+#     Examples:
+#        $self->_load_xml_lib();
+#
+sub _load_xml_lib{
+    my ($self) = @_;
+    
+    unless ( $self->{xs} ){
+       $self->{xs} = XML::Simple->new(
+           ForceArray => 1,
+           XMLDecl    => 1, 
+           KeyAttr    => 'id',
+           );
+    }
+}
+
 =head1 AUTHORS
 
 Carlos Vicente & Clayton Parker Coleman
 
 =head1 COPYRIGHT & LICENSE
 
-Copyright 2012 University of Oregon, all rights reserved.
+Copyright 2014 University of Oregon, all rights reserved.
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by

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


hooks/post-receive
-- 
Netdot


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

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


End of Netdot-devel Digest, Vol 90, Issue 3
*******************************************

Reply via email to