File Coverage

blib/lib/Net/Intermapper/Interface.pm
Criterion Covered Total %
statement 18 43 41.8
branch 0 2 0.0
condition 0 4 0.0
subroutine 5 8 62.5
pod 3 3 100.0
total 26 60 43.3


line stmt bran cond sub pod time code
1             package Net::Intermapper::Interface;
2 1     1   5 use strict;
  1         1  
  1         28  
3 1     1   4 use Moose;
  1         1  
  1         7  
4              
5             BEGIN {
6 1     1   4629 use Exporter ();
  1         1  
  1         21  
7 1     1   3 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS @HEADERS);
  1         2  
  1         109  
8 1     1   2 $VERSION = '0.04';
9 1         14 @ISA = qw(Exporter);
10 1         2 @EXPORT = qw();
11 1         2 @EXPORT_OK = qw();
12 1         1 %EXPORT_TAGS = ();
13            
14 1         472 @HEADERS = qw(MapName InterfaceID DeviceID NetworkID Index IntegerIndex Description Name Alias PhysAddress Type MTU Address SubnetMask SubnetList SubnetPrefixList Speed PreferredSpeed ReportedSPeed LastChange
15             Status Enabled MapId IMID TypeInt RecvSpeed StatusInt CustomerNameReference DataRetentionPolicy Duplex VLANs NatVLAN);
16            
17             };
18              
19             # MOOSE!
20            
21             has 'MapName' => (
22             is => 'rw',
23             isa => 'Str',
24             );
25              
26             has 'InterfaceID' => (
27             is => 'rw',
28             isa => 'Str',
29             );
30              
31             has 'DeviceID' => (
32             is => 'rw',
33             isa => 'Str',
34             );
35              
36             has 'NetworkID' => (
37             is => 'rw',
38             isa => 'Str',
39             );
40              
41             has 'Index' => (
42             is => 'rw',
43             isa => 'Str',
44             );
45              
46             has 'IntegerIndex' => (
47             is => 'rw',
48             isa => 'Str',
49             );
50              
51             has 'Description' => (
52             is => 'rw',
53             isa => 'Str',
54             );
55              
56             has 'Name' => (
57             is => 'rw',
58             isa => 'Str',
59             );
60              
61             has 'Alias' => (
62             is => 'rw',
63             isa => 'Str',
64             );
65              
66             has 'PhysAddress' => (
67             is => 'rw',
68             isa => 'Str',
69             );
70              
71             has 'Type' => (
72             is => 'rw',
73             isa => 'Str',
74             );
75              
76             has 'MTU' => (
77             is => 'rw',
78             isa => 'Str',
79             );
80              
81             has 'Address' => (
82             is => 'rw',
83             isa => 'Str',
84             );
85              
86             has 'SubnetMask' => (
87             is => 'rw',
88             isa => 'Str',
89             );
90              
91             has 'SubnetList' => (
92             is => 'rw',
93             isa => 'Str',
94             );
95              
96             has 'SubnetPrefixList' => (
97             is => 'rw',
98             isa => 'Str',
99             );
100              
101             has 'Speed' => (
102             is => 'rw',
103             isa => 'Str',
104             );
105              
106             has 'PreferredSpeed' => (
107             is => 'rw',
108             isa => 'Str',
109             );
110              
111             has 'ReportedSPeed' => (
112             is => 'rw',
113             isa => 'Str',
114             );
115              
116             has 'LastChange' => (
117             is => 'rw',
118             isa => 'Str',
119             );
120              
121             has 'Status' => (
122             is => 'rw',
123             isa => 'Str',
124             );
125              
126             has 'Enabled' => (
127             is => 'rw',
128             isa => 'Str',
129             );
130              
131             has 'MapId' => (
132             is => 'rw',
133             isa => 'Str',
134             );
135              
136             has 'IMID' => (
137             is => 'rw',
138             isa => 'Str',
139             );
140              
141             has 'TypeInt' => (
142             is => 'rw',
143             isa => 'Str',
144             );
145              
146             has 'RecvSpeed' => (
147             is => 'rw',
148             isa => 'Str',
149             );
150              
151             has 'StatusInt' => (
152             is => 'rw',
153             isa => 'Str',
154             );
155              
156             has 'CustomerNameReference' => (
157             is => 'rw',
158             isa => 'Str',
159             );
160              
161             has 'DataRetentionPolicy' => (
162             is => 'rw',
163             isa => 'Str',
164             );
165              
166             has 'Duplex' => (
167             is => 'rw',
168             isa => 'Str',
169             );
170              
171             has 'VLANs' => (
172             is => 'rw',
173             isa => 'Str',
174             );
175              
176             has 'NatVLAN' => (
177             is => 'rw',
178             isa => 'Str',
179             );
180              
181             # No Moose
182            
183             sub toXML
184 0     0 1   { my $self = shift;
185 0           my $id = $self->Id;
186 0           my $result = "";
187            
188 0 0         if ($id) { $result = " <id>$id</id>\n"; }
  0            
189 0           return $result;
190             }
191              
192             sub toCSV
193 0     0 1   { my $self = shift;
194 0           my $id = $self->IMID; # Hopefully this is unique enough
195 0           my $result = "";
196 0           my @attributes = $self->meta->get_all_attributes;
197 0           my %attributes = ();
198 0           for my $attribute (@attributes)
199 0   0       { $attributes{$attribute->name} = $attribute->get_value($self) || "";
200             }
201 0           for my $key (@HEADERS)
202 0           { $result .= $attributes{$key}.","; }
203 0           chop $result; # Remove the comma of the last field
204 0           $result .= "\r\n";
205 0           return $result;
206             }
207              
208             sub header
209 0     0 1   { my $self = shift;
210 0   0       my $format = shift || "";
211 0           my $header = "# format=$format table=interfaces fields=";
212 0           for my $key (@HEADERS)
213 0           { $header .= $key.","; }
214 0           $header .= "\r\n";
215 0           return $header;
216             }
217              
218             =pod
219            
220             =head1 NAME
221              
222             Net::Intermapper::Interface - Interface with the HelpSystems Intermapper HTTP API - Interfaces
223              
224             =head1 SYNOPSIS
225              
226             use Net::Intermapper;
227             my $intermapper = Net::Intermapper->new(hostname=>"10.0.0.1", username=>"admin", password=>"nmsadmin");
228             # Options:
229             # hostname - IP or hostname of Intermapper 5.x and 6.x server
230             # username - Username of Administrator user
231             # password - Password of user
232             # ssl - SSL enabled (1 - default) or disabled (0)
233             # port - TCP port for querying information. Defaults to 8181
234             # modifyport - TCP port for modifying information. Default to 443
235             # cache - Boolean to enable smart caching or force network queries
236              
237             my %users = $intermapper->users;
238             my $users_ref = $intermapper->users;
239             # Retrieve all users from Intermapper, Net::Intermapper::User instances
240             # Returns hash or hashref, depending on context
241            
242             my %devices = $intermapper->devices;
243             my $devices_ref = $intermapper->devices;
244             # Retrieve all devices from Intermapper, Net::Intermapper::Device instances
245             # Returns hash or hashref, depending on context
246              
247             my %maps = $intermapper->maps;
248             my $maps_ref = $intermapper->maps;
249             # Retrieve all maps from Intermapper, Net::Intermapper::Map instances
250             # Returns hash or hashref, depending on context
251              
252             my %interfaces = $intermapper->interfaces;
253             my $interfaces_ref = $intermapper->interfaces;
254             # Retrieve all interfaces from Intermapper, Net::Intermapper::Interface instances
255             # Returns hash or hashref, depending on context
256              
257             my %vertices = $intermapper->vertices;
258             my $vertices_ref = $intermapper->vertices;
259             # Retrieve all vertices from Intermapper, Net::Intermapper::Vertice instances
260             # Returns hash or hashref, depending on context
261              
262             my $user = $intermapper->users->{"admin"};
263            
264             # Each class will generate specific header. These are typically only for internal use but are compliant to the import format Intermapper uses.
265             print $user->header;
266             print $device->header;
267             print $map->header;
268             print $interface->header;
269             print $vertice->header;
270              
271             print $user->toTAB;
272             print $device->toXML; # This one is broken still!
273             print $map->toCSV;
274             # Works on ALL subclasses
275             # Produce human-readable output of each record in the formats Intermapper supports
276            
277             my $user = Net::Intermapper::User->new(Name=>"testuser", Password=>"Test12345");
278             my $response = $intermapper->create($user);
279             # Create new user
280             # Return value is HTTP::Response object
281            
282             my $device = Net::Intermapper::Device->new(Name=>"testDevice", MapName=>"TestMap", MapPath=>"/TestMap", Address=>"10.0.0.1");
283             my $response = $intermapper->create($device);
284             # Create new device
285             # Return value is HTTP::Response object
286              
287             $user->Password("Foobar123");
288             my $response = $intermapper->update($user);
289             # Update existing user
290             # Return value is HTTP::Response object
291              
292             my $user = $intermapper->users->{"bob"};
293             my $response = $intermapper->delete($user);
294             # Delete existing user
295             # Return value is HTTP::Response object
296              
297             my $device = $intermapper->devices->{"UniqueDeviceID"};
298             my $response = $intermapper->delete($device);
299             # Delete existing device
300             # Return value is HTTP::Response object
301              
302             my $users = { "Tom" => $tom_user, "Bob" => $bob_user };
303             $intermapper->users($users);
304             # At this point, there is no real reason to do this as update, create and delete work with explicit arguments.
305             # But it can be done with users, devices, interfaces, maps and vertices
306             # Pass a hashref to each method. This will NOT affect the smart-caching (only explicit calls to create, update and delete do this - for now).
307            
308             =head1 DESCRIPTION
309              
310             Net::Intermapper::Interface is a perl wrapper around the HelpSystems Intermapper API provided through HTTP/HTTPS for access to interface information.
311              
312             All calls are handled through an instance of the L<Net::Intermapper> class.
313              
314             use Net::Intermapper;
315             my $intermapper = Net::Intermapper->new(hostname => '10.0.0.1', username => 'admin', password => 'nmsadmin');
316              
317             =head1 USAGE
318              
319             =over 3
320              
321             =item new
322              
323             Class constructor. Returns object of Net::Intermapper::Interface on succes. Attributes are:
324              
325             =over 5
326              
327             =item MapName (read-only)
328              
329             The name of the map to which the interface belongs.
330              
331             =item InterfaceID (read-only)
332              
333             A unique persistent identifier for this interface instance. This value is used for lookups in the C<users> method in L<Net::Intermapper>.
334              
335             =item DeviceID (read-only)
336              
337             The unique persistent identifier for the adjacent device.
338              
339             =item NetworkID (read-only)
340              
341             The unique persistent identifier for the adjacent network.
342              
343             =item Index (read-only)
344              
345             The interface index (i.e. ifIndex) of the interface.
346              
347             =item IntegerIndex (read-only)
348              
349             The interface index (i.e. ifIndex) of the interface, as an integer.
350              
351             =item Description (read-only)
352              
353             The interface description (i.e. ifDescr).
354              
355             =item Name (read-only)
356              
357             The interface name (i.e. ifName).
358              
359             =item Alias (read-only)
360              
361             The interface alias (i.e. ifAlias).
362              
363             =item PhysAddress (read-only)
364              
365             The interface's data-link layer address (i.e. ifPhysAddr) .
366              
367             =item Type (read-only)
368              
369             The interface type as a human-readable string (i.e. ifType).
370              
371             =item MTU (read-only)
372              
373             The interface MTU (i.e. ifMTU).
374              
375             =item Address (read-only)
376              
377             The interface's first network-layer address.
378              
379             =item SubnetMask (read-only)
380              
381             The subnet mask associated with Address.
382              
383             =item SubnetList (read-only)
384              
385             A comma-separated list of addresses/masks on this interface.
386              
387             =item SubnetPrefixList (read-only)
388              
389             A comma-separated list of addresses/prefixes on this interface.
390              
391             =item Speed (read-only)
392              
393             The interface's speed in bits per second. (Derived from preferred speed and reported speed.)
394              
395             =item PreferredSpeed (read-write)
396              
397             The preferred speed of the interface as set by the customer.
398              
399             =item ReportedSpeed (read-only)
400              
401             The speed of the interface as reported by the interface.
402              
403             =item LastChange (read-only)
404              
405             The timestamp when the interface last changed status.
406              
407             =item Status (read-only)
408              
409             The status of the interface (e.g. UP, DOWN, or ADMIN-DOWN).
410              
411             =item Enabled (read-write)
412              
413             Flag which indicates whether the interface is enabled or not.
414              
415             =item MapId (read-only)
416              
417             The unique persistent identifier for the map to which the interface belongs.
418              
419             =item IMID (read-only)
420              
421             Identifier of the interface in the IMID format.
422              
423             =item TypeInt (read-only)
424              
425             The interface type as a number.
426              
427             =item RecvSpeed (read-write)
428              
429             Unsigned 64-bit integer. 0 means baseband; speed in Speed.
430              
431             =item StatusInt (read-only)
432              
433             The status of the interface as integer. Values correspond to {UP, DOWN, ADMIN-DOWN, DOWN but locally acked}.
434              
435             =item CustomerNameReference (read-only)
436              
437             Customer-supplied name, for referencing an external database.
438              
439             =item DataRetentionPolicy (read-only)
440              
441             Database data retention policy.
442              
443             =item Duplex (read-only)
444              
445             Interface Duplex status.
446              
447             =item VLANs (read-only)
448              
449             Comma-separated list of this interface's VLANs.
450              
451             =item NatVLAN (read-write)
452              
453             Native VLAN. Signed integer (0-4093). 0 means none.
454              
455             =back
456              
457             =over 3
458              
459             =item header
460              
461             Returns the C<directive> aka data header required by the Intermapper API to perform CRUD actions. This is handled through the C<create>, C<update> and C<delete> method and should not really be used.
462              
463             =back
464              
465             =over 3
466              
467             =item toTAB
468              
469             Returns the object data formatted in TAB delimited format. Used in combination with the C<header> and the C<format> method in L<Net::Intermapper> to perform CRUD actions. This is handled through the C<create>, C<update> and C<delete> method and should not really be used.
470              
471             =back
472              
473             =over 3
474              
475             =item toCSV
476              
477             Returns the object data formatted in Comma Separated delimited format. Used in combination with the C<header> and the C<format> method in L<Net::Intermapper> to perform CRUD actions. This is handled through the C<create>, C<update> and C<delete> method and should not really be used.
478              
479             =back
480              
481             =over 3
482              
483             =item toXML
484              
485             Returns the object data formatted in XML format. Used in combination with the C<header> and the C<format> method in L<Net::Intermapper> to perform CRUD actions. This is handled through the C<create>, C<update> and C<delete> method and should not really be used.
486              
487             =back
488              
489             =over 3
490              
491             =item mode
492              
493             Internal method to properly format the data and header for CRUD actions. Typically not used.
494              
495             =back
496              
497             =item $ERROR
498              
499             NEEDS TO BE ADDED
500              
501             This variable will contain detailed error information.
502            
503             =back
504              
505             =head1 REQUIREMENTS
506              
507             For this library to work, you need an instance with Intermapper (obviously) or a simulator like L<Net::Intermapper::Mock>.
508              
509             =over 3
510              
511             =item L<Moose>
512              
513             =item L<IO::Socket::SSL>
514              
515             =item L<LWP::UserAgent>
516              
517             =item L<XML::Simple>
518              
519             =item L<MIME::Base64>
520              
521             =item L<URI::Escape>
522              
523             =item L<Text::CSV_XS>
524              
525             =back
526            
527             =head1 BUGS
528              
529             None so far
530              
531             =head1 SUPPORT
532              
533             None so far :)
534              
535             =head1 AUTHOR
536              
537             Hendrik Van Belleghem
538             CPAN ID: BEATNIK
539             hendrik.vanbelleghem@gmail.com
540              
541             =head1 COPYRIGHT
542              
543             This program is free software licensed under the...
544              
545             The General Public License (GPL)
546             Version 2, June 1991
547              
548             The full text of the license can be found in the
549             LICENSE file included with this module.
550              
551              
552             =head1 SEE ALSO
553              
554             L<http://download.intermapper.com/docs/UserGuide/Content/09-Reference/09-05-Advanced_Importing/the_directive_line.htm>
555             L<http://download.intermapper.com/schema/imserverschema.html>
556              
557             =cut
558              
559             #################### main pod documentation end ###################
560              
561             __PACKAGE__->meta->make_immutable();
562              
563             1;
564             # The preceding line will help the module return a true value
565