blib/lib/Net/Intermapper/Interface.pm

filter: Statementstmt 67.5% 52 / 77 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 62.5% 5 / 8 Podpod 100% 3 / 3 totaltotal 62.5% 60 / 96 CC 7 SCAR 22.5
CC
7
Cov
63%
toCSV
20.0
header
12.0
toXML
6.0
CRAP 9.5
« blib/lib/Net/Intermapper/Vertice.pm ↑ Summary Build »
1 package Net::Intermapper::Interface;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 BEGIN {
6 1 ▶ use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶ use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS @HEADERS);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶ $VERSION = '0.02';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 @ISA = qw(Exporter);
10 1 @EXPORT = qw();
11 1 @EXPORT_OK = qw();
12 1 %EXPORT_TAGS = ();
13
14 1 @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 1 has 'MapName' => (
22 is => 'rw',
23 isa => 'Str',
24 );
25  
26 1 has 'InterfaceID' => (
27 is => 'rw',
28 isa => 'Str',
29 );
30  
31 1 has 'DeviceID' => (
32 is => 'rw',
33 isa => 'Str',
34 );
35  
36 1 has 'NetworkID' => (
37 is => 'rw',
38 isa => 'Str',
39 );
40  
41 1 has 'Index' => (
42 is => 'rw',
43 isa => 'Str',
44 );
45  
46 1 has 'IntegerIndex' => (
47 is => 'rw',
48 isa => 'Str',
49 );
50  
51 1 has 'Description' => (
52 is => 'rw',
53 isa => 'Str',
54 );
55  
56 1 has 'Name' => (
57 is => 'rw',
58 isa => 'Str',
59 );
60  
61 1 has 'Alias' => (
62 is => 'rw',
63 isa => 'Str',
64 );
65  
66 1 has 'PhysAddress' => (
67 is => 'rw',
68 isa => 'Str',
69 );
70  
71 1 has 'Type' => (
72 is => 'rw',
73 isa => 'Str',
74 );
75  
76 1 has 'MTU' => (
77 is => 'rw',
78 isa => 'Str',
79 );
80  
81 1 has 'Address' => (
82 is => 'rw',
83 isa => 'Str',
84 );
85  
86 1 has 'SubnetMask' => (
87 is => 'rw',
88 isa => 'Str',
89 );
90  
91 1 has 'SubnetList' => (
92 is => 'rw',
93 isa => 'Str',
94 );
95  
96 1 has 'SubnetPrefixList' => (
97 is => 'rw',
98 isa => 'Str',
99 );
100  
101 1 has 'Speed' => (
102 is => 'rw',
103 isa => 'Str',
104 );
105  
106 1 has 'PreferredSpeed' => (
107 is => 'rw',
108 isa => 'Str',
109 );
110  
111 1 has 'ReportedSPeed' => (
112 is => 'rw',
113 isa => 'Str',
114 );
115  
116 1 has 'LastChange' => (
117 is => 'rw',
118 isa => 'Str',
119 );
120  
121 1 has 'Status' => (
122 is => 'rw',
123 isa => 'Str',
124 );
125  
126 1 has 'Enabled' => (
127 is => 'rw',
128 isa => 'Str',
129 );
130  
131 1 has 'MapId' => (
132 is => 'rw',
133 isa => 'Str',
134 );
135  
136 1 has 'IMID' => (
137 is => 'rw',
138 isa => 'Str',
139 );
140  
141 1 has 'TypeInt' => (
142 is => 'rw',
143 isa => 'Str',
144 );
145  
146 1 has 'RecvSpeed' => (
147 is => 'rw',
148 isa => 'Str',
149 );
150  
151 1 has 'StatusInt' => (
152 is => 'rw',
153 isa => 'Str',
154 );
155  
156 1 has 'CustomerNameReference' => (
157 is => 'rw',
158 isa => 'Str',
159 );
160  
161 1 has 'DataRetentionPolicy' => (
162 is => 'rw',
163 isa => 'Str',
164 );
165  
166 1 has 'Duplex' => (
167 is => 'rw',
168 isa => 'Str',
169 );
170  
171 1 has 'VLANs' => (
172 is => 'rw',
173 isa => 'Str',
174 );
175  
176 1 has 'NatVLAN' => (
177 is => 'rw',
178 isa => 'Str',
179 );
180  
181 # No Moose
182
183 sub toXML
184 0 ▶{ my $self = shift;
Subroutine toXML: not called CC=2 SCAR=17.9
Pod documented
185 0 my $id = $self->Id;
186 0 my $result = "";
187
188 0 ▶ if ($id) { $result = " <id>$id</id>\n"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($id) 0 0 0
189 0 return $result;
190 }
191  
192 sub toCSV
193 0 ▶{ my $self = shift;
Subroutine toCSV: not called CC=4 SCAR=30.0
Pod documented
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 ▶ { $attributes{$attribute->name} = $attribute->get_value($self) || "";
Condition0%0/2
$attribute->get_value($self) || ''
l!l
00
MC/DC0%0/1
$attribute->get_value($self) || ''
$attribute->get_value($self)
Truth table0%0/2
A
A= $attribute->get_value($self)
Aresult
11
00
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 ▶{ my $self = shift;
Subroutine header: not called CC=3 SCAR=24.8
Pod documented
210 0 ▶ my $format = shift || "";
Condition0%0/2
shift() || ''
l!l
00
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
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 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 print $user->header;
264 print $device->header;
265 print $map->header;
266 print $interface->header;
267 print $vertice->header;
268 # Generate 'directive' needed for manipulation. Mostly used internally.
269 # $user->mode("create"); # This changes the header fields
270 # $user->mode("update"); # This also changes the header fields
271 # Both are NOT needed when adding or updating a record
272 print $user->toTAB;
273 print $device->toXML;
274 print $map->toCSV;
275 # Works on ALL classes
276 # Produce human-readable output of each record.
277
278 my $user = Net::Intermapper::User->new(Name=>"testuser", Password=>"Test12345");
279 my $response = $intermapper->create($user);
280 # Create new user
281 # Return value is HTTP::Response object
282
283 my $device = Net::Intermapper::Device->new(Name=>"testDevice", MapName=>"TestMap", MapPath=>"/TestMap", Address=>"10.0.0.1");
284 my $response = $intermapper->create($device);
285 # Create new device
286 # Return value is HTTP::Response object
287  
288 $user->Password("Foobar123");
289 my $response = $intermapper->update($user);
290 # Update existing user
291 # Return value is HTTP::Response object
292  
293 my $user = $intermapper->users->{"bob"};
294 my $response = $intermapper->delete($user);
295 # Delete existing user
296 # Return value is HTTP::Response object
297  
298 my $device = $intermapper->devices->{"UniqueDeviceID"};
299 my $response = $intermapper->delete($device);
300 # Delete existing device
301 # Return value is HTTP::Response object
302  
303 my $users = { "Tom" => $tom_user, "Bob" => $bob_user };
304 $intermapper->users($users);
305 # At this point, there is no real reason to do this as update, create and delete work with explicit arguments.
306 # But it can be done with users, devices, interfaces, maps and vertices
307 # 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).
308
309 =head1 DESCRIPTION
310  
311 Net::Intermapper::Interface is a perl wrapper around the HelpSystems Intermapper API provided through HTTP/HTTPS for access to interface information.
312  
313 All calls are handled through an instance of the L<Net::Intermapper> class.
314  
315 use Net::Intermapper;
316 my $intermapper = Net::Intermapper->new(hostname => '10.0.0.1', username => 'admin', password => 'nmsadmin');
317  
318 =head1 USAGE
319  
320 =over 3
321  
322 =item new
323  
324 Class constructor. Returns object of Net::Intermapper::Interface on succes. Attributes are:
325  
326 =over 5
327  
328 =item MapName (read-only)
329  
330 The name of the map to which the interface belongs.
331  
332 =item InterfaceID (read-only)
333  
334 A unique persistent identifier for this interface instance. This value is used for lookups in the C<users> method in L<Net::Intermapper>.
335  
336 =item DeviceID (read-only)
337  
338 The unique persistent identifier for the adjacent device.
339  
340 =item NetworkID (read-only)
341  
342 The unique persistent identifier for the adjacent network.
343  
344 =item Index (read-only)
345  
346 The interface index (i.e. ifIndex) of the interface.
347  
348 =item IntegerIndex (read-only)
349  
350 The interface index (i.e. ifIndex) of the interface, as an integer.
351  
352 =item Description (read-only)
353  
354 The interface description (i.e. ifDescr).
355  
356 =item Name (read-only)
357  
358 The interface name (i.e. ifName).
359  
360 =item Alias (read-only)
361  
362 The interface alias (i.e. ifAlias).
363  
364 =item PhysAddress (read-only)
365  
366 The interface's data-link layer address (i.e. ifPhysAddr) .
367  
368 =item Type (read-only)
369  
370 The interface type as a human-readable string (i.e. ifType).
371  
372 =item MTU (read-only)
373  
374 The interface MTU (i.e. ifMTU).
375  
376 =item Address (read-only)
377  
378 The interface's first network-layer address.
379  
380 =item SubnetMask (read-only)
381  
382 The subnet mask associated with Address.
383  
384 =item SubnetList (read-only)
385  
386 A comma-separated list of addresses/masks on this interface.
387  
388 =item SubnetPrefixList (read-only)
389  
390 A comma-separated list of addresses/prefixes on this interface.
391  
392 =item Speed (read-only)
393  
394 The interface's speed in bits per second. (Derived from preferred speed and reported speed.)
395  
396 =item PreferredSpeed (read-write)
397  
398 The preferred speed of the interface as set by the customer.
399  
400 =item ReportedSpeed (read-only)
401  
402 The speed of the interface as reported by the interface.
403  
404 =item LastChange (read-only)
405  
406 The timestamp when the interface last changed status.
407  
408 =item Status (read-only)
409  
410 The status of the interface (e.g. UP, DOWN, or ADMIN-DOWN).
411  
412 =item Enabled (read-write)
413  
414 Flag which indicates whether the interface is enabled or not.
415  
416 =item MapId (read-only)
417  
418 The unique persistent identifier for the map to which the interface belongs.
419  
420 =item IMID (read-only)
421  
422 Identifier of the interface in the IMID format.
423  
424 =item TypeInt (read-only)
425  
426 The interface type as a number.
427  
428 =item RecvSpeed (read-write)
429  
430 Unsigned 64-bit integer. 0 means baseband; speed in Speed.
431  
432 =item StatusInt (read-only)
433  
434 The status of the interface as integer. Values correspond to {UP, DOWN, ADMIN-DOWN, DOWN but locally acked}.
435  
436 =item CustomerNameReference (read-only)
437  
438 Customer-supplied name, for referencing an external database.
439  
440 =item DataRetentionPolicy (read-only)
441  
442 Database data retention policy.
443  
444 =item Duplex (read-only)
445  
446 Interface Duplex status.
447  
448 =item VLANs (read-only)
449  
450 Comma-separated list of this interface's VLANs.
451  
452 =item NatVLAN (read-write)
453  
454 Native VLAN. Signed integer (0-4093). 0 means none.
455  
456 =back
457  
458 =over 3
459  
460 =item header
461  
462 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.
463  
464 =back
465  
466 =over 3
467  
468 =item toTAB
469  
470 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.
471  
472 =back
473  
474 =over 3
475  
476 =item toCSV
477  
478 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.
479  
480 =back
481  
482 =over 3
483  
484 =item toXML
485  
486 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.
487  
488 =back
489  
490 =over 3
491  
492 =item mode
493  
494 Internal method to properly format the data and header for CRUD actions. Typically not used.
495  
496 =back
497  
498 =item $ERROR
499  
500 NEEDS TO BE ADDED
501  
502 This variable will contain detailed error information.
503
504 =back
505  
506 =head1 REQUIREMENTS
507  
508 For this library to work, you need an instance with Intermapper (obviously) or a simulator like L<Net::Intermapper::Mock>.
509  
510 =over 3
511  
512 =item L<Moose>
513  
514 =item L<IO::Socket::SSL>
515  
516 =item L<LWP::UserAgent>
517  
518 =item L<XML::Simple>
519  
520 =item L<MIME::Base64>
521  
522 =item L<URI::Escape>
523  
524 =back
525
526 =head1 BUGS
527  
528 None so far
529  
530 =head1 SUPPORT
531  
532 None so far :)
533  
534 =head1 AUTHOR
535  
536 Hendrik Van Belleghem
537 CPAN ID: BEATNIK
538 hendrik.vanbelleghem@gmail.com
539  
540 =head1 COPYRIGHT
541  
542 This program is free software licensed under the...
543  
544 The General Public License (GPL)
545 Version 2, June 1991
546  
547 The full text of the license can be found in the
548 LICENSE file included with this module.
549  
550  
551 =head1 SEE ALSO
552  
553 L<http://download.intermapper.com/docs/UserGuide/Content/09-Reference/09-05-Advanced_Importing/the_directive_line.htm>
554 L<http://download.intermapper.com/schema/imserverschema.html>
555  
556 =cut
557  
558 #################### main pod documentation end ###################
559  
560 1 __PACKAGE__->meta->make_immutable();
561  
562 1 1;
563 # The preceding line will help the module return a true value
564  
« blib/lib/Net/Intermapper/Vertice.pm ↑ Summary Build »