(plugin) cloud::nutanix::snmp - remove characters (#3905)

* (plugin) cloud::nutanix::snmp - remove characters

* (plugin) cloud::nutanix::snmp - remove characters
This commit is contained in:
qgarnier 2022-09-21 10:50:34 +02:00 committed by GitHub
parent 03204fb20a
commit 85287021d4
2 changed files with 21 additions and 22 deletions

View File

@ -49,7 +49,7 @@ sub prefix_disk_output {
my ($self, %options) = @_; my ($self, %options) = @_;
return sprintf( return sprintf(
"Disk '%s'", "Disk '%s' ",
$options{instance_value}->{display} $options{instance_value}->{display}
); );
} }
@ -57,11 +57,10 @@ sub prefix_disk_output {
sub custom_status_output { sub custom_status_output {
my ($self, %options) = @_; my ($self, %options) = @_;
return sprintf( return sprintf(
"state: '%s'", "state: '%s'",
$self->{result_values}->{state} $self->{result_values}->{state}
); );
} }
sub custom_status_calc { sub custom_status_calc {
@ -127,7 +126,7 @@ sub custom_usage_output {
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}); my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
return sprintf( return sprintf(
'Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)', 'usage total: %s used: %s (%.2f%%) free: %s (%.2f%%)',
$total_size_value . " " . $total_size_unit, $total_size_value . " " . $total_size_unit,
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free} $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}
@ -179,25 +178,25 @@ sub set_counters {
}, },
{ label => 'inodes', nlabel => 'disk.storage.inodes.usage.percentage', set => { { label => 'inodes', nlabel => 'disk.storage.inodes.usage.percentage', set => {
key_values => [ { name => 'inodes_used' }, { name => 'display' } ], key_values => [ { name => 'inodes_used' }, { name => 'display' } ],
output_template => 'Inodes Used : %s %%', output_template => 'inodes used: %s %%',
perfdatas => [ perfdatas => [
{ label => 'inodes', template => '%s', unit => '%', { label => 'inodes', template => '%s', unit => '%',
min => 0, label_extra_instance => 1 } min => 0, label_extra_instance => 1 }
] ]
} }
}, },
{ label => 'avg-latency', nlabel => 'disk.average.io.latency.microseconds', set => { { label => 'avg-latency', nlabel => 'disk.average.io.latency.milliseconds', set => {
key_values => [ { name => 'dstAverageLatency' } ], key_values => [ { name => 'dstAverageLatency' } ],
output_template => 'Average Latency : %s µs', output_template => 'average latency: %.3f ms',
perfdatas => [ perfdatas => [
{ label => 'avg_latency', template => '%s', unit => s', { label => 'avg_latency', template => '%.3f', unit => 'ms',
min => 0, label_extra_instance => 1 } min => 0, label_extra_instance => 1 }
] ]
} }
}, },
{ label => 'iops', nlabel => 'disk.operations.iops', set => { { label => 'iops', nlabel => 'disk.operations.iops', set => {
key_values => [ { name => 'dstNumberIops' }, { name => 'display' } ], key_values => [ { name => 'dstNumberIops' }, { name => 'display' } ],
output_template => 'IOPs : %s', output_template => 'IOPs: %s',
perfdatas => [ perfdatas => [
{ label => 'iops', template => '%s', unit => 'iops', { label => 'iops', template => '%s', unit => 'iops',
min => 0, label_extra_instance => 1 } min => 0, label_extra_instance => 1 }
@ -222,11 +221,6 @@ sub new {
return $self; return $self;
} }
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
}
my %map_state = (1 => 'online', 2 => 'offline'); my %map_state = (1 => 'online', 2 => 'offline');
my $disk_mapping = { my $disk_mapping = {
@ -269,19 +263,21 @@ sub manage_selection {
my $controllervm_instance = $1; my $controllervm_instance = $1;
my $controllervm_result = $options{snmp}->map_instance(mapping => $controllervm_mapping, results => $controllervm_snmp_result, instance => $controllervm_instance); my $controllervm_result = $options{snmp}->map_instance(mapping => $controllervm_mapping, results => $controllervm_snmp_result, instance => $controllervm_instance);
$controllervm_result->{crtName} = centreon::plugins::misc::trim($controllervm_result->{crtName});
if (defined($self->{option_results}->{filter_controllervm}) && $self->{option_results}->{filter_controllervm} ne '' && if (defined($self->{option_results}->{filter_controllervm}) && $self->{option_results}->{filter_controllervm} ne '' &&
$controllervm_result->{crtName} !~ /$self->{option_results}->{filter_controllervm}/) { $controllervm_result->{crtName} !~ /$self->{option_results}->{filter_controllervm}/) {
$self->{output}->output_add(long_msg => "skipping '" . $controllervm_result->{crtName} . "': no matching filter.", debug => 1); $self->{output}->output_add(long_msg => "skipping '" . $controllervm_result->{crtName} . "': no matching filter.", debug => 1);
next; next;
} }
$self->{controllervm}->{$controllervm_result->{crtName}} = { $self->{controllervm}->{ $controllervm_result->{crtName} } = {
id => $controllervm_result->{crtControllerVMId}, id => $controllervm_result->{crtControllerVMId},
name => $controllervm_result->{crtName}, name => $controllervm_result->{crtName},
disk => {} disk => {}
}; };
$controllervm_name_mapping->{$controllervm_result->{crtControllerVMId}} = $controllervm_result->{crtName}; $controllervm_name_mapping->{ $controllervm_result->{crtControllerVMId} } = $controllervm_result->{crtName};
} }
my $disk_snmp_result = $options{snmp}->get_table( my $disk_snmp_result = $options{snmp}->get_table(
@ -305,11 +301,13 @@ sub manage_selection {
} }
$disk_result->{dstDiskId} = centreon::plugins::misc::trim($disk_result->{dstDiskId}); $disk_result->{dstDiskId} = centreon::plugins::misc::trim($disk_result->{dstDiskId});
my $inodes_used; my $inodes_used;
$inodes_used = 100 - ($disk_result->{dstNumFreeInodes} * 100 / $disk_result->{dstNumTotalInodes}) if ($disk_result->{dstNumTotalInodes} > 0); $inodes_used = 100 - ($disk_result->{dstNumFreeInodes} * 100 / $disk_result->{dstNumTotalInodes}) if ($disk_result->{dstNumTotalInodes} > 0);
$self->{controllervm}->{$controllervm_name_mapping->{$disk_result->{dstControllerVMId}}}->{disk}->{$disk_result->{dstDiskId}} = { $disk_result->{dstAverageLatency} /= 1000;
$self->{controllervm}->{ $controllervm_name_mapping->{ $disk_result->{dstControllerVMId} } }->{disk}->{ $disk_result->{dstDiskId} } = {
name => $controllervm_name_mapping->{$disk_result->{dstControllerVMId}}, name => $controllervm_name_mapping->{$disk_result->{dstControllerVMId}},
display => $disk_result->{dstDiskId}, display => $disk_result->{dstDiskId},
%$disk_result, %$disk_result,

View File

@ -63,6 +63,7 @@ sub manage_selection {
return_type => 1, return_type => 1,
nothing_quit => 1 nothing_quit => 1
); );
$self->{disk} = {}; $self->{disk} = {};
foreach my $oid (keys %{$snmp_result}) { foreach my $oid (keys %{$snmp_result}) {
next if ($oid !~ /^$mapping->{dstState}->{oid}\.(.*)$/); next if ($oid !~ /^$mapping->{dstState}->{oid}\.(.*)$/);
@ -75,7 +76,7 @@ sub manage_selection {
next; next;
} }
$self->{disk}->{$result->{dstDiskId}} = { %{$result} }; $self->{disk}->{ $result->{dstDiskId} } = $result;
} }
} }