Skip to content
This repository was archived by the owner on Oct 9, 2023. It is now read-only.

Commit 85e4463

Browse files
fix error in logs from net-host
1 parent 9344828 commit 85e4463

2 files changed

Lines changed: 35 additions & 31 deletions

File tree

centreon/vmware/cmdnethost.pm

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,20 @@ sub new {
2828
my ($class, %options) = @_;
2929
my $self = $class->SUPER::new(%options);
3030
bless $self, $class;
31-
31+
3232
$self->{commandName} = 'nethost';
33-
33+
3434
return $self;
3535
}
3636

3737
sub checkArgs {
3838
my ($self, %options) = @_;
3939

40-
if (defined($options{arguments}->{esx_hostname}) && $options{arguments}->{esx_hostname} eq "") {
41-
centreon::vmware::common::set_response(code => 100, short_message => "Argument error: esx hostname cannot be null");
40+
if (defined($options{arguments}->{esx_hostname}) && $options{arguments}->{esx_hostname} eq '') {
41+
centreon::vmware::common::set_response(code => 100, short_message => 'Argument error: esx hostname cannot be null');
4242
return 1;
4343
}
44-
44+
4545
return 0;
4646
}
4747

@@ -61,7 +61,7 @@ sub run {
6161
}
6262
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'HostSystem', properties => \@properties, filter => $filters);
6363
return if (!defined($result));
64-
64+
6565
my $data = {};
6666
my $pnic_def_up = {};
6767
my $query_perfs = [];
@@ -73,7 +73,7 @@ sub run {
7373

7474
$pnic_def_up->{$entity_value} = {};
7575
my $instances = [];
76-
76+
7777
# Get Name from vswitch
7878
if (defined($entity_view->{'config.network.vswitch'})) {
7979
foreach (@{$entity_view->{'config.network.vswitch'}}) {
@@ -85,15 +85,16 @@ sub run {
8585
# Get Name from proxySwitch
8686
if (defined($entity_view->{'config.network.proxySwitch'})) {
8787
foreach (@{$entity_view->{'config.network.proxySwitch'}}) {
88-
$data->{$entity_value}->{proxyswitch}->{$_->{name}} = { pnic => [] };
88+
my $name = defined($_->{name}) ? $_->{name} : $_->{key};
89+
$data->{$entity_value}->{proxyswitch}->{$name} = { pnic => [] };
8990
next if (!defined($_->{pnic}));
90-
push @{$data->{$entity_value}->{proxyswitch}->{$_->{name}}->{pnic}}, @{$_->{pnic}};
91+
push @{$data->{$entity_value}->{proxyswitch}->{$name}->{pnic}}, @{$_->{pnic}};
9192
}
9293
}
9394

9495
foreach (@{$entity_view->{'config.network.pnic'}}) {
9596
$data->{$entity_value}->{pnic}->{$_->device} = { speed => undef, status => 'down', key => $_->{key} };
96-
97+
9798
$number_nic++;
9899
if (defined($_->linkSpeed)) {
99100
$data->{$entity_value}->{pnic}->{$_->device}->{speed} = $_->linkSpeed->speedMb;
@@ -105,29 +106,31 @@ sub run {
105106
}
106107

107108
push @$query_perfs, {
108-
entity => $entity_view,
109-
metrics => [
110-
{label => 'net.received.average', instances => $instances},
111-
{label => 'net.transmitted.average', instances => $instances},
112-
{label => 'net.droppedRx.summation', instances => $instances},
113-
{label => 'net.droppedTx.summation', instances => $instances},
114-
{label => 'net.packetsRx.summation', instances => $instances},
115-
{label => 'net.packetsTx.summation', instances => $instances}
116-
]
117-
};
109+
entity => $entity_view,
110+
metrics => [
111+
{label => 'net.received.average', instances => $instances},
112+
{label => 'net.transmitted.average', instances => $instances},
113+
{label => 'net.droppedRx.summation', instances => $instances},
114+
{label => 'net.droppedTx.summation', instances => $instances},
115+
{label => 'net.packetsRx.summation', instances => $instances},
116+
{label => 'net.packetsTx.summation', instances => $instances}
117+
]
118+
};
118119
}
119-
120+
120121
# Nothing to retrieve. problem before already.
121122
return if (scalar(@$query_perfs) == 0);
122-
123-
my $values = centreon::vmware::common::generic_performance_values_historic($self->{connector},
124-
undef,
125-
$query_perfs,
126-
$self->{connector}->{perfcounter_speriod},
127-
sampling_period => $self->{sampling_period}, time_shift => $self->{time_shift},
128-
skip_undef_counter => 1, multiples => 1, multiples_result_by_entity => 1);
123+
124+
my $values = centreon::vmware::common::generic_performance_values_historic(
125+
$self->{connector},
126+
undef,
127+
$query_perfs,
128+
$self->{connector}->{perfcounter_speriod},
129+
sampling_period => $self->{sampling_period}, time_shift => $self->{time_shift},
130+
skip_undef_counter => 1, multiples => 1, multiples_result_by_entity => 1
131+
);
129132
return if (centreon::vmware::common::performance_errors($self->{connector}, $values) == 1);
130-
133+
131134
foreach my $entity_view (@$result) {
132135
my $entity_value = $entity_view->{mo_ref}->{value};
133136

@@ -139,7 +142,7 @@ sub run {
139142
my $packets_out = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'net.packetsTx.summation'}->{key} . ":" . $_}));
140143
my $dropped_in = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'net.droppedRx.summation'}->{key} . ":" . $_}));
141144
my $dropped_out = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'net.droppedTx.summation'}->{key} . ":" . $_}));
142-
145+
143146
$data->{$entity_value}->{pnic}->{$_}->{'net.received.average'} = $traffic_in;
144147
$data->{$entity_value}->{pnic}->{$_}->{'net.transmitted.average'} = $traffic_out;
145148
$data->{$entity_value}->{pnic}->{$_}->{'net.packetsRx.summation'} = $packets_in;
@@ -148,7 +151,7 @@ sub run {
148151
$data->{$entity_value}->{pnic}->{$_}->{'net.droppedTx.summation'} = $dropped_out;
149152
}
150153
}
151-
154+
152155
centreon::vmware::common::set_response(data => $data);
153156
}
154157

changelog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
2020-04-06 Quentin Garnier <qgarnier@centreon.com> - 3.1.2
22
* Enhancement: add drs and das config enable 'cluster-status'
3+
* Fix: remove errors in logs 'net-host'
34

45
2020-02-20 Quentin Garnier <qgarnier@centreon.com> - 3.1.1
56
* Fix: discovery folders management

0 commit comments

Comments
 (0)