Permalink
Browse files

Documentation and sample code for new REST resources

  • Loading branch information...
Carlos Vicente
Carlos Vicente committed Jan 2, 2015
1 parent e8570ef commit f8b806f78957e98f43b7a4e1633ed3b459544d67
Binary file not shown.
@@ -131,6 +131,8 @@ <h2 class="author">Manual del Usuario</h2>
<li><a href="#actualizar-récords-existentes-http-post."><span class="toc-section-number">7.2.1.3</span> Actualizar récords existentes (HTTP POST).</a></li>
<li><a href="#borrar-records-http-delete"><span class="toc-section-number">7.2.1.4</span> Borrar records (HTTP DELETE)</a></li>
</ul></li>
<li><a href="#restdevinfo"><span class="toc-section-number">7.2.2</span> /rest/devinfo</a></li>
<li><a href="#restupdatedev"><span class="toc-section-number">7.2.3</span> /rest/updatedev</a></li>
</ul></li>
<li><a href="#autorización-en-la-interfaz-rest"><span class="toc-section-number">7.3</span> Autorización en la interfaz REST</a></li>
<li><a href="#módulo-perl-para-programas-cliente-en-cpan"><span class="toc-section-number">7.4</span> Módulo Perl para programas cliente en CPAN</a></li>
@@ -141,7 +143,7 @@ <h2 class="author">Manual del Usuario</h2>
<p></p>
<h1 id="copyright"><a href="#TOC"><span class="header-section-number">1</span> Copyright</a></h1>
<p>Version 1.0</p>
<p>Copyright 2012 University of Oregon, Todos los derechos reservados.</p>
<p>Copyright 2014 Carlos Vicente</p>
<p>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 the Free Software Foundation; either version 2 of the License, or (at your option) any later version.</p>
<p>This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.</p>
<p>You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.</p>
@@ -689,6 +691,12 @@ <h4 id="borrar-records-http-delete"><a href="#TOC"><span class="header-section-n
<li>Borrar el nombre de host con RR Id 3 (también libera la IP)</li>
</ul>
<pre><code>http://netdot.localdomain/netdot/rest/host?rrid=3</code></pre>
<h3 id="restdevinfo"><a href="#TOC"><span class="header-section-number">7.2.2</span> /rest/devinfo</a></h3>
<p>Puede utilizarse este recurso REST para obtener información extensa acerca de todos los dispositivos de la red existentes en la base de datos. La estructura de datos resultante es la misma que utiliza la clase de exportación para NAGIOS, por lo que puede ser útil en la generación de configuraciones para otros programas de monitorización.</p>
<h3 id="restupdatedev"><a href="#TOC"><span class="header-section-number">7.2.3</span> /rest/updatedev</a></h3>
<p>This special REST resource can be used to import devices into Netdot, as an alternative to using SNMP discovery. It accepts only POST requests. An example using the Perl client library can be found in the Netdot source, at:</p>
<p>Este recurso REST puede ser usado para importar información de dispositivos de forma alternativa al descubrimiento via SNMP. Acepta solamente peticiones tipo POST. Se incluye un ejemplo de su utilización con la biblioteca cliente para Perl ul siguiente archivo dentro de la fuente de Netdot:</p>
<pre><code>import/update_dev_rest.pl</code></pre>
<h2 id="autorización-en-la-interfaz-rest"><a href="#TOC"><span class="header-section-number">7.3</span> Autorización en la interfaz REST</a></h2>
<p>Todos los tipos de usuario pueden interactuar con la interfaz REST siempre que se le hayan asignado permisos. Sin embargo, sólo los usuarios tipo Admin pueden editar o borrar objetos utilizando los recursos genéricos REST. Los usuarios tipo 'Operator' y tipo 'User' pueden 'ver' los recursos genéricos pero sólo pueden editar o borrar algunas cosas utilizando los recursos de propósito específico como 'rest/host'.</p>
<h2 id="módulo-perl-para-programas-cliente-en-cpan"><a href="#TOC"><span class="header-section-number">7.4</span> Módulo Perl para programas cliente en CPAN</a></h2>
Binary file not shown.
@@ -7,7 +7,7 @@
Version 1.0
Copyright 2012 University of Oregon, Todos los derechos reservados.
Copyright 2014 Carlos Vicente
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 the
@@ -1550,6 +1550,29 @@ POST: {ethernet=>'DEADDEADBEEF'}
http://netdot.localdomain/netdot/rest/host?rrid=3
~~~~
### /rest/devinfo
Puede utilizarse este recurso REST para obtener información extensa
acerca de todos los dispositivos de la red existentes en la base de datos.
La estructura de datos resultante es la misma que utiliza la clase de exportación
para NAGIOS, por lo que puede ser útil en la generación de configuraciones para
otros programas de monitorización.
### /rest/updatedev
This special REST resource can be used to import devices into Netdot,
as an alternative to using SNMP discovery. It accepts only POST requests.
An example using the Perl client library can be found in the Netdot source, at:
Este recurso REST puede ser usado para importar información de dispositivos
de forma alternativa al descubrimiento via SNMP. Acepta solamente peticiones
tipo POST. Se incluye un ejemplo de su utilización con la biblioteca cliente
para Perl ul siguiente archivo dentro de la fuente de Netdot:
~~~~
import/update_dev_rest.pl
~~~~
## Autorización en la interfaz REST
Todos los tipos de usuario pueden interactuar con la interfaz REST
Binary file not shown.
@@ -133,6 +133,8 @@ <h2 class="author">User's Manual</h2>
<li><a href="#updating-existing-records-http-post"><span class="toc-section-number">7.2.1.3</span> Updating existing records (HTTP POST)</a></li>
<li><a href="#deleting-records-http-delete"><span class="toc-section-number">7.2.1.4</span> Deleting records (HTTP DELETE)</a></li>
</ul></li>
<li><a href="#restdevinfo"><span class="toc-section-number">7.2.2</span> /rest/devinfo</a></li>
<li><a href="#restupdatedev"><span class="toc-section-number">7.2.3</span> /rest/updatedev</a></li>
</ul></li>
<li><a href="#restful-interface-authorization"><span class="toc-section-number">7.3</span> RESTful Interface Authorization</a></li>
<li><a href="#client-module-on-cpan"><span class="toc-section-number">7.4</span> Client module on CPAN</a></li>
@@ -143,7 +145,7 @@ <h2 class="author">User's Manual</h2>
<p></p>
<h1 id="copyright"><a href="#TOC"><span class="header-section-number">1</span> Copyright</a></h1>
<p>Version 1.0</p>
<p>Copyright 2012 University of Oregon, all rights reserved.</p>
<p>Copyright 2014 Carlos Vicente</p>
<p>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 the Free Software Foundation; either version 2 of the License, or (at your option) any later version.</p>
<p>This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.</p>
<p>You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.</p>
@@ -702,6 +704,11 @@ <h4 id="deleting-records-http-delete"><a href="#TOC"><span class="header-section
<li>Delete hostname with RR id 3 (also frees IP)</li>
</ul>
<pre><code>http://netdot.localdomain/netdot/rest/host?rrid=3</code></pre>
<h3 id="restdevinfo"><a href="#TOC"><span class="header-section-number">7.2.2</span> /rest/devinfo</a></h3>
<p>This special REST resource can be used to retrieve extensive information about every device in the database using a single GET request. The returned data structure is the same one used by the NAGIOS exporter class.</p>
<h3 id="restupdatedev"><a href="#TOC"><span class="header-section-number">7.2.3</span> /rest/updatedev</a></h3>
<p>This special REST resource can be used to import devices into Netdot, as an alternative to using SNMP discovery. It accepts only POST requests. An example using the Perl client library can be found in the Netdot source, at:</p>
<pre><code>import/update_dev_rest.pl</code></pre>
<h2 id="restful-interface-authorization"><a href="#TOC"><span class="header-section-number">7.3</span> RESTful Interface Authorization</a></h2>
<p>All user types can interact with the RESTful interface as long as they are granted permissions to do so. However only Admin users can edit or delete objects using generic REST resources. Operators and regular users can view generic resources but can only edit or delete them using specific-purpose resources such as 'rest/host'.</p>
<h2 id="client-module-on-cpan"><a href="#TOC"><span class="header-section-number">7.4</span> Client module on CPAN</a></h2>
Binary file not shown.
@@ -7,7 +7,7 @@
Version 1.0
Copyright 2012 University of Oregon, all rights reserved.
Copyright 2014 Carlos Vicente
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 the
@@ -1466,6 +1466,23 @@ POST: {ethernet=>'DEADDEADBEEF'}
http://netdot.localdomain/netdot/rest/host?rrid=3
~~~~
### /rest/devinfo
This special REST resource can be used to retrieve extensive
information about every device in the database
using a single GET request. The returned data structure is the same
one used by the NAGIOS exporter class.
### /rest/updatedev
This special REST resource can be used to import devices into Netdot,
as an alternative to using SNMP discovery. It accepts only POST requests.
An example using the Perl client library can be found in the Netdot source, at:
~~~~
import/update_dev_rest.pl
~~~~
## RESTful Interface Authorization
All user types can interact with the RESTful interface as long as they
View
@@ -0,0 +1,102 @@
#!/usr/bin/perl -w
#
# Sample code demonstrating the use
# of the REST resource: /rest/updatedev
# for importing device data in a single
# operation.
#
use Netdot::Client::REST;
use Data::Dumper;
use XML::Simple;
my $server = 'http://localhost/netdot';
my $username = 'admin';
my $passwd = 'admin';
my $netdot = Netdot::Client::REST->new(server=>$server,
username=>$username,
password=>$passwd);
my $xs = XML::Simple->new(
ForceArray => 1,
XMLDecl => 1,
KeyAttr => 'id',
);
my $info = {
'sysname' => 'newdevice.localdomain',
'ipforwarding' => 0,
'layers' => '01000010',
'sysobjectid' => '',
'model' => 'Foo',
'os' => '1.2.3.4',
'manufacturer' => 'Bar',
'serial_number' => 'abcd1234',
'interface' => {
'1' => {
'name' => 'lo0',
'number' => '1',
'type' => 'softwareLoopback',
'physaddr' => '',
'admin_status' => 'up',
'oper_status' => 'up',
'speed' => '10000000',
'ips' => {
'192.168.10.20' => {
'address' => '192.168.10.20',
'version' => '4',
'subnet' => '192.168.10.20/32'
},
},
},
'2' => {
'name' => 'eth0',
'number' => '2',
'type' => 'ethernet-csmacd',
'physaddr' => 'abcabcabcabc',
'admin_status' => 'up',
'oper_status' => 'up',
'speed' => '1000000000',
'ips' => {
'192.168.100.200' => {
'address' => '192.168.100.200',
'version' => '4',
'subnet' => '192.168.100.0/24'
},
},
},
},
};
my $xml = $xs->XMLout($info);
my $r = $netdot->post('updatedev', { name => 'newdevice.localdomain',
info => $xml });
print Dumper($r);
=head1 AUTHOR
Carlos Vicente, C<< <cvicente at ns.uoregon.edu> >>
=head1 COPYRIGHT & LICENSE
Copyright 2014 Carlos Vicente
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
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
=cut

0 comments on commit f8b806f

Please sign in to comment.