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.7-3-ge8570ef ([email protected])


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

Message: 1
Date: Mon, 22 Dec 2014 06:55:01 -0800
From: [email protected]
Subject: [Netdot-devel] [SCM] Netdot branch netdot-1.0 updated.
        netdot-1.0.7-3-ge8570ef
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  e8570ef3d075f8942e420f753652909f585bf655 (commit)
       via  036a846d5f8d9e24b246c391eb86d31470df2c7a (commit)
      from  1c4900cdc42075238d22facbd740681a1dd2c36f (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 e8570ef3d075f8942e420f753652909f585bf655
Author: Carlos Vicente <[email protected]>
Date:   Mon Dec 22 09:54:43 2014 -0500

    New REST resource to retrieve all device-related information

diff --git a/bin/exporter.pl b/bin/exporter.pl
index 523f39d..da617e1 100755
--- a/bin/exporter.pl
+++ b/bin/exporter.pl
@@ -70,24 +70,25 @@ if ( $self{debug} ){
 
 foreach my $type ( split ',', $self{types} ){
     $type =~ s/\s+//g;
-    my $exporter = Netdot::Exporter->new(type=>$type);
+    my %args;
     if ( $type eq 'BIND' ){
-       my %args = (nopriv => $self{nopriv},
-                   force  => $self{force},
+       %args = (nopriv => $self{nopriv},
+                force  => $self{force},
            );
        if ( $self{zones} ){
            my @zones = split ',', $self{zones};
            $args{zones} = \@zones;
        }
-       $exporter->generate_configs(%args);
-
     }elsif ( $type eq 'DHCPD' ){
-       my %args;
        $args{scopes} = [split ',', $self{scopes}] if $self{scopes};
        $args{force} = $self{force} if $self{force};
+    }
+    eval {
+       my $exporter = Netdot::Exporter->new(type=>$type);
        $exporter->generate_configs(%args);
-    }else{
-       $exporter->generate_configs();
+    };
+    if ( my $e = $@ ){
+       die "Problem exporting configs: $e\n"; 
     }
 }
 
diff --git a/htdocs/rest/devinfo b/htdocs/rest/devinfo
new file mode 100644
index 0000000..c2aca97
--- /dev/null
+++ b/htdocs/rest/devinfo
@@ -0,0 +1,47 @@
+<%doc>
+REST resource to fetch device information
+</%doc>
+<%args>
+$user                    # Should be assigned by autohandler
+$manager                 # Should be assigned by autohandler
+</%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;
+use Netdot::Exporter;
+
+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/devinfo: %s request with args: %s from %s (%s)", 
+                     $method, 
+                     $req_args,
+                     $rest->{request}->connection->remote_ip, 
+                     $headers->{'User-Agent'}
+             ));
+
+</%init>
+<%perl>
+    
+my %ret;
+if ( $method eq 'GET' ){
+    my $info = Netdot::Exporter->get_device_info();
+    $ret{device} = $info;
+    $rest->print_serialized(\%ret);
+}
+</%perl>
diff --git a/lib/Netdot/Exporter.pm b/lib/Netdot/Exporter.pm
index 4233715..de71231 100644
--- a/lib/Netdot/Exporter.pm
+++ b/lib/Netdot/Exporter.pm
@@ -59,7 +59,6 @@ sub new{
        bless $self, $class;
     }
     
-    $self->{_dbh} = Netdot::Model->db_Main();
     return $self;
 }
 
@@ -67,12 +66,14 @@ sub new{
 
 =head2 get_device_info
 
+All device information needed for building monitoring configurations
+
   Arguments:
     None
   Returns:
     Hash reference where key=device.id
   Examples:
-    my $ips = Netdot::Model::Exporter->get_device_info();
+    my $info = Netdot::Exporter->get_device_info();
 =cut
 
 sub get_device_info {
@@ -82,10 +83,12 @@ sub get_device_info {
 
     my %device_info;
     $logger->debug("Netdot::Exporter::get_device_info: querying database");
-    my $rows = $self->{_dbh}->selectall_arrayref("
 
+    my $dbh = Netdot::Model->db_Main();
+    my $rows = $dbh->selectall_arrayref("
           SELECT    d.id, d.snmp_managed, d.community, d.snmp_target, 
d.host_device,
                     d.monitoring_template, d.down_from, d.down_until, 
entity.name, entity.aliases,
+                    p.name, ptype.name, manuf.name,
                     site.name, site.number, site.aliases, contactlist.id,
                     i.id, i.number, i.name, i.description, i.admin_status, 
i.monitored, i.contactlist,
                     ip.id, ip.address, ip.version, ip.parent, ip.monitored, 
rr.name, zone.name,
@@ -95,11 +98,15 @@ sub get_device_info {
           LEFT OUTER JOIN (bgppeering, entity peer) ON d.id=bgppeering.device 
                            AND bgppeering.entity=peer.id
                            AND bgppeering.monitored=1
+          LEFT OUTER JOIN (asset, product p, producttype ptype, entity manuf) 
ON asset.id=d.asset_id
+                           AND asset.product_id=p.id
+                           AND p.type=ptype.id
+                           AND manuf.id=p.manufacturer
           LEFT OUTER JOIN devicecontacts ON d.id=devicecontacts.device
           LEFT OUTER JOIN contactlist ON 
contactlist.id=devicecontacts.contactlist
           LEFT OUTER JOIN entity ON d.used_by=entity.id
           LEFT OUTER JOIN site ON d.site=site.id,
-                    interface i 
+                     interface i 
           LEFT OUTER JOIN ipblock ip ON ip.interface=i.id
           LEFT OUTER JOIN ipservice ON ipservice.ip=ip.id
           LEFT OUTER JOIN service ON ipservice.service=service.id
@@ -114,6 +121,7 @@ sub get_device_info {
 
        my ($devid, $dev_snmp, $community, $target_id, $host_device,
            $mon_template, $down_from, $down_until, $entity_name, 
$entity_alias, 
+           $pname, $ptype, $manuf,
            $site_name, $site_number, $site_alias, $clid,
            $intid, $intnumber, $intname, $intdesc, $intadmin, $intmon, $intcl,
            $ip_id, $ip_addr, $ip_version, $subnet, $ip_mon, $name, $zone,
@@ -122,6 +130,9 @@ sub get_device_info {
        my $hostname = ($name eq '@')? $zone : $name.'.'.$zone;
        $device_info{$devid}{target_id}    = $target_id;
        $device_info{$devid}{hostname}     = $hostname;
+       $device_info{$devid}{pname}        = $pname if defined $pname;
+       $device_info{$devid}{ptype}        = $ptype if defined $ptype;
+       $device_info{$devid}{manuf}        = $manuf if defined $manuf;
        $device_info{$devid}{host_device}  = $host_device;
        $device_info{$devid}{community}    = $community;
        $device_info{$devid}{snmp_managed} = $dev_snmp;
@@ -133,7 +144,7 @@ sub get_device_info {
        $device_info{$devid}{site_name}    = $site_name    if defined 
$site_name;
        $device_info{$devid}{site_number}  = $site_number  if defined 
$site_number;
        $device_info{$devid}{site_alias}   = $site_alias   if defined 
$site_alias;
-       $device_info{$devid}{contactlist}{$clid} = 1 if defined $clid;
+       $device_info{$devid}{contactlist}{$clid}{clid} = $clid if defined $clid;
        if ( $peer_addr ){
            $device_info{$devid}{peering}{$peer_addr}{contactlist} = $peer_cl;
            $device_info{$devid}{peering}{$peer_addr}{asn}         = $peer_asn  
  if $peer_asn;
diff --git a/lib/Netdot/Exporter/Nagios.pm b/lib/Netdot/Exporter/Nagios.pm
index b7740ce..3facfc7 100644
--- a/lib/Netdot/Exporter/Nagios.pm
+++ b/lib/Netdot/Exporter/Nagios.pm
@@ -7,6 +7,8 @@ use Data::Dumper;
 
 my $logger = Netdot->log->get_logger('Netdot::Exporter');
 
+my $dbh = Netdot::Model->db_Main();
+
 =head1 NAME
 
 Netdot::Exporter::Nagios
@@ -88,7 +90,7 @@ sub generate_configs {
 
     # Get Subnet info
     my %subnet_info;
-    my $subnetq = $self->{_dbh}->selectall_arrayref("
+    my $subnetq = $dbh->selectall_arrayref("
                   SELECT    ipblock.id, ipblock.description, entity.name, 
entity.aliases
                   FROM      ipblockstatus, ipblock
                   LEFT JOIN entity ON (ipblock.used_by=entity.id)
@@ -104,7 +106,7 @@ sub generate_configs {
 
     # Get Contact Info
     my %contact_info;
-    my $clq = $self->{_dbh}->selectall_arrayref("
+    my $clq = $dbh->selectall_arrayref("
                   SELECT    contactlist.id, contactlist.name,
                             contact.id, contact.escalation_level, 
                             person.firstname, person.lastname, person.email, 
person.emailpager,
@@ -855,7 +857,7 @@ sub get_interface_graph {
 
     $logger->debug("Netdot::Exporter::get_interface_graph: querying database");
     my $graph = {};
-    my $links = $self->{_dbh}->selectall_arrayref("
+    my $links = $dbh->selectall_arrayref("
                 SELECT  i1.id, i2.id 
                 FROM    interface i1, interface i2
                 WHERE   i1.id > i2.id AND i2.neighbor = i1.id AND i1.neighbor 
= i2.id
diff --git a/lib/Netdot/Exporter/Rancid.pm b/lib/Netdot/Exporter/Rancid.pm
index a94f13d..21c17c8 100644
--- a/lib/Netdot/Exporter/Rancid.pm
+++ b/lib/Netdot/Exporter/Rancid.pm
@@ -74,7 +74,9 @@ sub new{
 sub generate_configs {
     my ($self) = @_;
 
-    my $query = $self->{_dbh}->selectall_arrayref("
+    my $dbh = Netdot::Model->db_Main();
+
+    my $query = $dbh->selectall_arrayref("
           SELECT rr.name, zone.name, p.name, p.sysobjectid, p.config_type, 
e.name, e.config_type,
                  d.sysdescription, d.monitor_config, d.monitor_config_group, 
d.down_from, d.down_until
           FROM   device d, rr, zone, product p, entity e, asset a
diff --git a/lib/Netdot/Exporter/Smokeping.pm b/lib/Netdot/Exporter/Smokeping.pm
index cb992d5..a44a058 100644
--- a/lib/Netdot/Exporter/Smokeping.pm
+++ b/lib/Netdot/Exporter/Smokeping.pm
@@ -59,7 +59,9 @@ sub new{
 sub generate_configs {
     my ($self) = @_;
 
-    my $query = $self->{_dbh}->selectall_arrayref("
+    my $dbh = Netdot::Model->db_Main();
+
+    my $query = $dbh->selectall_arrayref("
                 SELECT     d.id, rr.name, zone.name, p.name, e.name,
                            d.monitored, t.name, d.down_from, d.down_until
                  FROM      device d, rr, zone, product p, entity e, asset a,

commit 036a846d5f8d9e24b246c391eb86d31470df2c7a
Author: Carlos Vicente <[email protected]>
Date:   Thu Dec 18 16:30:40 2014 -0500

    Fix for #1845 (upadte for staging support)

diff --git a/htdocs/Makefile b/htdocs/Makefile
index 50b4de8..25282ec 100644
--- a/htdocs/Makefile
+++ b/htdocs/Makefile
@@ -9,7 +9,7 @@ FILES := `find . -name "*" | egrep 
".*(rest\/.*|handler|\.?html|\.css|\.png|\.gi
 
 all: wipedir dir
        $(substitute)
-       ln -s $(STAGEDIR)/doc/manual/netdot-manual.htm  
$(STAGEDIR)/$(DIR)/help/manual.html
+       ln -s $(PREFIX)/doc/manual/netdot-manual.htm  
$(STAGEDIR)/$(DIR)/help/manual.html
 
 # Wipe out dir before installing
 wipedir:

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

Summary of changes:
 bin/exporter.pl                    | 17 +++++++++--------
 htdocs/Makefile                    |  2 +-
 htdocs/rest/{updatedev => devinfo} | 34 +++++++++-------------------------
 lib/Netdot/Exporter.pm             | 21 ++++++++++++++++-----
 lib/Netdot/Exporter/Nagios.pm      |  8 +++++---
 lib/Netdot/Exporter/Rancid.pm      |  4 +++-
 lib/Netdot/Exporter/Smokeping.pm   |  4 +++-
 7 files changed, 46 insertions(+), 44 deletions(-)
 copy htdocs/rest/{updatedev => devinfo} (61%)


hooks/post-receive
-- 
Netdot


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

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


End of Netdot-devel Digest, Vol 93, Issue 9
*******************************************

Reply via email to