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 netdot-1.0 updated.
      netdot-1.0.4-119-g491fdc7 ([email protected])
   2. [SCM] Netdot branch netdot-1.0 updated.
      netdot-1.0.4-120-g22a472c ([email protected])
   3. [SCM] Netdot branch master updated.       netdot-1.0.4-120-g22a472c
      ([email protected])
   4. [SCM] Netdot branch netdot-1.0 updated.
      netdot-1.0.4-121-gcd9c0a7 ([email protected])
   5. [SCM] Netdot branch master updated.       netdot-1.0.4-121-gcd9c0a7
      ([email protected])


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

Message: 1
Date: Fri, 8 Nov 2013 09:46:50 -0800
From: [email protected]
Subject: [Netdot-devel] [SCM] Netdot branch netdot-1.0 updated.
        netdot-1.0.4-119-g491fdc7
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  491fdc743668c97d2aa83719263a384240fe18d7 (commit)
       via  36386ae12019b1319786eeb3709bdb8cd2cc0f99 (commit)
      from  166d9b6886c091f007a35bee09b314444b5f11c1 (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 491fdc743668c97d2aa83719263a384240fe18d7
Author: Carlos Vicente <[email protected]>
Date:   Wed Nov 6 10:24:31 2013 -0500

    Improve how a device is added manually. Now tries to determine name and IP, 
add IP to a single interface, set neighbor relationship if possible

diff --git a/htdocs/management/device.html b/htdocs/management/device.html
index c46da87..5c6150d 100644
--- a/htdocs/management/device.html
+++ b/htdocs/management/device.html
@@ -140,9 +140,9 @@ if( $deviceadd && $newhost ){
        print "<p><b>Device $newhost already exists in DB</b>";   
        $m->abort;
     }else{
-       # Minimal info to create device manually
+       # Add device manually
        eval {
-           $o = Device->insert({name=>$newhost, snmp_managed=>0, 
canautoupdate=>0});
+           $o = Device->manual_add(host=>$newhost);
        };
        if ( my $e = $@ ){
            $m->comp('/generic/error.mhtml', error=>$e);        
diff --git a/htdocs/management/device_tasks.html 
b/htdocs/management/device_tasks.html
index 03bc76b..586ba1d 100644
--- a/htdocs/management/device_tasks.html
+++ b/htdocs/management/device_tasks.html
@@ -273,7 +273,7 @@ my $manager = $ui->get_permission_manager($r);
             <legend>Add Device manually</legend>
             <form action="device.html" method="POST">
                 <p>
-                <label for="newhost">Name:&nbsp;&nbsp;&nbsp;&nbsp;</label>
+                <label for="newhost">Name or 
IP:&nbsp;&nbsp;&nbsp;&nbsp;</label>
                 <input type="text" name="newhost" class="longtxt" value="">
                 <input type="hidden" name="deviceadd" value="add">
                 <input type="submit" name="submit" class="btn" value="add">
diff --git a/lib/Netdot/Model/Device.pm b/lib/Netdot/Model/Device.pm
index 790a3ca..ab31edb 100644
--- a/lib/Netdot/Model/Device.pm
+++ b/lib/Netdot/Model/Device.pm
@@ -636,6 +636,51 @@ sub insert {
 
 ############################################################################
 
+=head2 manual_add - Add a device manually
+
+    Sets enough information so it can be monitored:
+    - Creates an interface
+    - Assigns IP to that interface
+    - Sets neighbor relationship if possible
+    
+  Arguments:
+    host - Name or IP address. Either one will be resolved
+  Returns:
+    New Device object
+  Examples:
+    my $newdevice = Device->manual_add(host=>"myhost");
+
+=cut
+
+sub manual_add {
+    my ($class, %argv) = @_;
+    $class->isa_class_method('manual_add');
+
+    # host is required
+    if ( !exists($argv{host}) ){
+       $class->throw_fatal('Model::Device::manual_add: Missing required 
argument: host');
+    }
+    # We will try to get both the IP and the name
+    my ($ip, $name) = Netdot->dns->resolve_any($argv{host});
+    $name ||= $ip;
+    my $dev = Device->insert({name=>$name, monitored=>1, snmp_managed=>0, 
+                             canautoupdate=>0, auto_dns=>0});
+    my $ints = $dev->add_interfaces(1);
+    my $int = $ints->[0];
+    if ( $ip ){
+       my $ipb = Ipblock->find_or_create({address=>$ip});
+       $ipb->update({status=>"Static", interface=>$int, monitored=>1});
+       $dev->update({snmp_target=>$ipb});
+       # Try to set the interface neighbor
+       my $mac = $ipb->get_last_arp_mac();
+       my $neighbor = $mac->find_edge_port if $mac;
+       $int->add_neighbor(id=>$neighbor, fixed=>1) if $neighbor;
+    }
+    return $dev;
+}
+
+############################################################################
+
 =head2 get_snmp_info - SNMP-query a Device for general information
     
     This method can either be called on an existing object, or as a 
diff --git a/lib/Netdot/Model/Ipblock.pm b/lib/Netdot/Model/Ipblock.pm
index 7d741db..b5d0397 100644
--- a/lib/Netdot/Model/Ipblock.pm
+++ b/lib/Netdot/Model/Ipblock.pm
@@ -2386,6 +2386,31 @@ sub get_last_n_arp {
 
 ################################################################
 
+=head2 get_last_arp_mac - Get latest MAC using this IP from ARP
+
+  Arguments: 
+    None
+  Returns:   
+    PhysAddr object if successful
+  Examples:
+    my $mac = $ipb->get_last_arp_mac();
+
+=cut
+
+sub get_last_arp_mac {
+    my ($self) = @_;
+    $self->isa_object_method('get_last_arp_mac');
+    
+    if ( my $arp = $self->get_last_n_arp(1) ){
+        my $row = shift @$arp;
+       my ($iid, $macid, $tstamp) = @$row;
+       my $mac = PhysAddr->retrieve($macid);
+       return $mac if defined $mac;
+    }
+}
+
+################################################################
+
 =head2 shared_network_subnets
 
     Determine if this subnet shares a physical link with another
diff --git a/lib/Netdot/Util/DNS.pm b/lib/Netdot/Util/DNS.pm
index c29f838..c940e0f 100644
--- a/lib/Netdot/Util/DNS.pm
+++ b/lib/Netdot/Util/DNS.pm
@@ -150,7 +150,7 @@ sub resolve_any {
     if ( $host =~ /^($IPV4)|($IPV6)$/ ){
        # looks like an IP address
        $ip   = $host;
-       $name = $self->resolve_ip($ip) || "?";
+       $name = $self->resolve_ip($ip) || "";
     }else{
        # looks like a name
        $name = $host;

commit 36386ae12019b1319786eeb3709bdb8cd2cc0f99
Author: Carlos Vicente <[email protected]>
Date:   Wed Nov 6 07:44:21 2013 -0500

    Removed unnecessary variable

diff --git a/lib/Netdot/Model/Device.pm b/lib/Netdot/Model/Device.pm
index 8091bf7..790a3ca 100644
--- a/lib/Netdot/Model/Device.pm
+++ b/lib/Netdot/Model/Device.pm
@@ -5700,7 +5700,6 @@ sub _assign_monitor_config_group{
     if ( $self->config->get('DEV_MONITOR_CONFIG') && 
         (!$self->monitor_config_group || $self->monitor_config_group eq "") ){
        my $monitor_config_map = 
$self->config->get('DEV_MONITOR_CONFIG_GROUP_MAP') || {};
-       my $config_group;
        if ( my $type = $info->{type} ){
            if ( exists $monitor_config_map->{$type} ){
                return $monitor_config_map->{$type};

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

Summary of changes:
 htdocs/management/device.html       |    4 +-
 htdocs/management/device_tasks.html |    2 +-
 lib/Netdot/Model/Device.pm          |   46 ++++++++++++++++++++++++++++++++++-
 lib/Netdot/Model/Ipblock.pm         |   25 +++++++++++++++++++
 lib/Netdot/Util/DNS.pm              |    2 +-
 5 files changed, 74 insertions(+), 5 deletions(-)


hooks/post-receive
-- 
Netdot


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

Message: 2
Date: Fri, 8 Nov 2013 10:00:25 -0800
From: [email protected]
Subject: [Netdot-devel] [SCM] Netdot branch netdot-1.0 updated.
        netdot-1.0.4-120-g22a472c
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  22a472ca9303eb3d84442fb203503fe424354f6e (commit)
      from  491fdc743668c97d2aa83719263a384240fe18d7 (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 22a472ca9303eb3d84442fb203503fe424354f6e
Author: Carlos Vicente <[email protected]>
Date:   Wed Nov 6 10:38:10 2013 -0500

    Small correction

diff --git a/lib/Netdot/Model/Device.pm b/lib/Netdot/Model/Device.pm
index ab31edb..2dad7dc 100644
--- a/lib/Netdot/Model/Device.pm
+++ b/lib/Netdot/Model/Device.pm
@@ -668,7 +668,7 @@ sub manual_add {
     my $ints = $dev->add_interfaces(1);
     my $int = $ints->[0];
     if ( $ip ){
-       my $ipb = Ipblock->find_or_create({address=>$ip});
+       my $ipb = Ipblock->search(address=>$ip)->first || 
Ipblock->insert({address=>$ip});
        $ipb->update({status=>"Static", interface=>$int, monitored=>1});
        $dev->update({snmp_target=>$ipb});
        # Try to set the interface neighbor

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

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


hooks/post-receive
-- 
Netdot


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

Message: 3
Date: Fri, 8 Nov 2013 10:00:55 -0800
From: [email protected]
Subject: [Netdot-devel] [SCM] Netdot branch master updated.
        netdot-1.0.4-120-g22a472c
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  22a472ca9303eb3d84442fb203503fe424354f6e (commit)
       via  491fdc743668c97d2aa83719263a384240fe18d7 (commit)
       via  36386ae12019b1319786eeb3709bdb8cd2cc0f99 (commit)
      from  166d9b6886c091f007a35bee09b314444b5f11c1 (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:
 htdocs/management/device.html       |    4 +-
 htdocs/management/device_tasks.html |    2 +-
 lib/Netdot/Model/Device.pm          |   46 ++++++++++++++++++++++++++++++++++-
 lib/Netdot/Model/Ipblock.pm         |   25 +++++++++++++++++++
 lib/Netdot/Util/DNS.pm              |    2 +-
 5 files changed, 74 insertions(+), 5 deletions(-)


hooks/post-receive
-- 
Netdot


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

Message: 4
Date: Fri, 8 Nov 2013 11:38:35 -0800
From: [email protected]
Subject: [Netdot-devel] [SCM] Netdot branch netdot-1.0 updated.
        netdot-1.0.4-121-gcd9c0a7
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  cd9c0a7d9d73c30c790ab3c3ff03e95ba3b15afd (commit)
      from  22a472ca9303eb3d84442fb203503fe424354f6e (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 cd9c0a7d9d73c30c790ab3c3ff03e95ba3b15afd
Author: Carlos Vicente <[email protected]>
Date:   Wed Nov 6 12:03:50 2013 -0500

    Fix OUI table population with PostgreSQL

diff --git a/lib/DBUTIL.pm b/lib/DBUTIL.pm
index 898f14f..3fab6ff 100644
--- a/lib/DBUTIL.pm
+++ b/lib/DBUTIL.pm
@@ -524,11 +524,11 @@ sub insert_oui{
     }
     close(OUI);
 
-    if (lc($CONFIG{DB_TYPE}) eq 'mysql') {
+    if ($CONFIG{DB_TYPE} eq 'mysql') {
        push @data, "LOAD DATA LOCAL INFILE '$oui_file' INTO TABLE oui (oui, 
vendor);"
-    } elsif (lc($CONFIG{DB_TYPE}) eq 'Pg') {
+    } elsif ($CONFIG{DB_TYPE} eq 'Pg') {
         push @data, "COPY oui(oui, vendor) FROM '$oui_file';"
-    }   
+}   
     &db_query(\@data);
     unlink($oui_file);
     my $oui_count = scalar keys %oui;

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

Summary of changes:
 lib/DBUTIL.pm |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)


hooks/post-receive
-- 
Netdot


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

Message: 5
Date: Fri, 8 Nov 2013 11:39:05 -0800
From: [email protected]
Subject: [Netdot-devel] [SCM] Netdot branch master updated.
        netdot-1.0.4-121-gcd9c0a7
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  cd9c0a7d9d73c30c790ab3c3ff03e95ba3b15afd (commit)
      from  22a472ca9303eb3d84442fb203503fe424354f6e (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/DBUTIL.pm |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)


hooks/post-receive
-- 
Netdot


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

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


End of Netdot-devel Digest, Vol 80, Issue 6
*******************************************

Reply via email to