File Coverage

blib/lib/IBM/SONAS.pm
Criterion Covered Total %
statement 15 25 60.0
branch n/a
condition n/a
subroutine 5 9 55.5
pod 1 1 100.0
total 21 35 60.0


line stmt bran cond sub pod time code
1             package IBM::SONAS;
2              
3 1     1   24643 use strict;
  1         2  
  1         41  
4 1     1   6 use warnings;
  1         2  
  1         30  
5              
6 1     1   1084 use IBM::StorageSystem;
  1         101586  
  1         40  
7 1     1   10 use Carp qw(croak);
  1         1  
  1         82  
8              
9             our $VERSION = '0.023';
10              
11             our @METHODS=qw(health disk export filesystem interface mount node quota replication service snapshot task);
12             # TO DO: lssnspshot lsrepl lsrepltask
13              
14             foreach my $method ( @METHODS ) {
15             {
16 1     1   11 no strict 'refs';
  1         1  
  1         327  
17             my $get_method = "get_$method";
18             my $get_methods = "get_${method}s";
19            
20             *{ __PACKAGE__ ."::$method" } = sub {
21 0     0     my $self = shift;
22 0           $self->{ss}->$method(@_)
23             };
24              
25             *{ __PACKAGE__ ."::$get_method" } = sub {
26 0     0     my $self = shift;
27 0           $self->{ss}->$get_method(@_)
28             };
29              
30             *{ __PACKAGE__ ."::$get_methods" } = sub {
31 0     0     my $self = shift;
32 0           $self->{ss}->$get_methods(@_)
33             }
34             }
35             }
36              
37             sub new {
38 0     0 1   my ($class, %args) = @_;
39 0           my $self = bless {} , $class;
40 0           $self->{ss} = IBM::StorageSystem->new( %args, no_stats => 1 );
41 0           return $self
42             }
43              
44             =head1 NAME
45              
46             IBM::SONAS - Perl API to IBM SONAS CLI
47              
48             =head1 VERSION
49              
50             Version 0.01
51              
52             =head1 SYNOPSIS
53              
54             IBM::SONAS is a Perl API to IBM SONAS CLI.
55              
56             use IBM::SONAS;
57              
58             # Create an IBM::SONAS object
59              
60             my $ibm = IBM::SONAS->new(
61             user => 'admin',
62             host => 'my-sonas.company.com',
63             key_path => '/path/to/my/.ssh/private_key'
64             ) or die "Couldn't create object! $!\n";
65              
66             =head1 METHODS
67              
68             =head3 new ( %ARGS )
69              
70             my $ibm = IBM::SONAS->new(
71             user => 'admin',
72             host => 'my-sonas.company.com',
73             key_path => '/path/to/my/.ssh/private_key'
74             ) or die "Couldn't create object! $!\n";
75              
76             Constructor - creates a new IBM::SONAS object. This method accepts three mandatory parameters
77             and one optional parameter, the three mandatory parameters are:
78              
79             =over 3
80              
81             =item user
82              
83             The username of the user with which to connect to the device.
84              
85             =item host
86              
87             The hostname or IP address of the device to which we are connecting.
88              
89             =item key_path
90              
91             Either a relative or fully qualified path to the private ssh key valid for the
92             user name and device to which we are connecting. Please note that the executing user
93             must have read permission to this key.
94              
95             =back
96              
97             =head3 disk ( $id )
98              
99             # Get the disk named "system_vol_00" as an IBM::StorageSystem::Disk object
100              
101             my $disk = $ibm->disk(system_vol_00);
102            
103             # Print the disk status
104              
105             print $disk->status;
106              
107             # Alternately
108              
109             print $ibm->disk(system_vol_00)->status;
110              
111             Returns a L object representing the disk specified by the value of the id parameter,
112             which should be a valid disk name in the target system.
113              
114             B that this is a caching method and that a previously retrieved L object will
115             be returned if one has been cached from previous invocations.
116              
117             =head3 get_disk( $id )
118              
119             This is a functionally equivalent non-caching implementation of the B method.
120              
121             =head3 get_disks
122              
123             # Print a listing of all disks in the target system including their name, the assigned pool and status
124              
125             printf( "%-20s%-20s%-20s\n",
126             "Name",
127             "Pool",
128             "Status"
129             );
130             printf( "%-20s%-20s%-20s\n",
131             "-----",
132             "------",
133             "-------"
134             );
135              
136             foreach my $disk ( $ibm->get_disks ) {
137             printf( "%-20s%-20s%-20s\n",
138             $disk->name,
139             $disk->pool,
140             $disk->status
141             )
142             }
143              
144             # Prints something like:
145             #
146             # Name Pool Status
147             # ----- ------ -------
148             # silver_vol_00 silver ready
149             # silver_vol_01 silver ready
150             # silver_vol_02 silver ready
151             # ... etc.
152              
153             Returns an array of L objects representing all disks in the target system.
154              
155             =head3 get_exports
156              
157             # Print a listing of all configured exports containing the export name, the export path,
158             # the export protocol and the export status.
159              
160             printf( "%-20s%-40s%-10s%-10s\n",
161             'Name',
162             'Path',
163             'Protocol',
164             'Active'
165             );
166              
167             foreach my $export ( $ibm->get_exports ) {
168             print '-'x55,"\n";
169             printf( "%-20s%-20s%-10s%-10s\n",
170             $export->name,
171             $export->path,
172             $export->protocol,
173             $export->active
174             )
175             }
176              
177             # Prints something like:
178             #
179             #Name Path Protocol Active
180             # ------------------------------------------------------
181             # homes_root /ibm/fs1/homes NFS true
182             # ------------------------------------------------------
183             # shares_root /ibm/fs1/shares NFS true
184             # -------------------------------------------------------
185             # test /ibm/fs1/test CIFS true
186             # -------------------------------------------------------
187             # ... etc.
188              
189             Returns all configured exports on the target system as an array of L objects.
190              
191             =head3 filesystem( $filesystem_name )
192              
193             # Print the block size of file system 'fs1'
194              
195             print $ibm->filesystem(fs1)->block_size;
196            
197             # Get the file system 'fs2' as a IBM::StorageSystem::FileSystem object
198              
199             my $fs = $ibm->filesystem(fs2);
200              
201             # Print the mount point of this file system
202              
203             print "fs2 mount point: " . $fs->mount_point . "\n";
204              
205             # Call a function if inode usage on file system 'fs2' exceeds 90% of maximum allocation.
206             monitoring_alert(
207             'Inode allocation > 90% on '.$filesystem->device_name
208             )
209             if ( ( ( $fs->inodes / $fs->max_inodes ) * 100 ) > 90 );
210              
211             Returns the file system specified by the value of the named parameter as a L object.
212              
213             Note that this is a caching method and a cached object will be retrieved if one exists, If you require a
214             non-cached object, then please use the B method.
215              
216             =head3 get_filesystem( $filesystem_name )
217              
218             This is a non-caching functionally equivalent implementation of the B method. Use this method if
219             you require the file system information to be retrieved directly from the target system rather than cache.
220              
221             =head3 get_filesystems
222              
223             # Do the same for all file systems
224             map { monitoring_alert( 'Inode allocation > 90% on '.$_->device_name ) }
225             grep { ( ( ( $_->inodes / $_->max_inodes ) * 100 ) > 90 ) } $ibm->get_filesystems;
226              
227             Returns an array of L objects representing all configured file systems on the
228             target system.
229              
230             =head3 get_healths
231              
232             # Simple one-liner to print the sensor status and value for any error conditions.
233             map { print join ' -> ', ( $_->sensor, $_->value."\n" ) }
234             grep { $_->status =~ /ERROR/ } $ibm->get_healths;
235              
236             # e.g.
237             # CLUSTER -> Alert found in component cluster
238             # MDISK -> Alert found in component mdisk
239             # NODE -> Alert found in component node
240              
241             Returns an array of L objects representative of all health sensors on the target system.
242              
243             =head3 interface ( $id )
244              
245             # Get interface ethX0 on management node mgmt001st001 as an IBM::StorageSystem::Interface object
246              
247             my $interface = $ibm->node('mgmt001st001')->interface('ethX0');
248              
249             # Print the interface status
250              
251             print $interface->up_or_down;
252              
253             # Print the interface status
254              
255             print $interface->speed;
256              
257             # Alternately;
258              
259             print $ibm->interface('mgmt001st001:ethX0')->speed;
260              
261             Returns the interface identified by the value of the id parameter as an L object.
262              
263             The value of the id parameter must be a valid node and interface name separated by a colon.
264              
265             B that this method implements caching and a cached object will be returned shoudl one be present.
266             If you require a non-cached object then please use the B method.
267              
268             =head3 get_interface( $id )
269              
270             This is a functionally equivalent non-caching implementation of the B method.
271              
272             =head3 get_interfaces
273              
274             # Print a list of all interfaces, their status, speed and role
275            
276             foreach my $interface ( $ibm->get_interfaces ) {
277             print "Interface: " . $interface->interface . "\n";
278             print "\tStatus: " . $interface->up_or_down . "\n";
279             print "\tSpeed: " . $interface->speed . "\n";
280             print "\tRole: " . $interface->isubordinate_or_master
281             . "\n----------\n";
282             }
283            
284             # Prints somethign like
285             #
286             # Interface: ethX0
287             # Status: UP
288             # Speed: 2000
289             # Role: MASTER
290             # ----------
291             # Interface: ethXsl0_0
292             # Status: UP
293             # Speed: 1000
294             # Role: SLAVE
295             # ----------
296             # etc.
297              
298             Returns an array of L objects representing all interfaces on the target system.
299              
300             =head3 mount( $mount )
301              
302             # Print mount status of file system fs1
303              
304             print "Mount status: " . $ibm->mount(fs1) . "\n";
305              
306             # Print only those file system that are not mounted
307              
308             map { print $_->file_system . " is not mounted.\n" }
309             grep { $_->mount_status ne 'mounted' }
310             $ibm->get_mounts;
311              
312             Returns the mount identified by the mount parameter as a L object.
313              
314             B that this method implements caching and a cached object will be returned shoudl one be present.
315             If you require a non-cached object then please use the B method.
316              
317             =head3 get_mount( $mount )
318              
319             This is a functionally equivalent non-caching implementation of the B method.
320              
321             =head3 get_mounts
322              
323             This method returns an array of L objects representing all mounts on the target system.
324              
325             =head3 node( $node )
326              
327             # Get node mgmt001st001 as an IBM::StorageSystem::Node object
328              
329             my $node = $ibm->node( mgmt001st001 );
330            
331             # Print the node description
332              
333             print "Description: " . $node->description . "\n";
334              
335             # Prints something like: "Description: active management node"
336             # Or alternately;
337              
338             print "Description: " . $ibm->node( mgmt001st001 )->description . "\n";
339              
340              
341             Returns the node identified by the value of the node parameter as a L object.
342              
343             B that this method implements caching and that a cached object will be returned if one is available.
344             If you require a non-cached object, then please use the non-caching B method.
345              
346             =head3 get_node( $node )
347              
348             This is a functionally equivalent non-caching implementation of the B method.
349              
350             =head3 get_nodes
351              
352             # Print the GPFS and CTDB stati of all nodes
353              
354             foreach my $node ( $ibm->get_nodes ) {
355             print "GPFS status: " . $node->GPFS_status
356             . " - CTDB status: " . $node->CTDB_status . "\n"
357             }
358              
359             Returns an array of L objects representing all configured nodes on the target system.
360              
361             =head3 get_quotas
362              
363             # Call a function to send a quota warning email for any quotas where the current
364             # usage exceeds 85% of the quota usage hard limit.
365              
366             map { send_quota_warning_email( $_ ) }
367             grep { ( $_->used_usage / $_->HL_usage ) > 0.85 }
368             grep { $_->name ne 'root' }
369             grep { $_->type eq 'U' } $ibm->get_quotas;
370              
371             Returns all quotas defined on the target system as an array of L objects.
372              
373             =head3 replication( $eventlog_id )
374              
375             Returns the replication event identified by the eventlog_id parameter as an L object.
376              
377             B that this method implements caching and that a cached object will be returned if one is available.
378             If you require a non-cached object, then please use the non-caching B method.
379              
380             =head3 get_replication( $eventlog_id )
381              
382             This is a functionally equivalent non-caching implementation of the B method.
383              
384             =head3 get_replications
385              
386             use Date::Calc qw(date_to_Time Today_and_Now);
387              
388             # Generate an alert for any replication errors in the last six hours
389              
390             foreach my $task ( $ibm->get_replications ) {
391              
392             if ( $repl->status eq 'ERROR' and ( Date_to_Time( Today_and_Now )
393             - ( Date_to_Time( split /-| |\./, $repl->time ) ) ) > 21_600 ) {
394             alert( "Replication failure for filesystem " . $repl->filesystem
395             . " - log ID: " . $repl->log_id .
396             )
397             }
398              
399             }
400              
401             Returns all asynchornous replication tasks as an array of L objects.
402              
403             =head3 service( $service )
404              
405             # Print the enabled status of the NFS service
406              
407             print $ibm->service(NFS)->enabled;
408              
409             # Print the configured and enabled status of all services
410              
411             printf( "%-20s%-20s%-20s\n", 'Service', 'Configured', 'Active' );
412             map { printf( "%-20s%-20s%-20s\n", $_->name, $_->configured, $_->active ) } $ibm->get_services;
413              
414             Returns a L object representing the service identified by the value of the
415             service parameter.
416              
417             B that this method implements caching and that a cached object will be returned if one is available.
418             If you require a non-cached object, then please use the non-caching B method.
419              
420             =head3 get_service( $service )
421              
422             This is a functionally equivalent non-caching implementation of the B method.
423              
424             =head3 get_services
425              
426             Returns an array of L objects representing all configured services on the target
427             system.
428              
429             =head3 task( $task )
430              
431             # Print the status of the SNAPSHOTS task
432              
433             my $snapshots = $ibm->task(SNAPSHOTS);
434             print "Status: " . $snapshots->status . "\n";
435              
436             # Alternately
437              
438             print "Status: " . $ibm->task(SNAPSHOTS)->status . "\n";
439              
440             Return the task identified by the value of the task parameter as an L object.
441              
442             B that this method implements caching and that a cached object will be returned if one is available.
443             If you require a non-cached object, then please use the non-caching B method.
444              
445             =head3 get_task( $task )
446              
447             This is a functionally equivalent non-caching implementation of the B method.
448              
449             =head3 get_tasks
450              
451             # Call an alert function for any tasks that are not in an OK state
452              
453             map { alert( $_->name ) } grep { $_->status ne 'OK' } $ibm->get_tasks;
454              
455             Returns an array of L objects representing all tasks on the target system.
456              
457             =head1 AUTHOR
458              
459             Luke Poskitt, C<< >>
460              
461             =head1 BUGS
462              
463             Please report any bugs or feature requests to C, or through
464             the web interface at L. I will be notified, and then you'll
465             automatically be notified of progress on your bug as I make changes.
466              
467             =head1 SUPPORT
468              
469             You can find documentation for this module with the perldoc command.
470              
471             perldoc IBM::SONAS
472              
473              
474             You can also look for information at:
475              
476             =over 4
477              
478             =item * RT: CPAN's request tracker (report bugs here)
479              
480             L
481              
482             =item * AnnoCPAN: Annotated CPAN documentation
483              
484             L
485              
486             =item * CPAN Ratings
487              
488             L
489              
490             =item * Search CPAN
491              
492             L
493              
494             =back
495              
496              
497             =head1 ACKNOWLEDGEMENTS
498              
499              
500             =head1 LICENSE AND COPYRIGHT
501              
502             Copyright 2013 Luke Poskitt.
503              
504             This program is free software; you can redistribute it and/or modify it
505             under the terms of either: the GNU General Public License as published
506             by the Free Software Foundation; or the Artistic License.
507              
508             See http://dev.perl.org/licenses/ for more information.
509              
510              
511             =cut
512              
513             1; # End of IBM::SONAS