diff --git a/centreon-plugins/cloud/nutanix/snmp/mode/clusterusage.pm b/centreon-plugins/cloud/nutanix/snmp/mode/clusterusage.pm index b8d906066..9db7dad4c 100644 --- a/centreon-plugins/cloud/nutanix/snmp/mode/clusterusage.pm +++ b/centreon-plugins/cloud/nutanix/snmp/mode/clusterusage.pm @@ -31,14 +31,13 @@ my $cluster_name = ''; 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 { my ($self, %options) = @_; - + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_clusterStatus'}; $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; return 0; @@ -59,11 +58,13 @@ sub custom_usage_perfdata { $total_options{cast_int} = 1; } - $self->{output}->perfdata_add(label => $label, unit => 'B', - value => $value_perf, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options), - min => 0, max => $self->{result_values}->{total}); + $self->{output}->perfdata_add( + label => $label, unit => 'B', + value => $value_perf, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options), + min => 0, max => $self->{result_values}->{total} + ); } sub custom_usage_threshold { @@ -86,11 +87,12 @@ sub custom_usage_output { my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); 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 $msg = sprintf("Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", - $total_size_value . " " . $total_size_unit, - $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, - $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}); - return $msg; + return sprintf( + 'Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)', + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free} + ); } sub custom_usage_calc { @@ -102,17 +104,16 @@ sub custom_usage_calc { $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used}; $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total}; $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used}; - return 0; } sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ { name => 'cluster', type => 0, cb_prefix_output => 'prefix_cluster_output', skipped_code => { -10 => 1 } }, ]; - + $self->{maps_counters}->{cluster} = [ { label => 'status', threshold => 0, set => { key_values => [ { name => 'clusterStatus' } ], @@ -155,15 +156,14 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '' }, - "units:s" => { name => 'units', default => '%' }, - "free" => { name => 'free' }, - }); - + + $options{options}->add_options(arguments => { + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '' }, + 'units:s' => { name => 'units', default => '%' }, + 'free' => { name => 'free' }, + }); + return $self; } @@ -176,7 +176,7 @@ sub check_options { sub prefix_cluster_output { my ($self, %options) = @_; - + return "Cluster '" . $cluster_name . "' "; } @@ -197,10 +197,12 @@ sub manage_selection { $self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3."); $self->{output}->option_exit(); } - - my $snmp_result = $options{snmp}->get_table(oid => $oid_nutanix, + + my $snmp_result = $options{snmp}->get_table( + oid => $oid_nutanix, start => $mapping->{clusterName}->{oid}, end => $mapping->{clusterLatency}->{oid}, - nothing_quit => 1); + nothing_quit => 1 + ); my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => '0'); $self->{cluster} = { %$result }; $cluster_name = centreon::plugins::misc::trim($result->{clusterName}); diff --git a/centreon-plugins/cloud/nutanix/snmp/mode/containerusage.pm b/centreon-plugins/cloud/nutanix/snmp/mode/containerusage.pm index 381118f15..c52cdacac 100644 --- a/centreon-plugins/cloud/nutanix/snmp/mode/containerusage.pm +++ b/centreon-plugins/cloud/nutanix/snmp/mode/containerusage.pm @@ -43,11 +43,13 @@ sub custom_usage_perfdata { $total_options{cast_int} = 1; } - $self->{output}->perfdata_add(label => $label . $extra_label, unit => 'B', - value => $value_perf, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options), - min => 0, max => $self->{result_values}->{total}); + $self->{output}->perfdata_add( + label => $label . $extra_label, unit => 'B', + value => $value_perf, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options), + min => 0, max => $self->{result_values}->{total} + ); } sub custom_usage_threshold { @@ -70,11 +72,12 @@ sub custom_usage_output { my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); 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 $msg = sprintf("Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", - $total_size_value . " " . $total_size_unit, - $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, - $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}); - return $msg; + return sprintf( + 'Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)', + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free} + ); } sub custom_usage_calc { @@ -86,17 +89,16 @@ sub custom_usage_calc { $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used}; $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total}; $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used}; - return 0; } sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ { name => 'container', type => 1, cb_prefix_output => 'prefix_container_output', message_multiple => 'All containers are ok', skipped_code => { -10 => 1 } }, ]; - + $self->{maps_counters}->{container} = [ { label => 'usage', set => { key_values => [ { name => 'display' }, { name => 'citUsedCapacity' }, { name => 'citTotalCapacity' } ], @@ -131,11 +133,11 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - + $options{options}->add_options(arguments => { - "filter-name:s" => { name => 'filter_name' }, - "units:s" => { name => 'units', default => '%' }, - "free" => { name => 'free' }, + 'filter-name:s' => { name => 'filter_name' }, + 'units:s' => { name => 'units', default => '%' }, + 'free' => { name => 'free' }, }); return $self; @@ -143,7 +145,7 @@ sub new { sub prefix_container_output { my ($self, %options) = @_; - + return "Container '" . $options{instance_value}->{display} . "' "; } @@ -164,10 +166,12 @@ sub manage_selection { $self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3."); $self->{output}->option_exit(); } - + $self->{container} = {}; - my $snmp_result = $options{snmp}->get_table(oid => $oid_citEntry, - nothing_quit => 1); + my $snmp_result = $options{snmp}->get_table( + oid => $oid_citEntry, + nothing_quit => 1 + ); foreach my $oid (keys %{$snmp_result}) { next if ($oid !~ /^$mapping->{citContainerName}->{oid}\.(.*)$/); @@ -180,12 +184,12 @@ sub manage_selection { $self->{output}->output_add(long_msg => "skipping '" . $result->{citContainerName} . "': no matching filter.", debug => 1); next; } - + $self->{container}->{$instance} = { display => $result->{citContainerName}, %$result, }; } - + if (scalar(keys %{$self->{container}}) <= 0) { $self->{output}->add_option_msg(short_msg => "No container found."); $self->{output}->option_exit(); diff --git a/centreon-plugins/cloud/nutanix/snmp/mode/diskusage.pm b/centreon-plugins/cloud/nutanix/snmp/mode/diskusage.pm index 9036d4f0c..2de3b02d2 100644 --- a/centreon-plugins/cloud/nutanix/snmp/mode/diskusage.pm +++ b/centreon-plugins/cloud/nutanix/snmp/mode/diskusage.pm @@ -29,14 +29,13 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold) sub custom_status_output { my ($self, %options) = @_; - - my $msg = 'state : ' . $self->{result_values}->{state}; - return $msg; + + return 'state : ' . $self->{result_values}->{state}; } sub custom_status_calc { my ($self, %options) = @_; - + $self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_dstState'}; $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; return 0; @@ -59,11 +58,13 @@ sub custom_usage_perfdata { $total_options{cast_int} = 1; } - $self->{output}->perfdata_add(label => $label . $extra_label, unit => 'B', - value => $value_perf, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options), - min => 0, max => $self->{result_values}->{total}); + $self->{output}->perfdata_add( + label => $label . $extra_label, unit => 'B', + value => $value_perf, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options), + min => 0, max => $self->{result_values}->{total} + ); } sub custom_usage_threshold { @@ -86,11 +87,12 @@ sub custom_usage_output { my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); 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 $msg = sprintf("Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", - $total_size_value . " " . $total_size_unit, - $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, - $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}); - return $msg; + return sprintf( + 'Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)', + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free} + ); } sub custom_usage_calc { @@ -102,17 +104,16 @@ sub custom_usage_calc { $self->{result_values}->{used} = $self->{result_values}->{total} - $self->{result_values}->{free}; $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total}; $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used}; - return 0; } sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ { name => 'disk', type => 1, cb_prefix_output => 'prefix_disk_output', message_multiple => 'All disks are ok', skipped_code => { -10 => 1 } }, ]; - + $self->{maps_counters}->{disk} = [ { label => 'status', threshold => 0, set => { key_values => [ { name => 'dstState' }, { name => 'display' } ], @@ -164,16 +165,15 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '' }, - "units:s" => { name => 'units', default => '%' }, - "free" => { name => 'free' }, - }); - + + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '' }, + 'units:s' => { name => 'units', default => '%' }, + 'free' => { name => 'free' }, + }); + return $self; } @@ -186,7 +186,7 @@ sub check_options { sub prefix_disk_output { my ($self, %options) = @_; - + return "Disk '" . $options{instance_value}->{display} . "' "; } @@ -212,10 +212,12 @@ sub manage_selection { $self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3."); $self->{output}->option_exit(); } - + $self->{disk} = {}; - my $snmp_result = $options{snmp}->get_table(oid => $oid_dstEntry, - nothing_quit => 1); + my $snmp_result = $options{snmp}->get_table( + oid => $oid_dstEntry, + nothing_quit => 1 + ); foreach my $oid (keys %{$snmp_result}) { next if ($oid !~ /^$mapping->{dstDiskId}->{oid}\.(.*)$/); @@ -228,14 +230,16 @@ sub manage_selection { $self->{output}->output_add(long_msg => "skipping '" . $result->{dstDiskId} . "': no matching filter.", debug => 1); next; } - + my $inodes_used; $inodes_used = 100 - ($result->{dstNumFreeInodes} * 100 / $result->{dstNumTotalInodes}) if ($result->{dstNumTotalInodes} > 0); - $self->{disk}->{$instance} = { display => $result->{dstDiskId}, - %$result, inodes_used => $inodes_used, + $self->{disk}->{$instance} = { + display => $result->{dstDiskId}, + %$result, + inodes_used => $inodes_used }; } - + if (scalar(keys %{$self->{disk}}) <= 0) { $self->{output}->add_option_msg(short_msg => "No disk found."); $self->{output}->option_exit(); diff --git a/centreon-plugins/cloud/nutanix/snmp/mode/hypervisorusage.pm b/centreon-plugins/cloud/nutanix/snmp/mode/hypervisorusage.pm index 6b4e26b77..351da7186 100644 --- a/centreon-plugins/cloud/nutanix/snmp/mode/hypervisorusage.pm +++ b/centreon-plugins/cloud/nutanix/snmp/mode/hypervisorusage.pm @@ -35,11 +35,13 @@ sub custom_usage_perfdata { $extra_label = '_' . $self->{result_values}->{display} if (!defined($options{extra_instance}) || $options{extra_instance} != 0); my %total_options = (total => $self->{result_values}->{total}, cast_int => 1); - $self->{output}->perfdata_add(label => $label . $extra_label, unit => 'B', - value => $value_perf, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options), - min => 0, max => $self->{result_values}->{total}); + $self->{output}->perfdata_add( + label => $label . $extra_label, unit => 'B', + value => $value_perf, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options), + min => 0, max => $self->{result_values}->{total} + ); } sub custom_usage_output { @@ -48,11 +50,12 @@ sub custom_usage_output { my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); 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 $msg = sprintf("Memory Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", - $total_size_value . " " . $total_size_unit, - $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, - $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}); - return $msg; + return sprintf( + 'Memory Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)', + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free} + ); } sub custom_usage_calc { @@ -64,17 +67,16 @@ sub custom_usage_calc { $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used}; $self->{result_values}->{used} = $self->{result_values}->{prct_used} * $self->{result_values}->{total} / 100; $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used}; - return 0; } sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ { name => 'hypervisor', type => 1, cb_prefix_output => 'prefix_hypervisor_output', message_multiple => 'All hypervisors are ok', skipped_code => { -10 => 1 } }, ]; - + $self->{maps_counters}->{hypervisor} = [ { label => 'cpu', set => { key_values => [ { name => 'hypervisorCpuUsagePercent' }, { name => 'display' } ], @@ -136,9 +138,9 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - + $options{options}->add_options(arguments => { - "filter-name:s" => { name => 'filter_name' }, + 'filter-name:s' => { name => 'filter_name' }, }); return $self; @@ -146,7 +148,7 @@ sub new { sub prefix_hypervisor_output { my ($self, %options) = @_; - + return "Hypervisor '" . $options{instance_value}->{display} . "' "; } @@ -172,8 +174,10 @@ sub manage_selection { } $self->{hypervisor} = {}; - my $snmp_result = $options{snmp}->get_table(oid => $oid_hypervisorEntry, - nothing_quit => 1); + my $snmp_result = $options{snmp}->get_table( + oid => $oid_hypervisorEntry, + nothing_quit => 1 + ); foreach my $oid (keys %{$snmp_result}) { next if ($oid !~ /^$mapping->{hypervisorName}->{oid}\.(.*)$/); @@ -186,12 +190,13 @@ sub manage_selection { $self->{output}->output_add(long_msg => "skipping '" . $result->{hypervisorName} . "': no matching filter.", debug => 1); next; } - - $self->{hypervisor}->{$instance} = { display => $result->{hypervisorName}, + + $self->{hypervisor}->{$instance} = { + display => $result->{hypervisorName}, %$result, }; } - + if (scalar(keys %{$self->{hypervisor}}) <= 0) { $self->{output}->add_option_msg(short_msg => "No hypervisor found."); $self->{output}->option_exit(); diff --git a/centreon-plugins/cloud/nutanix/snmp/mode/listcontainers.pm b/centreon-plugins/cloud/nutanix/snmp/mode/listcontainers.pm index b2fc1dbe2..d2398a0ec 100644 --- a/centreon-plugins/cloud/nutanix/snmp/mode/listcontainers.pm +++ b/centreon-plugins/cloud/nutanix/snmp/mode/listcontainers.pm @@ -32,11 +32,10 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - }); + + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + }); return $self; } @@ -57,7 +56,7 @@ sub manage_selection { $self->{output}->output_add(long_msg => "skipping container '" . $snmp_result->{$oid} . "'.", debug => 1); next; } - + $self->{container}->{$snmp_result->{$oid}} = { name => $snmp_result->{$oid} }; } } @@ -70,16 +69,18 @@ sub run { foreach my $name (sort keys %{$self->{container}}) { $self->{output}->output_add(long_msg => "'" . $name . "'"); } - - $self->{output}->output_add(severity => 'OK', - short_msg => 'List Containers:'); + + $self->{output}->output_add( + severity => 'OK', + short_msg => 'List containers:' + ); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } sub disco_format { my ($self, %options) = @_; - + $self->{output}->add_disco_format(elements => ['name']); } @@ -110,4 +111,3 @@ Filter by container name. =back =cut - diff --git a/centreon-plugins/cloud/nutanix/snmp/mode/listdisks.pm b/centreon-plugins/cloud/nutanix/snmp/mode/listdisks.pm index bddc051b3..48ca5c4b6 100644 --- a/centreon-plugins/cloud/nutanix/snmp/mode/listdisks.pm +++ b/centreon-plugins/cloud/nutanix/snmp/mode/listdisks.pm @@ -41,10 +41,9 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - }); + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + }); return $self; } @@ -56,14 +55,18 @@ sub check_options { sub manage_selection { my ($self, %options) = @_; - my $snmp_result = $self->{snmp}->get_multiple_table(oids => [ + my $snmp_result = $self->{snmp}->get_multiple_table( + oids => [ { oid => $mapping->{dstDiskId}->{oid} }, { oid => $mapping->{dstState}->{oid} }, - ], return_type => 1, nothing_quit => 1); + ], + return_type => 1, + nothing_quit => 1 + ); $self->{disk} = {}; foreach my $oid (keys %{$snmp_result}) { next if ($oid !~ /^$mapping->{dstState}->{oid}\.(.*)$/); - + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $1); $result->{dstDiskId} = centreon::plugins::misc::trim($result->{dstDiskId}); if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && @@ -71,7 +74,7 @@ sub manage_selection { $self->{output}->output_add(long_msg => "skipping disk '" . $result->{dstDiskId} . "'.", debug => 1); next; } - + $self->{disk}->{$result->{dstDiskId}} = { %{$result} }; } } @@ -84,16 +87,18 @@ sub run { foreach my $name (sort keys %{$self->{disk}}) { $self->{output}->output_add(long_msg => "[disk_id = " . $self->{disk}->{$name}->{dstDiskId} . "] [state = " . $self->{disk}->{$name}->{dstState} . "]"); } - - $self->{output}->output_add(severity => 'OK', - short_msg => 'List Disks:'); + + $self->{output}->output_add( + severity => 'OK', + short_msg => 'List disks:' + ); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } sub disco_format { my ($self, %options) = @_; - + $self->{output}->add_disco_format(elements => ['disk_id', 'state']); } @@ -103,8 +108,10 @@ sub disco_show { $self->manage_selection(); foreach my $name (sort keys %{$self->{disk}}) { - $self->{output}->add_disco_entry(disk_id => $self->{disk}->{$name}->{dstDiskId}, - state => $self->{disk}->{$name}->{dstState}); + $self->{output}->add_disco_entry( + disk_id => $self->{disk}->{$name}->{dstDiskId}, + state => $self->{disk}->{$name}->{dstState} + ); } } @@ -125,4 +132,3 @@ Filter by disk id. =back =cut - diff --git a/centreon-plugins/cloud/nutanix/snmp/mode/listhypervisors.pm b/centreon-plugins/cloud/nutanix/snmp/mode/listhypervisors.pm index 4c53eaf14..60c2f2bf4 100644 --- a/centreon-plugins/cloud/nutanix/snmp/mode/listhypervisors.pm +++ b/centreon-plugins/cloud/nutanix/snmp/mode/listhypervisors.pm @@ -33,10 +33,9 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - }); + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + }); return $self; } @@ -57,7 +56,7 @@ sub manage_selection { $self->{output}->output_add(long_msg => "skipping hypervisor '" . $snmp_result->{$oid} . "'.", debug => 1); next; } - + $self->{hypervisor}->{$snmp_result->{$oid}} = { name => $snmp_result->{$oid} }; } } @@ -110,4 +109,3 @@ Filter by hypervisor name. =back =cut - diff --git a/centreon-plugins/cloud/nutanix/snmp/mode/liststoragepools.pm b/centreon-plugins/cloud/nutanix/snmp/mode/liststoragepools.pm index 49bf826ed..6662204f7 100644 --- a/centreon-plugins/cloud/nutanix/snmp/mode/liststoragepools.pm +++ b/centreon-plugins/cloud/nutanix/snmp/mode/liststoragepools.pm @@ -33,10 +33,9 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - }); + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + }); return $self; } @@ -110,4 +109,3 @@ Filter by storage pool name. =back =cut - diff --git a/centreon-plugins/cloud/nutanix/snmp/mode/listvms.pm b/centreon-plugins/cloud/nutanix/snmp/mode/listvms.pm index 2b6ce3949..2e83528b2 100644 --- a/centreon-plugins/cloud/nutanix/snmp/mode/listvms.pm +++ b/centreon-plugins/cloud/nutanix/snmp/mode/listvms.pm @@ -35,11 +35,10 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - }); + + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + }); return $self; } @@ -51,14 +50,18 @@ sub check_options { sub manage_selection { my ($self, %options) = @_; - my $snmp_result = $self->{snmp}->get_multiple_table(oids => [ + my $snmp_result = $self->{snmp}->get_multiple_table( + oids => [ { oid => $mapping->{vmName}->{oid} }, { oid => $mapping->{vmPowerState}->{oid} }, - ], return_type => 1, nothing_quit => 1); + ], + return_type => 1, + nothing_quit => 1 + ); $self->{vm} = {}; foreach my $oid (keys %{$snmp_result}) { next if ($oid !~ /^$mapping->{vmPowerState}->{oid}\.(.*)$/); - + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $1); $result->{vmName} = centreon::plugins::misc::trim($result->{vmName}); if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && @@ -66,7 +69,7 @@ sub manage_selection { $self->{output}->output_add(long_msg => "skipping virtual machine '" . $result->{vmName} . "'.", debug => 1); next; } - + $self->{vm}->{$result->{vmName}} = { %{$result} }; } } @@ -79,16 +82,18 @@ sub run { foreach my $name (sort keys %{$self->{vm}}) { $self->{output}->output_add(long_msg => "[name = " . $self->{vm}->{$name}->{vmName} . "] [state = " . $self->{vm}->{$name}->{vmPowerState} . "]"); } - - $self->{output}->output_add(severity => 'OK', - short_msg => 'List Virtual Machines:'); + + $self->{output}->output_add( + severity => 'OK', + short_msg => 'List Virtual Machines:' + ); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } sub disco_format { my ($self, %options) = @_; - + $self->{output}->add_disco_format(elements => ['name', 'state']); } @@ -98,8 +103,10 @@ sub disco_show { $self->manage_selection(); foreach my $name (sort keys %{$self->{vm}}) { - $self->{output}->add_disco_entry(name => $self->{vm}->{$name}->{vmName}, - state => $self->{vm}->{$name}->{vmPowerState}); + $self->{output}->add_disco_entry( + name => $self->{vm}->{$name}->{vmName}, + state => $self->{vm}->{$name}->{vmPowerState} + ); } } @@ -120,4 +127,3 @@ Filter by virtual machine name. =back =cut - diff --git a/centreon-plugins/cloud/nutanix/snmp/mode/storagepoolusage.pm b/centreon-plugins/cloud/nutanix/snmp/mode/storagepoolusage.pm index 80c8b5e2d..5de35cb0d 100644 --- a/centreon-plugins/cloud/nutanix/snmp/mode/storagepoolusage.pm +++ b/centreon-plugins/cloud/nutanix/snmp/mode/storagepoolusage.pm @@ -43,11 +43,13 @@ sub custom_usage_perfdata { $total_options{cast_int} = 1; } - $self->{output}->perfdata_add(label => $label . $extra_label, unit => 'B', - value => $value_perf, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options), - min => 0, max => $self->{result_values}->{total}); + $self->{output}->perfdata_add( + label => $label . $extra_label, unit => 'B', + value => $value_perf, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options), + min => 0, max => $self->{result_values}->{total} + ); } sub custom_usage_threshold { @@ -70,11 +72,12 @@ sub custom_usage_output { my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); 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 $msg = sprintf("Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", - $total_size_value . " " . $total_size_unit, - $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, - $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}); - return $msg; + return sprintf( + 'Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)', + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free} + ); } sub custom_usage_calc { @@ -86,17 +89,16 @@ sub custom_usage_calc { $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used}; $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total}; $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used}; - return 0; } sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ { name => 'sp', type => 1, cb_prefix_output => 'prefix_sp_output', message_multiple => 'All storage pools are ok', skipped_code => { -10 => 1 } }, ]; - + $self->{maps_counters}->{sp} = [ { label => 'usage', set => { key_values => [ { name => 'display' }, { name => 'spitUsedCapacity' }, { name => 'spitTotalCapacity' } ], @@ -133,9 +135,9 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "filter-name:s" => { name => 'filter_name' }, - "units:s" => { name => 'units', default => '%' }, - "free" => { name => 'free' }, + 'filter-name:s' => { name => 'filter_name' }, + 'units:s' => { name => 'units', default => '%' }, + 'free' => { name => 'free' }, }); return $self; @@ -166,8 +168,10 @@ sub manage_selection { } $self->{sp} = {}; - my $snmp_result = $options{snmp}->get_table(oid => $oid_spitEntry, - nothing_quit => 1); + my $snmp_result = $options{snmp}->get_table( + oid => $oid_spitEntry, + nothing_quit => 1 + ); foreach my $oid (keys %{$snmp_result}) { next if ($oid !~ /^$mapping->{spitStoragePoolName}->{oid}\.(.*)$/); @@ -180,12 +184,13 @@ sub manage_selection { $self->{output}->output_add(long_msg => "skipping '" . $result->{spitStoragePoolName} . "': no matching filter.", debug => 1); next; } - - $self->{sp}->{$instance} = { display => $result->{spitStoragePoolName}, - %$result, + + $self->{sp}->{$instance} = { + display => $result->{spitStoragePoolName}, + %$result }; } - + if (scalar(keys %{$self->{sp}}) <= 0) { $self->{output}->add_option_msg(short_msg => "No storage pool found."); $self->{output}->option_exit(); diff --git a/centreon-plugins/cloud/nutanix/snmp/mode/vmusage.pm b/centreon-plugins/cloud/nutanix/snmp/mode/vmusage.pm index c86383533..5e0e94724 100644 --- a/centreon-plugins/cloud/nutanix/snmp/mode/vmusage.pm +++ b/centreon-plugins/cloud/nutanix/snmp/mode/vmusage.pm @@ -29,11 +29,11 @@ use Digest::MD5 qw(md5_hex); sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ { name => 'vm', type => 1, cb_prefix_output => 'prefix_vm_output', message_multiple => 'All virtual machines are ok', skipped_code => { -10 => 1 } }, ]; - + $self->{maps_counters}->{vm} = [ { label => 'cpu', set => { key_values => [ { name => 'vmCpuUsagePercent' }, { name => 'display' } ], @@ -98,17 +98,17 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - + $options{options}->add_options(arguments => { - "filter-name:s" => { name => 'filter_name' }, + 'filter-name:s' => { name => 'filter_name' }, }); - + return $self; } sub prefix_vm_output { my ($self, %options) = @_; - + return "Virtual machine '" . $options{instance_value}->{display} . "' "; } @@ -135,8 +135,10 @@ sub manage_selection { } $self->{vm} = {}; - my $snmp_result = $options{snmp}->get_table(oid => $oid_vmEntry, - nothing_quit => 1); + my $snmp_result = $options{snmp}->get_table( + oid => $oid_vmEntry, + nothing_quit => 1 + ); foreach my $oid (keys %{$snmp_result}) { next if ($oid !~ /^$mapping->{vmName}->{oid}\.(.*)$/); @@ -149,19 +151,20 @@ sub manage_selection { $self->{output}->output_add(long_msg => "skipping '" . $result->{vmName} . "': no matching filter.", debug => 1); next; } - + $result->{vmRxBytes} *= 8; $result->{vmTxBytes} *= 8; - $self->{vm}->{$instance} = { display => $result->{vmName}, - %$result, + $self->{vm}->{$instance} = { + display => $result->{vmName}, + %$result }; } - + if (scalar(keys %{$self->{vm}}) <= 0) { $self->{output}->add_option_msg(short_msg => "No virtual machine found."); $self->{output}->option_exit(); } - + $self->{cache_name} = "nutanix_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all'));