(plugin) cloud::vmware::velocloud::restapi - fix empty return (#4476)

This commit is contained in:
qgarnier 2023-06-16 16:53:29 +02:00 committed by GitHub
parent cde60ceeb1
commit 17979bb7c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 100 additions and 84 deletions

View File

@ -25,6 +25,24 @@ use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
sub prefix_edge_output {
my ($self, %options) = @_;
return "Edge '" . $options{instance_value}->{display} . "' ";
}
sub prefix_app_output {
my ($self, %options) = @_;
return "Application '" . $options{instance_value}->{display} . "' [Id: " . $options{instance_value}->{id} . "] ";
}
sub long_output {
my ($self, %options) = @_;
return "Checking edge '" . $options{instance_value}->{display} . "' [Id: " . $options{instance_value}->{id} . "] ";
}
sub set_counters {
my ($self, %options) = @_;
@ -86,24 +104,6 @@ sub set_counters {
];
}
sub prefix_edge_output {
my ($self, %options) = @_;
return "Edge '" . $options{instance_value}->{display} . "' ";
}
sub prefix_app_output {
my ($self, %options) = @_;
return "Application '" . $options{instance_value}->{display} . "' [Id: " . $options{instance_value}->{id} . "] ";
}
sub long_output {
my ($self, %options) = @_;
return "Checking edge '" . $options{instance_value}->{display} . "' [Id: " . $options{instance_value}->{id} . "] ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
@ -137,8 +137,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 => { app_count => 0 },
apps => {}
};
my $apps = $options{custom}->get_apps_metrics(
edge_id => $edge->{id},
@ -158,8 +162,8 @@ sub manage_selection {
next;
}
$self->{edges}->{$edge->{name}}->{global}->{app_count}++;
$self->{edges}->{$edge->{name}}->{apps}->{ $app_name } = {
$self->{edges}->{ $edge->{name} }->{global}->{app_count}++;
$self->{edges}->{ $edge->{name} }->{apps}->{ $app_name } = {
id => $app->{application},
display => $app_name,
traffic_out => int($app->{bytesTx} * 8 / $self->{timeframe}),

View File

@ -25,6 +25,24 @@ use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
sub prefix_edge_output {
my ($self, %options) = @_;
return "Edge '" . $options{instance_value}->{display} . "' ";
}
sub prefix_category_output {
my ($self, %options) = @_;
return "Category '" . $options{instance_value}->{display} . "' [Id: " . $options{instance_value}->{id} . "] ";
}
sub long_output {
my ($self, %options) = @_;
return "Checking edge '" . $options{instance_value}->{display} . "' [Id: " . $options{instance_value}->{id} . "] ";
}
sub set_counters {
my ($self, %options) = @_;
@ -86,24 +104,6 @@ sub set_counters {
];
}
sub prefix_edge_output {
my ($self, %options) = @_;
return "Edge '" . $options{instance_value}->{display} . "' ";
}
sub prefix_category_output {
my ($self, %options) = @_;
return "Category '" . $options{instance_value}->{display} . "' [Id: " . $options{instance_value}->{id} . "] ";
}
sub long_output {
my ($self, %options) = @_;
return "Checking edge '" . $options{instance_value}->{display} . "' [Id: " . $options{instance_value}->{id} . "] ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
@ -137,8 +137,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 => { category_count => 0 },
categories => {}
};
my $categories = $options{custom}->get_categories_metrics(
edge_id => $edge->{id},
@ -153,14 +157,14 @@ sub manage_selection {
next;
}
$self->{edges}->{$edge->{name}}->{global}->{category_count}++;
$self->{edges}->{$edge->{name}}->{categories}->{$category->{name}} = {
$self->{edges}->{ $edge->{name} }->{global}->{category_count}++;
$self->{edges}->{ $edge->{name} }->{categories}->{$category->{name}} = {
id => $category->{category},
display => $category->{name},
traffic_out => int($category->{bytesTx} * 8 / $self->{timeframe}),
traffic_in => int($category->{bytesRx} * 8 / $self->{timeframe}),
packets_out => $category->{packetsTx} / $self->{timeframe},
packets_in => $category->{packetsRx} / $self->{timeframe},
packets_in => $category->{packetsRx} / $self->{timeframe}
};
}
}

View File

@ -25,6 +25,24 @@ use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
sub prefix_edge_output {
my ($self, %options) = @_;
return "Edge '" . $options{instance_value}->{display} . "' ";
}
sub prefix_link_output {
my ($self, %options) = @_;
return "Link '" . $options{instance_value}->{display} . "' [Id: " . $options{instance_value}->{id} . "] ";
}
sub long_output {
my ($self, %options) = @_;
return "Checking edge '" . $options{instance_value}->{display} . "' [Id: " . $options{instance_value}->{id} . "] ";
}
sub set_counters {
my ($self, %options) = @_;
@ -102,24 +120,6 @@ sub set_counters {
];
}
sub prefix_edge_output {
my ($self, %options) = @_;
return "Edge '" . $options{instance_value}->{display} . "' ";
}
sub prefix_link_output {
my ($self, %options) = @_;
return "Link '" . $options{instance_value}->{display} . "' [Id: " . $options{instance_value}->{id} . "] ";
}
sub long_output {
my ($self, %options) = @_;
return "Checking edge '" . $options{instance_value}->{display} . "' [Id: " . $options{instance_value}->{id} . "] ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
@ -146,15 +146,19 @@ sub manage_selection {
my $results = $options{custom}->list_edges();
$self->{edges} = {};
foreach my $edge (@{$results}) {
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}/) {
$self->{output}->output_add(long_msg => "skipping '" . $edge->{name} . "'.", debug => 1);
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 => { link_count => 0 },
links => {}
};
my $links = $options{custom}->list_links(
edge_id => $edge->{id},
@ -183,8 +187,8 @@ sub manage_selection {
next;
}
$self->{edges}->{$edge->{name}}->{global}->{link_count}++;
$self->{edges}->{$edge->{name}}->{links}->{$link->{link}->{displayName}} = {
$self->{edges}->{ $edge->{name} }->{global}->{link_count}++;
$self->{edges}->{ $edge->{name} }->{links}->{ $link->{link}->{displayName} } = {
id => $link->{linkId},
display => $link->{link}->{displayName},
voice => $qoes->{$link->{link}->{internalId}}->{score}->{0},
@ -226,4 +230,4 @@ Can be: 'edge-links-count', 'qoe-voice-global', 'qoe-video-global', 'qoe-transac
=back
=cut
=cut

View File

@ -96,7 +96,7 @@ sub manage_selection {
next;
}
$self->{edges}->{$edge->{id}} = {
$self->{edges}->{ $edge->{id} } = {
display => $edge->{name},
edge_state => $edge->{edgeState},
service_state => $edge->{serviceState},

View File

@ -129,8 +129,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 => { link_count => 0 },
links => {}
};
my $links = $options{custom}->get_links_metrics(
edge_id => $edge->{id},
@ -144,8 +148,8 @@ sub manage_selection {
next;
}
$self->{edges}->{$edge->{name}}->{global}->{link_count}++;
$self->{edges}->{$edge->{name}}->{links}->{$link->{link}->{displayName}} = {
$self->{edges}->{ $edge->{name} }->{global}->{link_count}++;
$self->{edges}->{ $edge->{name} }->{links}->{ $link->{link}->{displayName} } = {
id => $link->{linkId},
display => $link->{link}->{displayName},
state => $link->{link}->{state},

View File

@ -189,10 +189,10 @@ sub manage_selection {
next;
}
$self->{edges}->{$edge->{name}} = {
$self->{edges}->{ $edge->{name} } = {
id => $edge->{id},
display => $edge->{name},
global => {},
global => { link_count => 0, traffic_in => 0, traffic_out => 0 },
links => {}
};
@ -208,8 +208,8 @@ sub manage_selection {
next;
}
$self->{edges}->{$edge->{name}}->{global}->{link_count}++;
$self->{edges}->{$edge->{name}}->{links}->{$link->{link}->{displayName}} = {
$self->{edges}->{ $edge->{name} }->{global}->{link_count}++;
$self->{edges}->{ $edge->{name} }->{links}->{$link->{link}->{displayName}} = {
id => $link->{linkId},
display => $link->{link}->{displayName},
traffic_out => int($link->{bytesTx} * 8 / $self->{timeframe}),
@ -221,12 +221,12 @@ 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;
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}));
$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}));
}
}