script/es-nodes.pl untested

filter: Statementstmt 0.0% 0 / 50 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 6 Podpod n/a totaltotal 0.0% 0 / 75 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/local/bin/perl
2 # PODNAME: es-nodes.pl
3 # ABSTRACT: Listing the nodes in a cluster with some details
4 use strict;
5 use warnings;
6  
7 use App::ElasticSearch::Utilities qw(es_request);
8 use CLI::Helpers qw(:output);
9 use Getopt::Long qw(:config no_ignore_case no_ignore_case_always);
10 use Pod::Usage;
11  
12 #------------------------------------------------------------------------#
13 # Argument Parsing
14 my %OPT;
15 GetOptions(\%OPT,
16 'attributes|attr=s',
17 'help|h',
18 'manual|m',
19 );
20  
21  
22 #------------------------------------------------------------------------#
23 # Documentation
24 pod2usage(1) if $OPT{help};
25 pod2usage(-exitval => 0, -verbose => 2) if $OPT{manual};
26  
27 my $cres = es_request('_cluster/health');
28 my $CLUSTER = defined $cres ? $cres->{cluster_name} : 'UNKNOWN';
29  
30 output({clear=>1,color=>'magenta'}, "Cluster [$CLUSTER] contains $cres->{number_of_nodes} nodes.", '-='x20);
31 # Get a list of nodes
32 my $nres = es_request('_cluster/state/master_node,nodes', {});
33 if(!defined $nres) {
34 output({stderr=>1,color=>'red'}, 'Fetching node status failed.');
35 exit 1;
36 }
37 debug_var($nres);
38 foreach my $uuid (sort { $nres->{nodes}{$a}->{name} cmp $nres->{nodes}{$b}->{name} } keys %{ $nres->{nodes} }) {
39 my $node = $nres->{nodes}{$uuid};
40 my $color = defined $nres->{master_node} && $uuid eq $nres->{master_node} ? 'green' : 'cyan';
41  
42 output({color=>$color}, $node->{name});
43 output({indent=>1,kv=>1,color=>$color}, address => $node->{transport_address});
44 verbose({indent=>1,kv=>1,color=>$color}, uuid => $uuid);
45 if( exists $OPT{attributes} ) {
46 output({indent=>1}, "attributes:");
47 foreach my $attr ( split /,/, $OPT{attributes} ) {
48 next unless exists $node->{attributes}{$attr};
49 output({indent=>2,kv=>1}, $attr => $node->{attributes}{$attr});
50 }
51 }
52 }
53  
54 __END__