3333 use Data::Dumper;
3434}
3535
36+ # Conditionally call add_child_chain(): only if the first arg is defined
37+ # call it with all args and the first one appened at the end
38+ sub cond_add_child_chain {
39+ my $str = shift // return ;
40+ add_child_chain( @_ , $str );
41+ }
42+
43+ # Add the second argument as a child of the first, the third as a child
44+ # of the second, and so on. Add the last two args as a string to the last
45+ # child.
46+ sub add_child_chain {
47+ my $parent = shift ;
48+ while ( @_ > 2 ) {
49+ my $child = shift ;
50+ $parent -> child_add( $child );
51+ $parent = $child ;
52+ }
53+ $parent -> child_add_string( @_ );
54+ }
55+
3656# #############################################
3757# # DISK HEALTH
3858# #############################################
@@ -46,12 +66,7 @@ sub get_disk_info {
4666 my $strActiveTag = " " ;
4767 my %hshDiskInfo ;
4868
49- if (defined ($strVHost )) {
50- $nahDiskIterator -> child_add($nahQuery );
51- $nahQuery -> child_add($nahDiskInfo );
52- $nahDiskInfo -> child_add($nahDiskOwnerInfo );
53- $nahDiskOwnerInfo -> child_add_string(" home-node" , $strVHost );
54- }
69+ cond_add_child_chain( $strVHost , $nahDiskIterator , $nahQuery , $nahDiskInfo , $nahDiskOwnerInfo , " home-node" );
5570
5671 while (defined ($strActiveTag )) {
5772 if ($strActiveTag ne " " ) {
@@ -181,12 +196,7 @@ sub get_spare_info {
181196 my $strActiveTag = " " ;
182197 my %hshSpareInfo ;
183198
184- if (defined ($strVHost )) {
185- $nahSpareIterator -> child_add($nahQuery );
186- $nahQuery -> child_add($nahSpareInfo );
187- $nahSpareInfo -> child_add($nahSpareOwnerInfo );
188- $nahSpareOwnerInfo -> child_add_string(" home-node" , $strVHost );
189- }
199+ cond_add_child_chain( $strVHost , $nahSpareIterator , $nahQuery , $nahSpareInfo , $nahSpareOwnerInfo , " home-node" );
190200
191201 while (defined ($strActiveTag )) {
192202 if ($strActiveTag ne " " ) {
@@ -370,11 +380,7 @@ sub get_port_health {
370380 my $strActiveTag = " " ;
371381 my %hshPortInfo ;
372382
373- if (defined ($strVHost )) {
374- $nahPortIterator -> child_add($nahQuery );
375- $nahQuery -> child_add($nahPortInfo );
376- $nahPortInfo -> child_add_string(" node" , $strVHost );
377- }
383+ cond_add_child_chain( $strVHost , $nahPortIterator , $nahQuery , $nahPortInfo , " node" );
378384
379385 while (defined ($strActiveTag )) {
380386 if ($strActiveTag ne " " ) {
@@ -418,11 +424,7 @@ sub get_interface_health {
418424 my $strActiveTag = " " ;
419425 my %hshInterfaceInfo ;
420426
421- if (defined ($strVHost )) {
422- $nahIntIterator -> child_add($nahQuery );
423- $nahQuery -> child_add($nahIntInfo );
424- $nahIntInfo -> child_add_string(" vserver" , $strVHost );
425- }
427+ cond_add_child_chain( $strVHost , $nahIntIterator , $nahQuery , $nahIntInfo , " vserver" );
426428
427429 while (defined ($strActiveTag )) {
428430 if ($strActiveTag ne " " ) {
@@ -604,11 +606,7 @@ sub get_cluster_node_health {
604606 my $strActiveTag = " " ;
605607 my %hshClusterNodeInfo ;
606608
607- if (defined ($strVHost )) {
608- $nahClusterNodeIterator -> child_add($nahQuery );
609- $nahQuery -> child_add($nahClusterNodeInfo );
610- $nahClusterNodeInfo -> child_add_string(" originating-node" , $strVHost );
611- }
609+ cond_add_child_chain( $strVHost , $nahClusterNodeIterator , $nahQuery , $nahClusterNodeInfo , " originating-node" );
612610
613611 while (defined ($strActiveTag )) {
614612 if ($strActiveTag ne " " ) {
@@ -668,11 +666,7 @@ sub get_cluster_health {
668666 my $strActiveTag = " " ;
669667 my %hshClusterInfo ;
670668
671- if (defined ($strVHost )) {
672- $nahClusterIterator -> child_add($nahQuery );
673- $nahQuery -> child_add($nahClusterInfo );
674- $nahClusterInfo -> child_add_string(" originating-node" , $strVHost );
675- }
669+ cond_add_child_chain( $strVHost , $nahClusterIterator , $nahQuery , $nahClusterInfo , " originating-node" );
676670
677671 while (defined ($strActiveTag )) {
678672 if ($strActiveTag ne " " ) {
@@ -743,11 +737,7 @@ sub get_vscan_info {
743737 my $strActiveTag = " " ;
744738 my %hshVscanInfo ;
745739
746- if (defined ($strVHost )) {
747- $nahVscanIterator -> child_add($nahQuery );
748- $nahQuery -> child_add($nahVscanInfo );
749- $nahVscanInfo -> child_add_string(" vserver" , $strVHost );
750- }
740+ cond_add_child_chain( $strVHost , $nahVscanIterator , $nahQuery , $nahVscanInfo , " vserver" );
751741
752742 while (defined ($strActiveTag )) {
753743 if ($strActiveTag ne " " ) {
@@ -807,11 +797,7 @@ sub get_netapp_alarms {
807797 my $strActiveTag = " " ;
808798 my %hshAlarms ;
809799
810- if (defined ($strVHost )) {
811- $nahAlarmIterator -> child_add($nahQuery );
812- $nahQuery -> child_add($nahDashInfo );
813- $nahDashInfo -> child_add_string(" node" , $strVHost );
814- }
800+ cond_add_child_chain( $strVHost , $nahAlarmIterator , $nahQuery , $nahDashInfo , " node" );
815801
816802 while (defined ($strActiveTag )) {
817803 if ($strActiveTag ne " " ) {
@@ -909,11 +895,7 @@ sub get_filer_hardware {
909895 my $strActiveTag = " " ;
910896 my %hshFilerHardware ;
911897
912- if (defined ($strVHost )) {
913- $nahFilerIterator -> child_add($nahQuery );
914- $nahQuery -> child_add($nahNodeInfo );
915- $nahNodeInfo -> child_add_string(" node" , $strVHost );
916- }
898+ cond_add_child_chain( $strVHost , $nahFilerIterator , $nahQuery , $nahNodeInfo , " node" );
917899
918900 while (defined ($strActiveTag )) {
919901 if ($strActiveTag ne " " ) {
@@ -1090,11 +1072,7 @@ sub get_snapmirror_lag {
10901072 my %hshSMHealth ;
10911073
10921074 # Narrow search to only the requested node if configured by user with the -n option
1093- if (defined ($strVHost )) {
1094- $nahSMIterator -> child_add($nahQuery );
1095- $nahQuery -> child_add($nahSMInfo );
1096- $nahSMInfo -> child_add_string(" destination-volume-node" , $strVHost );
1097- }
1075+ cond_add_child_chain( $strVHost , $nahSMIterator , $nahQuery , $nahSMInfo , " destination-volume-node" );
10981076
10991077 # The active tag is a feature of the NetApp API that allows you to do queries in batches. In this case we are getting records in batches of 100.
11001078 $nahSMIterator -> child_add_string(" max-records" , 100);
@@ -1233,11 +1211,7 @@ sub get_quota_space {
12331211 my %hshQuotaUsage ;
12341212
12351213 # Narrow search to only the requested node if configured by user with the -n option
1236- if (defined ($strVHost )) {
1237- $nahQuotaIterator -> child_add($nahQuery );
1238- $nahQuery -> child_add($nahQuotaInfo );
1239- $nahQuotaInfo -> child_add_string(" vserver" , $strVHost );
1240- }
1214+ cond_add_child_chain( $strVHost , $nahQuotaIterator , $nahQuery , $nahQuotaInfo , " vserver" );
12411215
12421216 # The active tag is a feature of the NetApp API that allows you to do queries in batches. In this case we are getting records in batches of 100.
12431217 while (defined ($strActiveTag )) {
@@ -1364,12 +1338,7 @@ sub get_aggregate_space {
13641338 my %hshAggUsage ;
13651339
13661340 # Narrow search to only the requested node if configured by user with the -n option
1367- if (defined ($strVHost )) {
1368- $nahAggIterator -> child_add($nahQuery );
1369- $nahQuery -> child_add($nahAggInfo );
1370- $nahAggInfo -> child_add($nahAggIdInfo );
1371- $nahAggIdInfo -> child_add_string(" home-name" , $strVHost );
1372- }
1341+ cond_add_child_chain( $strVHost , $nahAggIterator , $nahQuery , $nahAggInfo , $nahAggIdInfo , " home-name" );
13731342
13741343 # The active tag is a feature of the NetApp API that allows you to do queries in batches. In this case we are getting records in batches of 100.
13751344 while (defined ($strActiveTag )) {
@@ -1437,12 +1406,7 @@ sub get_snap_space {
14371406 my %hshVolUsage ;
14381407
14391408 # Narrow search to only the requested node if configured by user with the -n option
1440- if (defined ($strVHost )) {
1441- $nahVolIterator -> child_add($nahQuery );
1442- $nahQuery -> child_add($nahVolInfo );
1443- $nahVolInfo -> child_add($nahVolIdInfo );
1444- $nahVolIdInfo -> child_add_string(" owning-vserver-name" , $strVHost );
1445- }
1409+ cond_add_child_chain( $strVHost , $nahVolIterator , $nahQuery , $nahVolInfo , $nahVolIdInfo , " owning-vserver-name" );
14461410
14471411 # The active tag is a feature of the NetApp API that allows you to do queries in batches. In this case we are getting records in batches of 100.
14481412 $nahVolIterator -> child_add_string(" max-records" , 100);
@@ -1520,12 +1484,7 @@ sub get_volume_space {
15201484 my %hshVolUsage ;
15211485
15221486 # Narrow search to only the requested node if configured by user with the -n option
1523- if (defined ($strVHost )) {
1524- $nahVolIterator -> child_add($nahQuery );
1525- $nahQuery -> child_add($nahVolInfo );
1526- $nahVolInfo -> child_add($nahVolIdInfo );
1527- $nahVolIdInfo -> child_add_string(" owning-vserver-name" , $strVHost );
1528- }
1487+ cond_add_child_chain( $strVHost , $nahVolIterator , $nahQuery , $nahVolInfo , $nahVolIdInfo , " owning-vserver-name" );
15291488
15301489 # The active tag is a feature of the NetApp API that allows you to do queries in batches. In this case we are getting records in batches of 100.
15311490 $nahVolIterator -> child_add_string(" max-records" , 100);
0 commit comments