From 28616fd6383e34bc52f8cc2effaeeadf93c29475 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 24 Jan 2020 14:17:20 +0100 Subject: [PATCH] update indent + fix bug with no result --- cloud/vmware/velocloud/restapi/custom/api.pm | 42 ++++++------ .../restapi/mode/applicationusage.pm | 34 +++------- .../velocloud/restapi/mode/categoryusage.pm | 34 +++------- .../vmware/velocloud/restapi/mode/edgeqoe.pm | 33 +++------ .../velocloud/restapi/mode/edgestatus.pm | 11 +-- .../velocloud/restapi/mode/linkstatus.pm | 21 +++--- .../velocloud/restapi/mode/linkusage.pm | 68 ++++++++++++------- .../velocloud/restapi/mode/listedges.pm | 22 +++--- .../velocloud/restapi/mode/listlinks.pm | 39 ++++++----- 9 files changed, 150 insertions(+), 154 deletions(-) diff --git a/cloud/vmware/velocloud/restapi/custom/api.pm b/cloud/vmware/velocloud/restapi/custom/api.pm index f9d93b893..f2d324272 100644 --- a/cloud/vmware/velocloud/restapi/custom/api.pm +++ b/cloud/vmware/velocloud/restapi/custom/api.pm @@ -39,18 +39,18 @@ sub new { $options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument."); $options{output}->option_exit(); } - + if (!defined($options{noptions})) { $options{options}->add_options(arguments => { - "hostname:s" => { name => 'hostname' }, - "port:s" => { name => 'port' }, - "proto:s" => { name => 'proto' }, - "username:s" => { name => 'username' }, - "password:s" => { name => 'password' }, - "operator-user" => { name => 'operator_user' }, - "api-path:s" => { name => 'api_path' }, - "timeframe:s" => { name => 'timeframe' }, - "timeout:s" => { name => 'timeout' }, + 'hostname:s' => { name => 'hostname' }, + 'port:s' => { name => 'port' }, + 'proto:s' => { name => 'proto' }, + 'username:s' => { name => 'username' }, + 'password:s' => { name => 'password' }, + 'operator-user' => { name => 'operator_user' }, + 'api-path:s' => { name => 'api_path' }, + 'timeframe:s' => { name => 'timeframe' }, + 'timeout:s' => { name => 'timeout' }, }); } $options{options}->add_help(package => __PACKAGE__, sections => 'REST API OPTIONS', once => 1); @@ -58,7 +58,7 @@ sub new { $self->{output} = $options{output}; $self->{mode} = $options{mode}; $self->{http} = centreon::plugins::http->new(%options); - + return $self; } @@ -94,7 +94,7 @@ sub check_options { $self->{password} = (defined($self->{option_results}->{password})) ? $self->{option_results}->{password} : undef; $self->{api_path} = (defined($self->{option_results}->{api_path})) ? $self->{option_results}->{api_path} : '/portal/rest'; $self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 10; - + if (!defined($self->{hostname}) || $self->{hostname} eq '') { $self->{output}->add_option_msg(short_msg => "Need to specify --hostname option."); $self->{output}->option_exit(); @@ -143,14 +143,14 @@ sub settings { sub get_session_cookie { my ($self, %options) = @_; - + my $form_post = { username => $self->{username}, password => $self->{password} }; my $encoded; eval { $encoded = JSON::XS->new->utf8->encode($form_post); }; if ($@) { - $self->{output}->add_option_msg(short_msg => "Cannot encode json request"); + $self->{output}->add_option_msg(short_msg => 'Cannot encode json request'); $self->{output}->option_exit(); } @@ -166,7 +166,7 @@ sub get_session_cookie { my $message = ''; my $session = ''; - + foreach my $cookie (@cookies) { $message = $1 if ($cookie =~ /^velocloud\.message=(.+?);/); $session = $1 if ($cookie =~ /^velocloud\.session=(.+?);/); @@ -176,7 +176,7 @@ sub get_session_cookie { $self->{output}->add_option_msg(short_msg => "Cannot get session cookie: " . $message); $self->{output}->option_exit(); } - + $self->{session_cookie} = $session; } @@ -188,7 +188,7 @@ sub get_entreprise_id { } $self->settings(); - + my $content = $self->{http}->request( method => 'POST', url_path => $self->{api_path} . '/enterprise/getEnterprise' @@ -202,7 +202,7 @@ sub get_entreprise_id { $self->{output}->add_option_msg(short_msg => "Cannot decode json response"); $self->{output}->option_exit(); } - + $self->{entreprise_id} = $decoded->{id}; } @@ -214,7 +214,7 @@ sub request_api { } $self->settings(); - + my $encoded_form_post; eval { $encoded_form_post = JSON::XS->new->utf8->encode($options{query_form_post}); @@ -257,13 +257,13 @@ sub list_edges { if (!defined($self->{entreprise_id})) { $self->get_entreprise_id(); } - + my $response = $self->request_api( method => 'POST', path => '/enterprise/getEnterpriseEdges', query_form_post => { enterpriseId => $self->{entreprise_id} } ); - + return $response; } diff --git a/cloud/vmware/velocloud/restapi/mode/applicationusage.pm b/cloud/vmware/velocloud/restapi/mode/applicationusage.pm index 48d56e201..22d9c7fb7 100644 --- a/cloud/vmware/velocloud/restapi/mode/applicationusage.pm +++ b/cloud/vmware/velocloud/restapi/mode/applicationusage.pm @@ -27,7 +27,7 @@ use warnings; sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ { name => 'edges', type => 3, cb_prefix_output => 'prefix_edge_output', cb_long_output => 'long_output', message_multiple => 'All edges applications usage are ok', indent_long_output => ' ', @@ -88,7 +88,7 @@ sub prefix_edge_output { sub prefix_app_output { my ($self, %options) = @_; - + return "Application '" . $options{instance_value}->{display} . "' [Id: " . $options{instance_value}->{id} . "] "; } @@ -102,14 +102,14 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - + $options{options}->add_options(arguments => { - "filter-edge-name:s" => { name => 'filter_edge_name' }, - "filter-application-name:s" => { name => 'filter_application_name' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '' }, + 'filter-edge-name:s' => { name => 'filter_edge_name' }, + 'filter-application-name:s' => { name => 'filter_application_name' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '' }, }); - + return $self; } @@ -125,10 +125,9 @@ sub check_options { sub manage_selection { my ($self, %options) = @_; - $self->{edges} = {}; - my $results = $options{custom}->list_edges; + $self->{edges} = {}; foreach my $edge (@{$results}) { if (defined($self->{option_results}->{filter_edge_name}) && $self->{option_results}->{filter_edge_name} ne '' && $edge->{name} !~ /$self->{option_results}->{filter_edge_name}/) { @@ -167,11 +166,6 @@ sub manage_selection { $self->{output}->add_option_msg(short_msg => "No edge found."); $self->{output}->option_exit(); } - foreach (keys %{$self->{edges}}) { - last if (defined($self->{edges}->{$_}->{apps})); - $self->{output}->add_option_msg(short_msg => "No applications found."); - $self->{output}->option_exit(); - } } 1; @@ -192,15 +186,9 @@ Filter edge by name (Can be a regexp). Filter application by name (Can be a regexp). -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> -Threshold warning. -Can be: 'traffic-in', 'traffic-out', -'packets-in', 'packets-out'. - -=item B<--critical-*> - -Threshold critical. +Thresholds. Can be: 'traffic-in', 'traffic-out', 'packets-in', 'packets-out'. diff --git a/cloud/vmware/velocloud/restapi/mode/categoryusage.pm b/cloud/vmware/velocloud/restapi/mode/categoryusage.pm index 4b369293e..e1ead2619 100644 --- a/cloud/vmware/velocloud/restapi/mode/categoryusage.pm +++ b/cloud/vmware/velocloud/restapi/mode/categoryusage.pm @@ -27,7 +27,7 @@ use warnings; sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ { name => 'edges', type => 3, cb_prefix_output => 'prefix_edge_output', cb_long_output => 'long_output', message_multiple => 'All edges categories usage are ok', indent_long_output => ' ', @@ -88,7 +88,7 @@ sub prefix_edge_output { sub prefix_category_output { my ($self, %options) = @_; - + return "Category '" . $options{instance_value}->{display} . "' [Id: " . $options{instance_value}->{id} . "] "; } @@ -102,14 +102,14 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - + $options{options}->add_options(arguments => { - "filter-edge-name:s" => { name => 'filter_edge_name' }, - "filter-category-name:s" => { name => 'filter_category_name' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '' }, + 'filter-edge-name:s' => { name => 'filter_edge_name' }, + 'filter-category-name:s' => { name => 'filter_category_name' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '' }, }); - + return $self; } @@ -125,10 +125,9 @@ sub check_options { sub manage_selection { my ($self, %options) = @_; - $self->{edges} = {}; - my $results = $options{custom}->list_edges; + $self->{edges} = {}; foreach my $edge (@{$results}) { if (defined($self->{option_results}->{filter_edge_name}) && $self->{option_results}->{filter_edge_name} ne '' && $edge->{name} !~ /$self->{option_results}->{filter_edge_name}/) { @@ -167,11 +166,6 @@ sub manage_selection { $self->{output}->add_option_msg(short_msg => "No edge found."); $self->{output}->option_exit(); } - foreach (keys %{$self->{edges}}) { - last if (defined($self->{edges}->{$_}->{categories})); - $self->{output}->add_option_msg(short_msg => "No category found."); - $self->{output}->option_exit(); - } } 1; @@ -192,15 +186,9 @@ Filter edge by name (Can be a regexp). Filter category by name (Can be a regexp). -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> -Threshold warning. -Can be: 'traffic-in', 'traffic-out', -'packets-in', 'packets-out'. - -=item B<--critical-*> - -Threshold critical. +Thresholds. Can be: 'traffic-in', 'traffic-out', 'packets-in', 'packets-out'. diff --git a/cloud/vmware/velocloud/restapi/mode/edgeqoe.pm b/cloud/vmware/velocloud/restapi/mode/edgeqoe.pm index e45de8540..0ba061381 100644 --- a/cloud/vmware/velocloud/restapi/mode/edgeqoe.pm +++ b/cloud/vmware/velocloud/restapi/mode/edgeqoe.pm @@ -27,7 +27,7 @@ use warnings; sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ { name => 'edges', type => 3, cb_prefix_output => 'prefix_edge_output', cb_long_output => 'long_output', message_multiple => 'All edges links QOE are ok', indent_long_output => ' ', @@ -68,6 +68,7 @@ sub set_counters { } }, ]; + $self->{maps_counters}->{links} = [ { label => 'qoe-voice', nlabel => 'link.qoe.voice.count', set => { key_values => [ { name => 'voice' }, { name => 'display' }, { name => 'id' } ], @@ -107,7 +108,7 @@ sub prefix_edge_output { sub prefix_link_output { my ($self, %options) = @_; - + return "Link '" . $options{instance_value}->{display} . "' [Id: " . $options{instance_value}->{id} . "] "; } @@ -123,8 +124,8 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "filter-edge-name:s" => { name => 'filter_edge_name' }, - "filter-link-name:s" => { name => 'filter_link_name' }, + "filter-edge-name:s' => { name => 'filter_edge_name' }, + "filter-link-name:s' => { name => 'filter_link_name' }, }); return $self; @@ -135,17 +136,15 @@ sub check_options { $self->SUPER::check_options(%options); $self->{timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900; - $self->change_macros(macros => ['warning_status', 'critical_status']); } sub manage_selection { my ($self, %options) = @_; - $self->{edges} = {}; - my $results = $options{custom}->list_edges; + $self->{edges} = {}; foreach my $edge (@{$results}) { if (defined($self->{option_results}->{filter_edge_name}) && $self->{option_results}->{filter_edge_name} ne '' && $edge->{name} !~ /$self->{option_results}->{filter_edge_name}/) { @@ -167,16 +166,16 @@ sub manage_selection { ); next if (ref($qoes) ne 'HASH'); - + $self->{edges}->{$edge->{name}}->{global} = { voice => $qoes->{overallLinkQuality}->{score}->{0}, video => $qoes->{overallLinkQuality}->{score}->{1}, transactional => $qoes->{overallLinkQuality}->{score}->{2}, }; - + foreach my $link (@{$links}) { next if (!defined($qoes->{$link->{link}->{internalId}})); - + if (defined($self->{option_results}->{filter_link_name}) && $self->{option_results}->{filter_link_name} ne '' && $link->{link}->{displayName} !~ /$self->{option_results}->{filter_link_name}/) { $self->{output}->output_add(long_msg => "skipping '" . $edge->{id} . "'.", debug => 1); @@ -197,11 +196,6 @@ sub manage_selection { $self->{output}->add_option_msg(short_msg => "No edge found."); $self->{output}->option_exit(); } - foreach (keys %{$self->{edges}}) { - last if (defined($self->{edges}->{$_}->{links})); - $self->{output}->add_option_msg(short_msg => "No link found."); - $self->{output}->option_exit(); - } } 1; @@ -222,14 +216,9 @@ Filter edge by name (Can be a regexp). Filter link by name (Can be a regexp). -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> -Threshold warning. -Can be: 'qoe-voice', 'qoe-video', 'qoe-transactional'. - -=item B<--critical-*> - -Threshold critical. +Thresholds. Can be: 'qoe-voice', 'qoe-video', 'qoe-transactional'. =back diff --git a/cloud/vmware/velocloud/restapi/mode/edgestatus.pm b/cloud/vmware/velocloud/restapi/mode/edgestatus.pm index 96cdb1a8f..c6fa7a1e1 100644 --- a/cloud/vmware/velocloud/restapi/mode/edgestatus.pm +++ b/cloud/vmware/velocloud/restapi/mode/edgestatus.pm @@ -29,11 +29,13 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold) sub custom_status_output { my ($self, %options) = @_; - return sprintf("State is '%s', Service State is '%s', HA State is '%s', Activation State is '%s'", + return sprintf( + "State is '%s', Service State is '%s', HA State is '%s', Activation State is '%s'", $self->{result_values}->{edge_state}, $self->{result_values}->{service_state}, $self->{result_values}->{ha_state}, - $self->{result_values}->{activation_state}); + $self->{result_values}->{activation_state} + ); } sub custom_status_calc { @@ -43,7 +45,7 @@ sub custom_status_calc { $self->{result_values}->{service_state} = $options{new_datas}->{$self->{instance} . '_service_state'}; $self->{result_values}->{ha_state} = $options{new_datas}->{$self->{instance} . '_ha_state'}; $self->{result_values}->{activation_state} = $options{new_datas}->{$self->{instance} . '_activation_state'}; - + return 0; } @@ -99,10 +101,9 @@ sub check_options { sub manage_selection { my ($self, %options) = @_; - $self->{edges} = {}; - my $results = $options{custom}->list_edges; + $self->{edges} = {}; foreach my $edge (@{$results}) { if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && $edge->{name} !~ /$self->{option_results}->{filter_name}/) { diff --git a/cloud/vmware/velocloud/restapi/mode/linkstatus.pm b/cloud/vmware/velocloud/restapi/mode/linkstatus.pm index 6df98294c..59f26f082 100644 --- a/cloud/vmware/velocloud/restapi/mode/linkstatus.pm +++ b/cloud/vmware/velocloud/restapi/mode/linkstatus.pm @@ -29,7 +29,8 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold sub custom_status_output { my ($self, %options) = @_; - return sprintf("status is '%s' [vpn state: '%s'] [backup state: '%s']", + return sprintf( + "status is '%s' [vpn state: '%s'] [backup state: '%s']", $self->{result_values}->{state}, $self->{result_values}->{vpn_state}, $self->{result_values}->{backup_state} @@ -86,11 +87,11 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "filter-edge-name:s" => { name => 'filter_edge_name' }, - "filter-link-name:s" => { name => 'filter_link_name' }, - "unknown-status:s" => { name => 'unknown_status', default => '' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '%{state} !~ /STABLE/ || %{vpn_state} !~ /STABLE/' }, + 'filter-edge-name:s' => { name => 'filter_edge_name' }, + 'filter-link-name:s' => { name => 'filter_link_name' }, + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{state} !~ /STABLE/ || %{vpn_state} !~ /STABLE/' }, }); return $self; @@ -108,10 +109,9 @@ sub check_options { sub manage_selection { my ($self, %options) = @_; - $self->{edges} = {}; - my $results = $options{custom}->list_edges; + $self->{edges} = {}; foreach my $edge (@{$results}) { if (defined($self->{option_results}->{filter_edge_name}) && $self->{option_results}->{filter_edge_name} ne '' && $edge->{name} !~ /$self->{option_results}->{filter_edge_name}/) { @@ -148,11 +148,6 @@ sub manage_selection { $self->{output}->add_option_msg(short_msg => "No edge found."); $self->{output}->option_exit(); } - foreach (keys %{$self->{edges}}) { - last if (defined($self->{edges}->{$_}->{links})); - $self->{output}->add_option_msg(short_msg => "No link found."); - $self->{output}->option_exit(); - } } 1; diff --git a/cloud/vmware/velocloud/restapi/mode/linkusage.pm b/cloud/vmware/velocloud/restapi/mode/linkusage.pm index 5ef54382d..e7274f071 100644 --- a/cloud/vmware/velocloud/restapi/mode/linkusage.pm +++ b/cloud/vmware/velocloud/restapi/mode/linkusage.pm @@ -32,12 +32,36 @@ sub set_counters { { name => 'edges', type => 3, cb_prefix_output => 'prefix_edge_output', cb_long_output => 'long_output', message_multiple => 'All edges links usage are ok', indent_long_output => ' ', group => [ + { name => 'global', cb_prefix_output => 'prefix_global_output', type => 0, skipped_code => { -10 => 1 } }, { name => 'links', display_long => 1, cb_prefix_output => 'prefix_link_output', message_multiple => 'All links status are ok', type => 1 }, ] } ]; + $self->{maps_counters}->{global} = [ + { label => 'links-traffic-in', nlabel => 'links.traffic.in.bitspersecond', set => { + key_values => [ { name => 'traffic_in' } ], + output_template => 'Total Traffic In: %s %s/s', + output_change_bytes => 2, + perfdatas => [ + { value => 'traffic_in_absolute', template => '%s', + min => 0, unit => 'b/s', label_extra_instance => 1 }, + ], + } + }, + { label => 'links-traffic-out', nlabel => 'links.traffic.out.bitspersecond', set => { + key_values => [ { name => 'traffic_out' } ], + output_template => 'Total Traffic Out: %s %s/s', + output_change_bytes => 2, + perfdatas => [ + { value => 'traffic_out_absolute', template => '%s', + min => 0, unit => 'b/s', label_extra_instance => 1 }, + ], + } + } + ]; + $self->{maps_counters}->{links} = [ { label => 'traffic-in', nlabel => 'link.traffic.in.bitspersecond', set => { key_values => [ { name => 'traffic_in' }, { name => 'display' }, { name => 'id' } ], @@ -140,8 +164,8 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "filter-edge-name:s" => { name => 'filter_edge_name' }, - "filter-link-name:s" => { name => 'filter_link_name' }, + 'filter-edge-name:s' => { name => 'filter_edge_name' }, + 'filter-link-name:s' => { name => 'filter_link_name' }, }); return $self; @@ -159,10 +183,9 @@ sub check_options { sub manage_selection { my ($self, %options) = @_; + my $results = $options{custom}->list_edges(); + $self->{edges} = {}; - - my $results = $options{custom}->list_edges; - foreach my $edge (@{$results}) { if (defined($self->{option_results}->{filter_edge_name}) && $self->{option_results}->{filter_edge_name} ne '' && $edge->{name} !~ /$self->{option_results}->{filter_edge_name}/) { @@ -170,8 +193,12 @@ sub manage_selection { next; } - $self->{edges}->{$edge->{name}}->{id} = $edge->{id}; - $self->{edges}->{$edge->{name}}->{display} = $edge->{name}; + $self->{edges}->{$edge->{name}} = { + id => $edge->{id}, + display => $edge->{name}, + global => {}, + links => {} + }; my $links = $options{custom}->get_links_metrics( edge_id => $edge->{id}, @@ -197,16 +224,17 @@ sub manage_selection { packet_loss_out => $link->{bestLossPctTx}, packet_loss_in => $link->{bestLossPctRx}, }; + if (!defined($self->{edges}->{$edge->{name}}->{global}->{traffic_in})) { + $self->{edges}->{$edge->{name}}->{global}->{traffic_in} = 0; + $self->{edges}->{$edge->{name}}->{global}->{traffic_out} = 0; + } + $self->{edges}->{$edge->{name}}->{global}->{traffic_in} += (int($link->{bytesRx} * 8 / $self->{timeframe})); + $self->{edges}->{$edge->{name}}->{global}->{traffic_out} += (int($link->{bytesTx} * 8 / $self->{timeframe})); } } if (scalar(keys %{$self->{edges}}) <= 0) { - $self->{output}->add_option_msg(short_msg => "No edge found."); - $self->{output}->option_exit(); - } - foreach (keys %{$self->{edges}}) { - last if (defined($self->{edges}->{$_}->{links})); - $self->{output}->add_option_msg(short_msg => "No link found."); + $self->{output}->add_option_msg(short_msg => 'no edge found.'); $self->{output}->option_exit(); } } @@ -229,17 +257,11 @@ Filter edge by name (Can be a regexp). Filter link by name (Can be a regexp). -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> -Threshold warning. -Can be: 'traffic-in', 'traffic-out', 'latency-in', -'latency-out', 'jitter-in', 'jitter-out', -'packet-loss-in', 'packet-loss-out'. - -=item B<--critical-*> - -Threshold critical. -Can be: 'traffic-in', 'traffic-out', 'latency-in', +Thresholds. +Can be: 'links-traffic-in', 'links-traffic-out', +'traffic-in', 'traffic-out', 'latency-in', 'latency-out', 'jitter-in', 'jitter-out', 'packet-loss-in', 'packet-loss-out'. diff --git a/cloud/vmware/velocloud/restapi/mode/listedges.pm b/cloud/vmware/velocloud/restapi/mode/listedges.pm index 41249236c..a6d513d17 100644 --- a/cloud/vmware/velocloud/restapi/mode/listedges.pm +++ b/cloud/vmware/velocloud/restapi/mode/listedges.pm @@ -29,7 +29,7 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - + $options{options}->add_options(arguments => {}); return $self; @@ -48,7 +48,7 @@ sub manage_selection { sub run { my ($self, %options) = @_; - + $self->manage_selection(%options); foreach my $edge (@{$self->{edges}}) { $self->{output}->output_add(long_msg => sprintf("[id = %s][name = %s][description = %s][edge_state = %s]" . @@ -56,18 +56,24 @@ sub run { $edge->{id}, $edge->{name}, $edge->{description}, $edge->{edgeState}, $edge->{serviceState}, $edge->{haState}, $edge->{activationState})); } - - $self->{output}->output_add(severity => 'OK', - short_msg => 'List edges:'); + + $self->{output}->output_add( + severity => 'OK', + short_msg => 'List edges:' + ); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } sub disco_format { my ($self, %options) = @_; - - $self->{output}->add_disco_format(elements => ['id', 'name', 'description', 'edge_state', 'service_state', - 'ha_state', 'activation_state']); + + $self->{output}->add_disco_format( + elements => [ + 'id', 'name', 'description', 'edge_state', 'service_state', + 'ha_state', 'activation_state' + ] + ); } sub disco_show { diff --git a/cloud/vmware/velocloud/restapi/mode/listlinks.pm b/cloud/vmware/velocloud/restapi/mode/listlinks.pm index a51046611..cf7e40797 100644 --- a/cloud/vmware/velocloud/restapi/mode/listlinks.pm +++ b/cloud/vmware/velocloud/restapi/mode/listlinks.pm @@ -29,9 +29,9 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - + $options{options}->add_options(arguments => { - "filter-edge-name:s" => { name => 'filter_edge_name' }, + 'filter-edge-name:s' => { name => 'filter_edge_name' }, }); return $self; @@ -44,9 +44,8 @@ sub check_options { sub manage_selection { my ($self, %options) = @_; - - my $edges = $options{custom}->list_edges; + my $edges = $options{custom}->list_edges; foreach my $edge (@{$edges}) { if (defined($self->{option_results}->{filter_edge_name}) && $self->{option_results}->{filter_edge_name} ne '' && $edge->{name} !~ /$self->{option_results}->{filter_edge_name}/) { @@ -62,26 +61,35 @@ sub manage_selection { sub run { my ($self, %options) = @_; - + $self->manage_selection(%options); foreach my $link (@{$self->{links}}) { - $self->{output}->output_add(long_msg => sprintf("[id = %s][display_name = %s][name = %s][edge_id = %s]" . - "[edge_name = %s][state = %s][vpn_state = %s]", - $link->{linkId}, $link->{link}->{displayName}, $link->{name}, $link->{link}->{edgeId}, - $link->{edgeName}, $link->{link}->{state}, $link->{link}->{vpnState})); + $self->{output}->output_add( + long_msg => sprintf( + "[id = %s][display_name = %s][name = %s][edge_id = %s]" . + "[edge_name = %s][state = %s][vpn_state = %s]", + $link->{linkId}, $link->{link}->{displayName}, $link->{name}, $link->{link}->{edgeId}, + $link->{edgeName}, $link->{link}->{state}, $link->{link}->{vpnState} + ) + ); } - - $self->{output}->output_add(severity => 'OK', - short_msg => 'List links:'); + + $self->{output}->output_add( + severity => 'OK', + short_msg => 'List links:' + ); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } sub disco_format { my ($self, %options) = @_; - - $self->{output}->add_disco_format(elements => ['id', 'display_name', 'name', 'edge_id', 'edge_name', 'state', - 'vpn_state']); + + $self->{output}->add_disco_format( + elements => [ + 'id', 'display_name', 'name', 'edge_id', 'edge_name', 'state', 'vpn_state' + ] + ); } sub disco_show { @@ -118,4 +126,3 @@ Filter edge by name (Can be a regexp). =back =cut -