add name for pnic vmware

This commit is contained in:
garnier-quentin 2020-04-06 10:47:50 +02:00
parent d991ad5bd9
commit ed3a7017de
1 changed files with 61 additions and 59 deletions

View File

@ -29,8 +29,7 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold)
sub custom_status_output { sub custom_status_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my $msg = 'status ' . $self->{result_values}->{status}; return 'status ' . $self->{result_values}->{status};
return $msg;
} }
sub custom_status_calc { sub custom_status_calc {
@ -43,8 +42,7 @@ sub custom_status_calc {
sub custom_linkstatus_output { sub custom_linkstatus_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my $msg = 'status ' . $self->{result_values}->{link_status}; return 'status ' . $self->{result_values}->{link_status};
return $msg;
} }
sub custom_linkstatus_calc { sub custom_linkstatus_calc {
@ -58,9 +56,10 @@ sub custom_traffic_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my ($value, $unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{traffic}, network => 1); my ($value, $unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{traffic}, network => 1);
my $msg = sprintf("traffic %s : %s/s (%.2f %%)", return sprintf(
$self->{result_values}->{label_ref}, $value . $unit, $self->{result_values}->{traffic_prct}); "traffic %s : %s/s (%.2f %%)",
return $msg; $self->{result_values}->{label_ref}, $value . $unit, $self->{result_values}->{traffic_prct}
);
} }
sub custom_traffic_calc { sub custom_traffic_calc {
@ -78,11 +77,12 @@ sub custom_traffic_calc {
sub custom_dropped_output { sub custom_dropped_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my $msg = sprintf("packets %s dropped : %.2f %% (%d/%d packets)", return sprintf(
$self->{result_values}->{label_ref}, 'packets %s dropped : %.2f %% (%d/%d packets)',
$self->{result_values}->{dropped_prct}, $self->{result_values}->{label_ref},
$self->{result_values}->{dropped}, $self->{result_values}->{packets}); $self->{result_values}->{dropped_prct},
return $msg; $self->{result_values}->{dropped}, $self->{result_values}->{packets}
);
} }
sub custom_dropped_calc { sub custom_dropped_calc {
@ -109,22 +109,22 @@ sub set_counters {
{ name => 'global', type => 0, skipped_code => { -10 => 1 } }, { name => 'global', type => 0, skipped_code => { -10 => 1 } },
{ name => 'global_host', 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 => '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} = [ $self->{maps_counters}->{global} = [
{ label => 'status', threshold => 0, set => { { label => 'status', threshold => 0, set => {
key_values => [ { name => 'state' } ], key_values => [ { name => 'state' } ],
closure_custom_calc => $self->can('custom_status_calc'), closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_output => $self->can('custom_status_output'), closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; }, 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} = [ $self->{maps_counters}->{global_host} = [
{ label => 'host-traffic-in', nlabel => 'host.traffic.in.bitsperseconds', set => { { label => 'host-traffic-in', nlabel => 'host.traffic.in.bitsperseconds', set => {
key_values => [ { name => 'traffic_in' } ], key_values => [ { name => 'traffic_in' } ],
@ -132,8 +132,8 @@ sub set_counters {
output_change_bytes => 2, output_change_bytes => 2,
perfdatas => [ perfdatas => [
{ label => 'host_traffic_in', value => 'traffic_in_absolute', template => '%s', { 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 => { { label => 'host-traffic-out', nlabel => 'host.traffic.out.bitsperseconds', set => {
@ -142,12 +142,12 @@ sub set_counters {
output_change_bytes => 2, output_change_bytes => 2,
perfdatas => [ perfdatas => [
{ label => 'host_traffic_out', value => 'traffic_out_absolute', template => '%s', { 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} = [ $self->{maps_counters}->{vswitch} = [
{ label => 'vswitch-traffic-in', nlabel => 'host.vswitch.traffic.in.bitsperseconds', set => { { label => 'vswitch-traffic-in', nlabel => 'host.vswitch.traffic.in.bitsperseconds', set => {
key_values => [ { name => 'traffic_in' } ], key_values => [ { name => 'traffic_in' } ],
@ -165,19 +165,19 @@ sub set_counters {
output_change_bytes => 2, output_change_bytes => 2,
perfdatas => [ perfdatas => [
{ label => 'vswitch_traffic_out', value => 'traffic_out_absolute', template => '%s', { 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} = [ $self->{maps_counters}->{pnic} = [
{ label => 'link-status', threshold => 0, set => { { 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_calc => $self->can('custom_linkstatus_calc'),
closure_custom_output => $self->can('custom_linkstatus_output'), closure_custom_output => $self->can('custom_linkstatus_output'),
closure_custom_perfdata => sub { return 0; }, 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 => { { label => 'link-traffic-in', nlabel => 'host.traffic.in.bitsperseconds', set => {
@ -187,8 +187,8 @@ sub set_counters {
threshold_use => 'traffic_prct', threshold_use => 'traffic_prct',
perfdatas => [ perfdatas => [
{ label => 'traffic_in', value => 'traffic', template => '%s', unit => 'b/s', { 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 => { { label => 'link-traffic-out', nlabel => 'host.traffic.out.bitsperseconds', set => {
@ -198,8 +198,8 @@ sub set_counters {
threshold_use => 'traffic_prct', threshold_use => 'traffic_prct',
perfdatas => [ perfdatas => [
{ label => 'traffic_out', value => 'traffic', template => '%s', unit => 'b/s', { 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 => { { label => 'link-dropped-in', nlabel => 'host.packets.in.dropped.percentage', set => {
@ -209,8 +209,8 @@ sub set_counters {
threshold_use => 'dropped_prct', threshold_use => 'dropped_prct',
perfdatas => [ perfdatas => [
{ label => 'packets_dropped_in', value => 'dropped_prct', template => '%s', unit => '%', { 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 => { { label => 'link-dropped-out', nlabel => 'host.packets.out.dropped.percentage', set => {
@ -220,10 +220,10 @@ sub set_counters {
threshold_use => 'dropped_prct', threshold_use => 'dropped_prct',
perfdatas => [ perfdatas => [
{ label => 'packets_dropped_out', value => 'dropped_prct', template => '%s', unit => '%', { 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; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
"esx-hostname:s" => { name => 'esx_hostname' }, 'esx-hostname:s' => { name => 'esx_hostname' },
"nic-name:s" => { name => 'nic_name' }, 'nic-name:s' => { name => 'nic_name' },
"filter" => { name => 'filter' }, 'filter' => { name => 'filter' },
"scope-datacenter:s" => { name => 'scope_datacenter' }, 'scope-datacenter:s' => { name => 'scope_datacenter' },
"scope-cluster:s" => { name => 'scope_cluster' }, 'scope-cluster:s' => { name => 'scope_cluster' },
"no-proxyswitch" => { name => 'no_proxyswitch' }, 'no-proxyswitch' => { name => 'no_proxyswitch' },
"unknown-status:s" => { name => 'unknown_status', default => '%{status} !~ /^connected$/i' }, 'unknown-status:s' => { name => 'unknown_status', default => '%{status} !~ /^connected$/i' },
"warning-status:s" => { name => 'warning_status', default => '' }, 'warning-status:s' => { name => 'warning_status', default => '' },
"critical-status:s" => { name => 'critical_status', default => '' }, 'critical-status:s' => { name => 'critical_status', default => '' },
"unknown-link-status:s" => { name => 'unknown_link_status', default => '' }, 'unknown-link-status:s' => { name => 'unknown_link_status', default => '' },
"warning-link-status:s" => { name => 'warning_link_status', default => '' }, 'warning-link-status:s' => { name => 'warning_link_status', default => '' },
"critical-link-status:s" => { name => 'critical_link_status', default => '%{link_status} !~ /up/' }, 'critical-link-status:s' => { name => 'critical_link_status', default => '%{link_status} !~ /up/' }
}); });
return $self; return $self;
} }
@ -278,8 +278,10 @@ sub check_options {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->SUPER::check_options(%options); $self->SUPER::check_options(%options);
$self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status', $self->change_macros(macros => [
'unknown_link_status', 'warning_link_status', 'critical_link_status']); 'unknown_status', 'warning_status', 'critical_status',
'unknown_link_status', 'warning_link_status', 'critical_link_status'
]);
} }
sub manage_selection { sub manage_selection {
@ -308,7 +310,7 @@ sub manage_selection {
$pnic_name !~ /$self->{option_results}->{nic_name}/); $pnic_name !~ /$self->{option_results}->{nic_name}/);
$self->{host}->{$host_name}->{pnic}->{$pnic_name} = { $self->{host}->{$host_name}->{pnic}->{$pnic_name} = {
display => $pnic_name, display => $pnic_name,
status => $response->{data}->{$host_id}->{pnic}->{$pnic_name}->{status} , status => $response->{data}->{$host_id}->{pnic}->{$pnic_name}->{status} ,
traffic_in => $response->{data}->{$host_id}->{pnic}->{$pnic_name}->{'net.received.average'}, traffic_in => $response->{data}->{$host_id}->{pnic}->{$pnic_name}->{'net.received.average'},
traffic_out => $response->{data}->{$host_id}->{pnic}->{$pnic_name}->{'net.transmitted.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> =item B<--unknown-link-status>
Set warning threshold for status (Default: ''). Set warning threshold for status.
Can used special variables like: %{link_status} Can used special variables like: %{link_status}, %{display}
=item B<--warning-link-status> =item B<--warning-link-status>
Set warning threshold for status (Default: ''). Set warning threshold for status.
Can used special variables like: %{link_status} Can used special variables like: %{link_status}, %{display}
=item B<--critical-link-status> =item B<--critical-link-status>
Set critical threshold for status (Default: '%{link_status} !~ /up/'). 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-*> =item B<--warning-*>