Netdot...::REST(3pm)

πŸ“¦
version 1.03 Β· 2 versions
  • 1.03 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 1.03 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Netdot::Client::REST(3pm) β€” the RESTful API for Netdot, bestie πŸ’–

Okay so this is a page from the User Contributed Perl Documentation for Perl v5.36.0, and it's about Netdot::Client::REST. Pull up a chair, grab a strawberry πŸ“, and let's get into it.


✨ NAME ✨

Netdot::Client::REST β€” the RESTful API for Netdot πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

Like, here's the vibe in code form, no cap:

use Netdot::Client::REST;
use Data::Dumper;

my $netdot = Netdot::Client::REST->new(
    server=>'http://localhost.localdomain/netdot',
    username=>'admin',
    password=>'xxxxx',
    );

# Get all devices
my @devs = $netdot->get('/Device');

print Dumper(@devs);

# Get Device id 1
my $dev = $netdot->get('/Device/1');

# Get Device id 1 and foreign objects one level away
my $dev = $netdot->get('/Device/1?depth=1');

# Update Device 1
$dev = $netdot->post('/Device/1', {community=>'public'});

# Delete Device 1
$netdot->delete('/Device/1');

See examples/ directory for a sample script πŸ‘€ (yes, fr fr, there's a whole script in there for you)


🌸 DESCRIPTION 🌸

So Netdot::Client::REST is the thing you reach for when your Perl script needs to get into the Netdot application database. 🫢 It talks over HTTP/HTTPS, which is the iconic part, because it means you do NOT have to open up SQL access on the machine running Netdot. We love a safe king. πŸ‘‘


πŸ‘‘ CLASS METHODS πŸ‘‘

πŸ’« new - Constructor and login method πŸ’«

It's giving "let me in". πŸšͺ✨

Arguments:

  • server β€” Netdot installation URL (e.g. http://host.localdomain/netdot)
  • username β€” Netdot username
  • password β€” Netdot password
  • retries β€” Number of retries (default: 3)
  • timeout β€” seconds (default: 10)
  • format β€” Representation format (default: xml)
Currently only XML is supported. πŸ’€ Like, that's it. That's the format. Don't come for me, I just work here.

Returns:

  • Netdot::Client::REST object

Examples:

my $netdot = Netdot::Client::REST->new(
     server   =>'http://host.localdomain/netdot',
     username => 'myuser',
     password => 'mypass',
);

πŸŽ€ INSTANCE METHODS πŸŽ€

🧚 get - Get all attributes from one or more Netdot objects 🧚

The main character of this whole module, honestly. ✨

Arguments:

  • Resource β€” string containing RESTful resource

And okay, bestie, this next part is important, so listen up:

In addition to the object's class and (optional) ID, the HTTP argument "depth" lets you fetch all foreign objects recursively, limited by the value of the depth argument. 🌈 Foreign objects include relational records referenced by the given object and records that reference the given object β€” that's both sides of the one-to-many relationship. The performance impact of the given depth is a balance between fewer queries with large datasets and more queries with smaller datasets. The default depth is 0 (only return the given object plus references to objects directly related).

Returns:

  • hashref with object's attributes

And here's the cute lil magic trick: a special attribute is added for each foreign key, so you can request that resource more easily. For example, if a record has a field called 'foo' which is a foreign key pointing to a record of class 'Bar', with id '1', then the result hashref will include keys like:

foo => 'Foo bar name',
foo_xlink => 'Bar/1',

where 'foo_xlink' can be passed to this method to get the full Bar/1 resource. πŸ¦‹ Obsessed, honestly.

Examples:

my $dev = $netdot->get('Device/1');
my $dev = $netdot->get('Device/1?depth=1');
my @alldevs = $netdot->get('Device');
my @mydevs = $netdot->get('Device?sysname=mydev');

⭐ post - Update or Insert a Netdot object ⭐

Arguments:

  • Resource β€” string containing RESTful resource
  • data β€” Hashref containing key/value pairs

Returns:

  • hashref with object's attributes

Examples:

$netdot->post('Device/1', \%data);
$netdot->post('Device', \%data);

πŸ”₯ delete - Delete a Netdot object πŸ”₯

Gone. Poof. πŸ’… (Be careful with this one, bestie, there's no undo button in the manpage. 😭)

Arguments:

  • Resource β€” string containing RESTful resource

Returns:

  • True if successful

Examples:

$netdot->delete('Device/1');

πŸ’œ AUTHOR πŸ’œ

Carlos Vicente <cvicente@cpan.org>


🌈 SEE ALSO 🌈

The Network Documentation Tool <http://netdot.uoregon.edu>


Copyright (c) 2012, Carlos Vicente <cvicente@cpan.org>. All rights reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.


πŸ’€ DISCLAIMER OF WARRANTY πŸ’€

Okay so this part is in ALL CAPS in the original and I am NOT about to soften it, because it's real and it matters:

BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.


And that's the whole page, bestie. 🫢 This lil number comes from the Netdot...::REST(3pm) manual, perl v5.36.0, dated 2022-10-22. Slay, go build something iconic. βœ¨πŸ‘‘

πŸ“¦ where this page comes from