From ed3a7017de1a243d8e198c094cdbf6bd0e3511ba Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 6 Apr 2020 10:47:50 +0200 Subject: [PATCH] add name for pnic vmware --- apps/vmware/connector/mode/nethost.pm | 120 +++++++++++++------------- 1 file changed, 61 insertions(+), 59 deletions(-) diff --git a/apps/vmware/connector/mode/nethost.pm b/apps/vmware/connector/mode/nethost.pm index 94f6acb9b..05488e026 100644 --- a/apps/vmware/connector/mode/nethost.pm +++ b/apps/vmware/connector/mode/nethost.pm @@ -29,8 +29,7 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold) sub custom_status_output { my ($self, %options) = @_; - my $msg = 'status ' . $self->{result_values}->{status}; - return $msg; + return 'status ' . $self->{result_values}->{status}; } sub custom_status_calc { @@ -43,8 +42,7 @@ sub custom_status_calc { sub custom_linkstatus_output { my ($self, %options) = @_; - my $msg = 'status ' . $self->{result_values}->{link_status}; - return $msg; + return 'status ' . $self->{result_values}->{link_status}; } sub custom_linkstatus_calc { @@ -58,9 +56,10 @@ sub custom_traffic_output { my ($self, %options) = @_; my ($value, $unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{traffic}, network => 1); - my $msg = sprintf("traffic %s : %s/s (%.2f %%)", - $self->{result_values}->{label_ref}, $value . $unit, $self->{result_values}->{traffic_prct}); - return $msg; + return sprintf( + "traffic %s : %s/s (%.2f %%)", + $self->{result_values}->{label_ref}, $value . $unit, $self->{result_values}->{traffic_prct} + ); } sub custom_traffic_calc { @@ -78,11 +77,12 @@ sub custom_traffic_calc { sub custom_dropped_output { my ($self, %options) = @_; - my $msg = sprintf("packets %s dropped : %.2f %% (%d/%d packets)", - $self->{result_values}->{label_ref}, - $self->{result_values}->{dropped_prct}, - $self->{result_values}->{dropped}, $self->{result_values}->{packets}); - return $msg; + return sprintf( + 'packets %s dropped : %.2f %% (%d/%d packets)', + $self->{result_values}->{label_ref}, + $self->{result_values}->{dropped_prct}, + $self->{result_values}->{dropped}, $self->{result_values}->{packets} + ); } sub custom_dropped_calc { @@ -109,22 +109,22 @@ sub set_counters { { name => 'global', type => 0, skipped_code => { -10 => 1 } }, { name => 'global_host', type => 0, skipped_code => { -10 => 1 } }, { name => 'pnic', cb_prefix_output => 'prefix_pnic_output', message_multiple => 'All physical interfaces are ok', type => 1, skipped_code => { -10 => 1 } }, - { name => 'vswitch', cb_prefix_output => 'prefix_vswitch_output', message_multiple => 'All vswitchs are ok', type => 1, skipped_code => { -10 => 1 } }, + { name => 'vswitch', cb_prefix_output => 'prefix_vswitch_output', message_multiple => 'All vswitchs are ok', type => 1, skipped_code => { -10 => 1 } } ] } ]; - + $self->{maps_counters}->{global} = [ { label => 'status', threshold => 0, set => { key_values => [ { name => 'state' } ], closure_custom_calc => $self->can('custom_status_calc'), closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold } - }, + } ]; - + $self->{maps_counters}->{global_host} = [ { label => 'host-traffic-in', nlabel => 'host.traffic.in.bitsperseconds', set => { key_values => [ { name => 'traffic_in' } ], @@ -132,8 +132,8 @@ sub set_counters { output_change_bytes => 2, perfdatas => [ { label => 'host_traffic_in', value => 'traffic_in_absolute', template => '%s', - unit => 'b/s', min => 0, label_extra_instance => 1 }, - ], + unit => 'b/s', min => 0, label_extra_instance => 1 } + ] } }, { label => 'host-traffic-out', nlabel => 'host.traffic.out.bitsperseconds', set => { @@ -142,12 +142,12 @@ sub set_counters { output_change_bytes => 2, perfdatas => [ { label => 'host_traffic_out', value => 'traffic_out_absolute', template => '%s', - unit => 'b/s', min => 0, label_extra_instance => 1 }, - ], + unit => 'b/s', min => 0, label_extra_instance => 1 } + ] } - }, + } ]; - + $self->{maps_counters}->{vswitch} = [ { label => 'vswitch-traffic-in', nlabel => 'host.vswitch.traffic.in.bitsperseconds', set => { key_values => [ { name => 'traffic_in' } ], @@ -165,19 +165,19 @@ sub set_counters { output_change_bytes => 2, perfdatas => [ { label => 'vswitch_traffic_out', value => 'traffic_out_absolute', template => '%s', - unit => 'b/s', min => 0, label_extra_instance => 1 }, - ], + unit => 'b/s', min => 0, label_extra_instance => 1 } + ] } - }, + } ]; - + $self->{maps_counters}->{pnic} = [ { label => 'link-status', threshold => 0, set => { - key_values => [ { name => 'status' } ], + key_values => [ { name => 'status' }, { name => 'display' } ], closure_custom_calc => $self->can('custom_linkstatus_calc'), closure_custom_output => $self->can('custom_linkstatus_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold } }, { label => 'link-traffic-in', nlabel => 'host.traffic.in.bitsperseconds', set => { @@ -187,8 +187,8 @@ sub set_counters { threshold_use => 'traffic_prct', perfdatas => [ { label => 'traffic_in', value => 'traffic', template => '%s', unit => 'b/s', - min => 0, max => 'speed', threshold_total => 'speed', cast_int => 1, label_extra_instance => 1 }, - ], + min => 0, max => 'speed', threshold_total => 'speed', cast_int => 1, label_extra_instance => 1 } + ] } }, { label => 'link-traffic-out', nlabel => 'host.traffic.out.bitsperseconds', set => { @@ -198,8 +198,8 @@ sub set_counters { threshold_use => 'traffic_prct', perfdatas => [ { label => 'traffic_out', value => 'traffic', template => '%s', unit => 'b/s', - min => 0, max => 'speed', threshold_total => 'speed', cast_int => 1, label_extra_instance => 1 }, - ], + min => 0, max => 'speed', threshold_total => 'speed', cast_int => 1, label_extra_instance => 1 } + ] } }, { label => 'link-dropped-in', nlabel => 'host.packets.in.dropped.percentage', set => { @@ -209,8 +209,8 @@ sub set_counters { threshold_use => 'dropped_prct', perfdatas => [ { label => 'packets_dropped_in', value => 'dropped_prct', template => '%s', unit => '%', - min => 0, max => 100, label_extra_instance => 1 }, - ], + min => 0, max => 100, label_extra_instance => 1 } + ] } }, { label => 'link-dropped-out', nlabel => 'host.packets.out.dropped.percentage', set => { @@ -220,10 +220,10 @@ sub set_counters { threshold_use => 'dropped_prct', perfdatas => [ { label => 'packets_dropped_out', value => 'dropped_prct', template => '%s', unit => '%', - min => 0, max => 100, label_extra_instance => 1 }, - ], + min => 0, max => 100, label_extra_instance => 1 } + ] } - }, + } ]; } @@ -257,20 +257,20 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "esx-hostname:s" => { name => 'esx_hostname' }, - "nic-name:s" => { name => 'nic_name' }, - "filter" => { name => 'filter' }, - "scope-datacenter:s" => { name => 'scope_datacenter' }, - "scope-cluster:s" => { name => 'scope_cluster' }, - "no-proxyswitch" => { name => 'no_proxyswitch' }, - "unknown-status:s" => { name => 'unknown_status', default => '%{status} !~ /^connected$/i' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '' }, - "unknown-link-status:s" => { name => 'unknown_link_status', default => '' }, - "warning-link-status:s" => { name => 'warning_link_status', default => '' }, - "critical-link-status:s" => { name => 'critical_link_status', default => '%{link_status} !~ /up/' }, + 'esx-hostname:s' => { name => 'esx_hostname' }, + 'nic-name:s' => { name => 'nic_name' }, + 'filter' => { name => 'filter' }, + 'scope-datacenter:s' => { name => 'scope_datacenter' }, + 'scope-cluster:s' => { name => 'scope_cluster' }, + 'no-proxyswitch' => { name => 'no_proxyswitch' }, + 'unknown-status:s' => { name => 'unknown_status', default => '%{status} !~ /^connected$/i' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '' }, + 'unknown-link-status:s' => { name => 'unknown_link_status', default => '' }, + 'warning-link-status:s' => { name => 'warning_link_status', default => '' }, + 'critical-link-status:s' => { name => 'critical_link_status', default => '%{link_status} !~ /up/' } }); - + return $self; } @@ -278,8 +278,10 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status', - 'unknown_link_status', 'warning_link_status', 'critical_link_status']); + $self->change_macros(macros => [ + 'unknown_status', 'warning_status', 'critical_status', + 'unknown_link_status', 'warning_link_status', 'critical_link_status' + ]); } sub manage_selection { @@ -308,7 +310,7 @@ sub manage_selection { $pnic_name !~ /$self->{option_results}->{nic_name}/); $self->{host}->{$host_name}->{pnic}->{$pnic_name} = { - display => $pnic_name, + display => $pnic_name, status => $response->{data}->{$host_id}->{pnic}->{$pnic_name}->{status} , traffic_in => $response->{data}->{$host_id}->{pnic}->{$pnic_name}->{'net.received.average'}, traffic_out => $response->{data}->{$host_id}->{pnic}->{$pnic_name}->{'net.transmitted.average'}, @@ -392,18 +394,18 @@ Can used special variables like: %{status} =item B<--unknown-link-status> -Set warning threshold for status (Default: ''). -Can used special variables like: %{link_status} +Set warning threshold for status. +Can used special variables like: %{link_status}, %{display} =item B<--warning-link-status> -Set warning threshold for status (Default: ''). -Can used special variables like: %{link_status} +Set warning threshold for status. +Can used special variables like: %{link_status}, %{display} =item B<--critical-link-status> Set critical threshold for status (Default: '%{link_status} !~ /up/'). -Can used special variables like: %{link_status} +Can used special variables like: %{link_status}, %{display} =item B<--warning-*>