diff --git a/centreon-plugins/apps/vmware/connector/mode/countvmhost.pm b/centreon-plugins/apps/vmware/connector/mode/countvmhost.pm index 5014280d9..814f791c1 100644 --- a/centreon-plugins/apps/vmware/connector/mode/countvmhost.pm +++ b/centreon-plugins/apps/vmware/connector/mode/countvmhost.pm @@ -153,7 +153,7 @@ sub check_options { sub manage_selection { my ($self, %options) = @_; - $self->{global} = { poweredon => 0, poweredoff => 0, suspended => 0 }; + $self->{global} = { poweredon => 0, poweredoff => 0, suspended => 0, total => 0 }; $self->{host} = {}; my $response = $options{custom}->execute(params => $self->{option_results}, command => 'countvmhost'); @@ -172,6 +172,8 @@ sub manage_selection { $self->{global}->{poweredoff} += $response->{data}->{$host_id}->{poweredoff} if (defined($response->{data}->{$host_id}->{poweredoff})); $self->{global}->{suspended} += $response->{data}->{$host_id}->{suspended} if (defined($response->{data}->{$host_id}->{suspended})); } + + $self->{global}->{total} = $self->{global}->{poweredon} + $self->{global}->{poweredoff} + $self->{global}->{suspended}; } 1; diff --git a/centreon-plugins/apps/vmware/connector/mode/cpuhost.pm b/centreon-plugins/apps/vmware/connector/mode/cpuhost.pm index 064230390..b8eadb442 100644 --- a/centreon-plugins/apps/vmware/connector/mode/cpuhost.pm +++ b/centreon-plugins/apps/vmware/connector/mode/cpuhost.pm @@ -45,7 +45,7 @@ sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'host', type => 3, cb_prefix_output => 'prefix_host_output', cb_long_output => 'host_long_output', message_multiple => 'All hosts are ok', + { name => 'host', type => 3, cb_prefix_output => 'prefix_host_output', cb_long_output => 'host_long_output', indent_long_output => ' ', message_multiple => 'All ESX hosts are ok', group => [ { name => 'global', type => 0, skipped_code => { -10 => 1 } }, { name => 'global_cpu', cb_prefix_output => 'prefix_global_cpu_output', type => 0, skipped_code => { -10 => 1 } }, diff --git a/centreon-plugins/apps/vmware/connector/mode/cpuvm.pm b/centreon-plugins/apps/vmware/connector/mode/cpuvm.pm index 2135c332f..0e490f1ff 100644 --- a/centreon-plugins/apps/vmware/connector/mode/cpuvm.pm +++ b/centreon-plugins/apps/vmware/connector/mode/cpuvm.pm @@ -46,7 +46,7 @@ sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'vm', type => 3, cb_prefix_output => 'prefix_vm_output', cb_long_output => 'vm_long_output', message_multiple => 'All virtual machines are ok', + { name => 'vm', type => 3, cb_prefix_output => 'prefix_vm_output', cb_long_output => 'vm_long_output', indent_long_output => ' ', message_multiple => 'All virtual machines are ok', group => [ { name => 'global', type => 0, skipped_code => { -10 => 1 } }, { name => 'global_cpu', cb_prefix_output => 'prefix_global_cpu_output', type => 0, skipped_code => { -10 => 1 } }, @@ -99,7 +99,7 @@ sub set_counters { $self->{maps_counters}->{cpu} = [ { label => 'cpu', set => { key_values => [ { name => 'cpu_usage' }, { name => 'display' } ], - output_template => 'usage : %s', + output_template => 'usage : %s %%', perfdatas => [ { label => 'cpu', value => 'cpu_usage_absolute', template => '%s', unit => '%', min => 0, max => 100, label_extra_instance => 1 }, diff --git a/centreon-plugins/apps/vmware/connector/mode/datastorecountvm.pm b/centreon-plugins/apps/vmware/connector/mode/datastorecountvm.pm index 6c6adc00d..bf3860b60 100644 --- a/centreon-plugins/apps/vmware/connector/mode/datastorecountvm.pm +++ b/centreon-plugins/apps/vmware/connector/mode/datastorecountvm.pm @@ -20,10 +20,109 @@ package apps::vmware::connector::mode::datastorecountvm; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; +use centreon::plugins::misc; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = 'accessible ' . $self->{result_values}->{accessible}; + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{accessible} = $options{new_datas}->{$self->{instance} . '_accessible'}; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, skipped_code => { -10 => 1 } }, + { name => 'datastore', type => 1, cb_prefix_output => 'prefix_datastore_output', message_multiple => 'All Datastores are ok' }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'total-on', set => { + key_values => [ { name => 'poweredon' }, { name => 'total' } ], + output_template => '%s VM(s) poweredon', + perfdatas => [ + { label => 'poweredon', value => 'poweredon_absolute', template => '%s', + min => 0, max => 'total_absolute' }, + ], + } + }, + { label => 'total-off', set => { + key_values => [ { name => 'poweredoff' }, { name => 'total' } ], + output_template => '%s VM(s) poweredoff', + perfdatas => [ + { label => 'poweredoff', value => 'poweredoff_absolute', template => '%s', + min => 0, max => 'total_absolute' }, + ], + } + }, + { label => 'total-suspended', set => { + key_values => [ { name => 'suspended' }, { name => 'total' } ], + output_template => '%s VM(s) suspended', + perfdatas => [ + { label => 'suspended', value => 'suspended_absolute', template => '%s', + min => 0, max => 'total_absolute' }, + ], + } + }, + ]; + + $self->{maps_counters}->{datastore} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'accessible' } ], + 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, + } + }, + { label => 'on', set => { + key_values => [ { name => 'poweredon' }, { name => 'total' } ], + output_template => '%s VM(s) poweredon', + perfdatas => [ + { label => 'poweredon', value => 'poweredon_absolute', template => '%s', + min => 0, max => 'total_absolute', label_extra_instance => 1 }, + ], + } + }, + { label => 'off', set => { + key_values => [ { name => 'poweredoff' }, { name => 'total' } ], + output_template => '%s VM(s) poweredoff', + perfdatas => [ + { label => 'poweredoff', value => 'poweredoff_absolute', template => '%s', + min => 0, max => 'total_absolute', label_extra_instance => 1 }, + ], + } + }, + { label => 'suspended', set => { + key_values => [ { name => 'suspended' }, { name => 'total' } ], + output_template => '%s VM(s) suspended', + perfdatas => [ + { label => 'suspended', value => 'suspended_absolute', template => '%s', + min => 0, max => 'total_absolute', label_extra_instance => 1 }, + ], + } + }, + ]; +} + +sub prefix_datastore_output { + my ($self, %options) = @_; + + return "Datastore '" . $options{instance_value}->{display} . "' : "; +} sub new { my ($class, %options) = @_; @@ -31,48 +130,49 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "datastore-name:s" => { name => 'datastore_name' }, - "filter" => { name => 'filter' }, - "scope-datacenter:s" => { name => 'scope_datacenter' }, - "disconnect-status:s" => { name => 'disconnect_status', default => 'unknown' }, - "warning-on:s" => { name => 'warning_on' }, - "critical-on:s" => { name => 'critical_on' }, - "warning-off:s" => { name => 'warning_off' }, - "critical-off:s" => { name => 'critical_off' }, - "warning-suspended:s" => { name => 'warning_suspended' }, - "critical-suspended:s" => { name => 'critical_suspended' }, - }); + $options{options}->add_options(arguments => { + "datastore-name:s" => { name => 'datastore_name' }, + "filter" => { name => 'filter' }, + "scope-datacenter:s" => { name => 'scope_datacenter' }, + "unknown-status:s" => { name => 'unknown_status', default => '%{accessible} !~ /^true|1$/i' }, + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '' }, + }); + return $self; } sub check_options { my ($self, %options) = @_; - $self->SUPER::init(%options); + $self->SUPER::check_options(%options); - foreach my $label (('warning_on', 'critical_on', 'warning_off', 'critical_off', 'warning_suspended', 'critical_suspended')) { - if (($self->{perfdata}->threshold_validate(label => $label, value => $self->{option_results}->{$label})) == 0) { - my ($label_opt) = $label; - $label_opt =~ tr/_/-/; - $self->{output}->add_option_msg(short_msg => "Wrong " . $label_opt . " threshold '" . $self->{option_results}->{$label} . "'."); - $self->{output}->option_exit(); - } - } - - if ($self->{output}->is_litteral_status(status => $self->{option_results}->{disconnect_status}) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong disconnect-status status option '" . $self->{option_results}->{disconnect_status} . "'."); - $self->{output}->option_exit(); - } + $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); } -sub run { +sub manage_selection { my ($self, %options) = @_; - $self->{connector} = $options{custom}; - $self->{connector}->add_params(params => $self->{option_results}, - command => 'datastorecountvm'); - $self->{connector}->run(); + $self->{global} = { poweredon => 0, poweredoff => 0, suspended => 0, total => 0 }; + $self->{datastore} = {}; + my $response = $options{custom}->execute(params => $self->{option_results}, + command => 'datastorecountvm'); + + foreach my $ds_id (keys %{$response->{data}}) { + my $ds_name = $response->{data}->{$ds_id}->{name}; + $self->{datastore}->{$ds_name} = { + display => $ds_name, + accessible => $response->{data}->{$ds_id}->{accessible}, + poweredon => $response->{data}->{$ds_id}->{poweredon}, + poweredoff => $response->{data}->{$ds_id}->{poweredoff}, + suspended => $response->{data}->{$ds_id}->{suspended}, + total => $response->{data}->{$ds_id}->{poweredon} + $response->{data}->{$ds_id}->{poweredoff} + $response->{data}->{$ds_id}->{suspended}, + }; + $self->{global}->{poweredon} += $response->{data}->{$ds_id}->{poweredon} if (defined($response->{data}->{$ds_id}->{poweredon})); + $self->{global}->{poweredoff} += $response->{data}->{$ds_id}->{poweredoff} if (defined($response->{data}->{$ds_id}->{poweredoff})); + $self->{global}->{suspended} += $response->{data}->{$ds_id}->{suspended} if (defined($response->{data}->{$ds_id}->{suspended})); + } + + $self->{global}->{total} = $self->{global}->{poweredon} + $self->{global}->{poweredoff} + $self->{global}->{suspended}; } 1; @@ -97,33 +197,32 @@ Datastore name is a regexp. Search in following datacenter(s) (can be a regexp). -=item B<--disconnect-status> +=item B<--unknown-status> -Status if datastore disconnected (default: 'unknown'). +Set warning threshold for status (Default: '%{accessible} !~ /^true|1$/i'). +Can used special variables like: %{status} -=item B<--warning-on> +=item B<--warning-status> -Threshold warning for 'poweredOn' vms. +Set warning threshold for status (Default: ''). +Can used special variables like: %{status} -=item B<--critical-on> +=item B<--critical-status> -Threshold critical for 'poweredOn' vms. +Set critical threshold for status (Default: ''). +Can used special variables like: %{status} -=item B<--warning-off> +=item B<--warning-*> -Threshold warning for 'poweredOff' vms. +Threshold warning. +Can be: 'total-on', 'total-off', 'total-suspended', +'on', 'off', 'suspended'. -=item B<--critical-off> +=item B<--critical-*> -Threshold critical for 'poweredOff' vms. - -=item B<--warning-suspended> - -Threshold warning for 'suspended' vms. - -=item B<--critical-suspended> - -Threshold critical for 'suspended' vms. +Threshold critical. +Can be: 'total-on', 'total-off', 'total-suspended', +'on', 'off', 'suspended'. =back diff --git a/centreon-plugins/apps/vmware/connector/mode/datastorehost.pm b/centreon-plugins/apps/vmware/connector/mode/datastorehost.pm index 11e967181..35fc6dc91 100644 --- a/centreon-plugins/apps/vmware/connector/mode/datastorehost.pm +++ b/centreon-plugins/apps/vmware/connector/mode/datastorehost.pm @@ -20,10 +20,89 @@ package apps::vmware::connector::mode::datastorehost; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; +use centreon::plugins::misc; +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; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_state'}; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'host', type => 3, cb_prefix_output => 'prefix_host_output', cb_long_output => 'host_long_output', indent_long_output => ' ', message_multiple => 'All ESX hosts are ok', + group => [ + { name => 'global', type => 0, skipped_code => { -10 => 1 } }, + { name => 'datastore', cb_prefix_output => 'prefix_datastore_output', message_multiple => 'All datastores latencies 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, + } + }, + ]; + + $self->{maps_counters}->{datastore} = [ + { label => 'read-latency', set => { + key_values => [ { name => 'read_latency' }, { name => 'display' } ], + output_template => 'read : %s ms', + perfdatas => [ + { label => 'trl', value => 'read_latency_absolute', template => '%s', unit => 'ms', + min => 0, label_extra_instance => 1 }, + ], + } + }, + { label => 'write-latency', set => { + key_values => [ { name => 'write_latency' }, { name => 'display' } ], + output_template => 'write : %s ms', + perfdatas => [ + { label => 'twl', value => 'write_latency_absolute', template => '%s', unit => 'ms', + min => 0, label_extra_instance => 1 }, + ], + } + }, + ]; +} + +sub prefix_host_output { + my ($self, %options) = @_; + + return "Host '" . $options{instance_value}->{display} . "' : "; +} + +sub host_long_output { + my ($self, %options) = @_; + + return "checking host '" . $options{instance_value}->{display} . "'"; +} + +sub prefix_datastore_output { + my ($self, %options) = @_; + + return "datastore '" . $options{instance_value}->{display} . "' latency : "; +} sub new { my ($class, %options) = @_; @@ -31,46 +110,52 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "esx-hostname:s" => { name => 'esx_hostname' }, - "filter" => { name => 'filter' }, - "scope-datacenter:s" => { name => 'scope_datacenter' }, - "scope-cluster:s" => { name => 'scope_cluster' }, - "disconnect-status:s" => { name => 'disconnect_status', default => 'unknown' }, - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, - "datastore-name:s" => { name => 'datastore_name' }, - "filter-datastore:s" => { name => 'filter_datastore' }, - }); + $options{options}->add_options(arguments => { + "esx-hostname:s" => { name => 'esx_hostname' }, + "filter" => { name => 'filter' }, + "scope-datacenter:s" => { name => 'scope_datacenter' }, + "scope-cluster:s" => { name => 'scope_cluster' }, + "datastore-name:s" => { name => 'datastore_name' }, + "filter-datastore:s" => { name => 'filter_datastore' }, + "unknown-status:s" => { name => 'unknown_status', default => '%{status} !~ /^connected$/i' }, + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '' }, + }); + return $self; } sub check_options { my ($self, %options) = @_; - $self->SUPER::init(%options); + $self->SUPER::check_options(%options); - if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); - $self->{output}->option_exit(); - } - if ($self->{output}->is_litteral_status(status => $self->{option_results}->{disconnect_status}) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong disconnect-status status option '" . $self->{option_results}->{disconnect_status} . "'."); - $self->{output}->option_exit(); - } + $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); } -sub run { +sub manage_selection { my ($self, %options) = @_; - $self->{connector} = $options{custom}; - $self->{connector}->add_params(params => $self->{option_results}, - command => 'datastorehost'); - $self->{connector}->run(); + $self->{host} = {}; + my $response = $options{custom}->execute(params => $self->{option_results}, + command => 'datastorehost'); + + foreach my $host_id (keys %{$response->{data}}) { + my $host_name = $response->{data}->{$host_id}->{name}; + $self->{host}->{$host_name} = { display => $host_name, + datastore => {}, + global => { + state => $response->{data}->{$host_id}->{state}, + }, + }; + + foreach my $ds_id (sort keys %{$response->{data}->{$host_id}->{datastore}}) { + $self->{host}->{$host_name}->{datastore}->{$ds_id} = { + display => $ds_id, + read_latency => $response->{data}->{$host_id}->{datastore}->{$ds_id}->{'datastore.totalReadLatency.average'}, + write_latency => $response->{data}->{$host_id}->{datastore}->{$ds_id}->{'datastore.totalWriteLatency.average'}, + }; + } + } } 1; @@ -109,17 +194,30 @@ If not set, we check all datastores. Datastore name is a regexp. -=item B<--disconnect-status> +=item B<--unknown-status> -Status if ESX host disconnected (default: 'unknown'). +Set warning threshold for status (Default: '%{status} !~ /^connected$/i'). +Can used special variables like: %{status} -=item B<--warning> +=item B<--warning-status> -Threshold warning in ms. +Set warning threshold for status (Default: ''). +Can used special variables like: %{status} -=item B<--critical> +=item B<--critical-status> -Threshold critical in ms. +Set critical threshold for status (Default: ''). +Can used special variables like: %{status} + +=item B<--warning-*> + +Threshold warning. +Can be: 'read-latency', 'write-latency'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'read-latency', 'write-latency'. =back diff --git a/centreon-plugins/apps/vmware/connector/mode/datastoreio.pm b/centreon-plugins/apps/vmware/connector/mode/datastoreio.pm index 009a3b979..6e1c78972 100644 --- a/centreon-plugins/apps/vmware/connector/mode/datastoreio.pm +++ b/centreon-plugins/apps/vmware/connector/mode/datastoreio.pm @@ -20,10 +20,95 @@ package apps::vmware::connector::mode::datastoreio; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; +use centreon::plugins::misc; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = 'accessible ' . $self->{result_values}->{accessible}; + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{accessible} = $options{new_datas}->{$self->{instance} . '_accessible'}; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, skipped_code => { -10 => 1 } }, + { name => 'datastore', type => 1, cb_prefix_output => 'prefix_datastore_output', message_multiple => 'All Datastores are ok' }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'total-read', set => { + key_values => [ { name => 'read' } ], + output_template => 'Total rate of reading data: %s %s/s', + output_change_bytes => 2, + perfdatas => [ + { label => 'total_read_rate', value => 'read_absolute', template => '%s', + unit => 'B/s', min => 0 }, + ], + } + }, + { label => 'total-write', set => { + key_values => [ { name => 'write' } ], + output_template => 'Total rate of writing data: %s %s/s', + output_change_bytes => 2, + perfdatas => [ + { label => 'total_write_rate', value => 'write_absolute', template => '%s', + min => 0 }, + ], + } + }, + ]; + + $self->{maps_counters}->{datastore} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'accessible' } ], + 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, + } + }, + { label => 'read', set => { + key_values => [ { name => 'read' } ], + output_template => 'rate of reading data: %s %s/s', + output_change_bytes => 2, + perfdatas => [ + { label => 'read_rate', value => 'read_absolute', template => '%s', + unit => 'B/s', min => 0, label_extra_instance => 1 }, + ], + } + }, + { label => 'write', set => { + key_values => [ { name => 'write' } ], + output_template => 'rate of writing data: %s %s/s', + output_change_bytes => 2, + perfdatas => [ + { label => 'write_rate', value => 'write_absolute', template => '%s', + min => 0, label_extra_instance => 1 }, + ], + } + }, + ]; +} + +sub prefix_datastore_output { + my ($self, %options) = @_; + + return "Datastore '" . $options{instance_value}->{display} . "' : "; +} sub new { my ($class, %options) = @_; @@ -31,43 +116,44 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "datastore-name:s" => { name => 'datastore_name' }, - "filter" => { name => 'filter' }, - "scope-datacenter:s" => { name => 'scope_datacenter' }, - "disconnect-status:s" => { name => 'disconnect_status', default => 'unknown' }, - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, - }); + $options{options}->add_options(arguments => { + "datastore-name:s" => { name => 'datastore_name' }, + "filter" => { name => 'filter' }, + "scope-datacenter:s" => { name => 'scope_datacenter' }, + "unknown-status:s" => { name => 'unknown_status', default => '%{accessible} !~ /^true|1$/i' }, + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '' }, + }); + return $self; } sub check_options { my ($self, %options) = @_; - $self->SUPER::init(%options); + $self->SUPER::check_options(%options); - if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); - $self->{output}->option_exit(); - } - if ($self->{output}->is_litteral_status(status => $self->{option_results}->{disconnect_status}) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong disconnect-status status option '" . $self->{option_results}->{disconnect_status} . "'."); - $self->{output}->option_exit(); - } + $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); } -sub run { +sub manage_selection { my ($self, %options) = @_; - $self->{connector} = $options{custom}; - $self->{connector}->add_params(params => $self->{option_results}, - command => 'datastoreio'); - $self->{connector}->run(); + $self->{global} = { read => 0, write => 0 }; + $self->{datastore} = {}; + my $response = $options{custom}->execute(params => $self->{option_results}, + command => 'datastoreio'); + + foreach my $ds_id (keys %{$response->{data}}) { + my $ds_name = $response->{data}->{$ds_id}->{name}; + $self->{datastore}->{$ds_name} = { + display => $ds_name, + accessible => $response->{data}->{$ds_id}->{accessible}, + read => $response->{data}->{$ds_id}->{'datastore.write.average'}, + write => $response->{data}->{$ds_id}->{'datastore.read.average'}, + }; + $self->{global}->{read} += $response->{data}->{$ds_id}->{'datastore.write.average'} if (defined($response->{data}->{$ds_id}->{'datastore.write.average'})); + $self->{global}->{write} += $response->{data}->{$ds_id}->{'datastore.write.average'} if (defined($response->{data}->{$ds_id}->{'datastore.write.average'})); + } } 1; @@ -96,13 +182,30 @@ Search in following datacenter(s) (can be a regexp). Status if datastore disconnected (default: 'unknown'). -=item B<--warning> +=item B<--unknown-status> -Threshold warning in bytes per seconds. +Set warning threshold for status (Default: '%{accessible} !~ /^true|1$/i'). +Can used special variables like: %{status} -=item B<--critical> +=item B<--warning-status> -Threshold critical in bytes per seconds. +Set warning threshold for status (Default: ''). +Can used special variables like: %{status} + +=item B<--critical-status> + +Set critical threshold for status (Default: ''). +Can used special variables like: %{status} + +=item B<--warning-*> + +Threshold warning. +Can be: 'total-read', 'total-write', 'read', 'write'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'total-read', 'total-write', 'read', 'write'. =back diff --git a/centreon-plugins/apps/vmware/connector/mode/datastoreiops.pm b/centreon-plugins/apps/vmware/connector/mode/datastoreiops.pm index ccfd5ea4a..7a26c580c 100644 --- a/centreon-plugins/apps/vmware/connector/mode/datastoreiops.pm +++ b/centreon-plugins/apps/vmware/connector/mode/datastoreiops.pm @@ -20,10 +20,111 @@ package apps::vmware::connector::mode::datastoreiops; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; +use centreon::plugins::misc; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = 'accessible ' . $self->{result_values}->{accessible}; + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{accessible} = $options{new_datas}->{$self->{instance} . '_accessible'}; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'datastore', type => 3, cb_prefix_output => 'prefix_datastore_output', cb_long_output => 'datastore_long_output', indent_long_output => ' ', message_multiple => 'All datastores are ok', + group => [ + { name => 'global', type => 0, skipped_code => { -10 => 1 } }, + { name => 'global_iops', type => 0, skipped_code => { -10 => 1 } }, + { name => 'vm', cb_prefix_output => 'prefix_vm_output', message_multiple => 'All virtual machines IOPs are ok', type => 1, skipped_code => { -10 => 1 } }, + ] + } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'accessible' } ], + 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, + } + }, + ]; + + $self->{maps_counters}->{global_iops} = [ + { label => 'read', set => { + key_values => [ { name => 'read' } ], + output_template => '%s read iops', + perfdatas => [ + { label => 'riops', value => 'read_absolute', template => '%s', unit => 'iops', + min => 0, label_extra_instance => 1 }, + ], + } + }, + { label => 'write', set => { + key_values => [ { name => 'write' } ], + output_template => '%s write iops', + perfdatas => [ + { label => 'wiops', value => 'write_absolute', template => '%s', unit => 'iops', + min => 0, max => 'write_absolute', label_extra_instance => 1 }, + ], + } + }, + ]; + + $self->{maps_counters}->{vm} = [ + { label => 'read-vm', set => { + key_values => [ { name => 'read' } ], + output_template => '%s read iops', + perfdatas => [ + { label => 'vm_riops', value => 'read_absolute', template => '%s', unit => 'iops', + min => 0, label_extra_instance => 1 }, + ], + } + }, + { label => 'write-vm', set => { + key_values => [ { name => 'write' } ], + output_template => '%s write iops', + perfdatas => [ + { label => 'vm_wiops', value => 'write_absolute', template => '%s', unit => 'iops', + min => 0, max => 'write_absolute', label_extra_instance => 1 }, + ], + } + }, + ]; +} + +sub prefix_datastore_output { + my ($self, %options) = @_; + + return "Datastore '" . $options{instance_value}->{display} . "' : "; +} + +sub datastore_long_output { + my ($self, %options) = @_; + + return "checking datastore '" . $options{instance_value}->{display} . "'"; +} + +sub prefix_vm_output { + my ($self, %options) = @_; + + return "virtual machine '" . $options{instance_value}->{display} . "' "; +} sub new { my ($class, %options) = @_; @@ -31,44 +132,61 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "datastore-name:s" => { name => 'datastore_name' }, - "filter" => { name => 'filter' }, - "scope-datacenter:s" => { name => 'scope_datacenter' }, - "disconnect-status:s" => { name => 'disconnect_status', default => 'unknown' }, - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, - "detail-iops-min:s" => { name => 'detail_iops_min', default => 50 }, - }); + $options{options}->add_options(arguments => { + "datastore-name:s" => { name => 'datastore_name' }, + "filter" => { name => 'filter' }, + "scope-datacenter:s" => { name => 'scope_datacenter' }, + "detail-iops-min:s" => { name => 'detail_iops_min', default => 50 }, + "unknown-status:s" => { name => 'unknown_status', default => '%{accessible} !~ /^true|1$/i' }, + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '' }, + }); + return $self; } sub check_options { my ($self, %options) = @_; - $self->SUPER::init(%options); + $self->SUPER::check_options(%options); - if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); - $self->{output}->option_exit(); - } - if ($self->{output}->is_litteral_status(status => $self->{option_results}->{disconnect_status}) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong disconnect-status status option '" . $self->{option_results}->{disconnect_status} . "'."); - $self->{output}->option_exit(); - } + $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); } -sub run { +sub manage_selection { my ($self, %options) = @_; - $self->{connector} = $options{custom}; - $self->{connector}->add_params(params => $self->{option_results}, - command => 'datastoreiops'); - $self->{connector}->run(); + $self->{datastore} = {}; + my $response = $options{custom}->execute(params => $self->{option_results}, + command => 'datastoreiops'); + + if ($response->{code} == 200) { + $self->{output}->output_add(severity => 'OK', + short_msg => $response->{short_message}); + return ; + + } + + foreach my $ds_id (keys %{$response->{data}}) { + my $ds_name = $response->{data}->{$ds_id}->{name}; + $self->{datastore}->{$ds_name} = { display => $ds_name, + vm => {}, + global => { + accessible => $response->{data}->{$ds_id}->{accessible}, + }, + global_iops => { + write => $response->{data}->{$ds_id}->{'disk.numberWrite.summation'}, + read => $response->{data}->{$ds_id}->{'disk.numberRead.summation'}, + }, + }; + + foreach my $vm_name (sort keys %{$response->{data}->{$ds_id}->{vm}}) { + $self->{datastore}->{$ds_name}->{vm}->{$vm_name} = { + display => $vm_name, + write => $response->{data}->{$ds_id}->{vm}->{$vm_name}->{'disk.numberWrite.summation'}, + read => $response->{data}->{$ds_id}->{vm}->{$vm_name}->{'disk.numberRead.summation'}, + }; + } + } } 1; @@ -93,21 +211,36 @@ Datastore name is a regexp. Search in following datacenter(s) (can be a regexp). -=item B<--disconnect-status> - -Status if datastore disconnected (default: 'unknown'). - =item B<--detail-iops-min> Only display VMs with iops higher value (default: 50). -=item B<--warning> +=item B<--unknown-status> -Threshold warning in IOPs. +Set warning threshold for status (Default: '%{accessible} !~ /^true|1$/i'). +Can used special variables like: %{status} -=item B<--critical> +=item B<--warning-status> -Threshold critical in IOPs. +Set warning threshold for status (Default: ''). +Can used special variables like: %{status} + +=item B<--critical-status> + +Set critical threshold for status (Default: ''). +Can used special variables like: %{status} + +=item B<--warning-*> + +Threshold warning. +Can be: 'total-on', 'total-off', 'total-suspended', +'on', 'off', 'suspended'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'total-on', 'total-off', 'total-suspended', +'on', 'off', 'suspended'. =back diff --git a/centreon-plugins/centreon/plugins/templates/counter.pm b/centreon-plugins/centreon/plugins/templates/counter.pm index acff47977..536e0acd0 100644 --- a/centreon-plugins/centreon/plugins/templates/counter.pm +++ b/centreon-plugins/centreon/plugins/templates/counter.pm @@ -195,7 +195,7 @@ sub run_global { $suffix_output = '' if (!defined($suffix_output)); if ($called_multiple == 1) { - $self->{output}->output_add(long_msg => "${prefix_output}${long_msg}${suffix_output}"); + $self->{output}->output_add(long_msg => "$options{indent_long_output}${prefix_output}${long_msg}${suffix_output}"); } my $exit = $self->{output}->get_most_critical(status => [ @exits ]); @@ -368,13 +368,14 @@ sub run_multiple_instances { return undef if (defined($options{config}->{cb_init}) && $self->call_object_callback(method_name => $options{config}->{cb_init}) == 1); my $multiple_parent = defined($options{multiple_parent}) && $options{multiple_parent} == 1 ? $options{multiple_parent} : 0; + my $indent_long_output = defined($options{indent_long_output}) ? $options{indent_long_output} : ''; - $self->{multiple} = 1; + my $multiple = 1; if (scalar(keys %{$self->{$options{config}->{name}}}) == 1) { - $self->{multiple} = 0; + $multiple = 0; } - if ($self->{multiple} == 1 && $multiple_parent == 0) { + if ($multiple == 1 && $multiple_parent == 0) { $self->{output}->output_add(short_msg => $options{config}->{message_multiple}); } @@ -390,8 +391,10 @@ sub run_multiple_instances { $_->{label} !~ /$self->{option_results}->{filter_counters}/); my $instance = $id; - if ($multiple_parent == 1) { + if ($multiple_parent == 1 && $multiple == 1) { $instance = $options{instance_parent} . "_" . $id; + } elsif ($multiple_parent == 1 && $multiple == 0) { + $instance = $options{instance_parent}; } $obj->set(instance => $instance); @@ -415,7 +418,11 @@ sub run_multiple_instances { $short_msg_append = $message_separator; } - $obj->perfdata(extra_instance => $self->{multiple}); + if ($multiple_parent == 1 && $multiple == 0) { + $obj->perfdata(extra_instance => 1); + } else { + $obj->perfdata(extra_instance => $multiple); + } } my ($prefix_output, $suffix_output); @@ -428,7 +435,7 @@ sub run_multiple_instances { $suffix_output = '' if (!defined($suffix_output)); my $exit = $self->{output}->get_most_critical(status => [ @exits ]); - $self->{output}->output_add(long_msg => "${prefix_output}${long_msg}${suffix_output}") + $self->{output}->output_add(long_msg => "${indent_long_output}${prefix_output}${long_msg}${suffix_output}") if (!defined($options{config}->{display_long}) || $options{config}->{display_long} != 0); if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) { @@ -437,7 +444,7 @@ sub run_multiple_instances { ); } - if ($self->{multiple} == 0 && $multiple_parent == 0) { + if ($multiple == 0 && $multiple_parent == 0) { $self->run_multiple_prefix_output(severity => 'ok', short_msg => "${prefix_output}${long_msg}${suffix_output}"); } } @@ -479,14 +486,17 @@ sub run_multiple { $self->{prefix_multiple_output_done} = { ok => 0, warning => 0, critical => 0, unknown => 0 }; $self->{prefix_multiple_output} = $self->call_object_callback(method_name => $options{config}->{cb_prefix_output}, instance_value => $self->{$options{config}->{name}}->{$instance}) if (defined($options{config}->{cb_prefix_output})); + my $indent_long_output = ''; + $indent_long_output = $options{config}->{indent_long_output} + if (defined($options{config}->{indent_long_output})); foreach my $group (@{$options{config}->{group}}) { $self->{$group->{name}} = $self->{$options{config}->{name}}->{$instance}->{$group->{name}}; if ($group->{type} == 1) { - $self->run_multiple_instances(config => $group, multiple_parent => $multiple, instance_parent => $instance); + $self->run_multiple_instances(config => $group, multiple_parent => $multiple, instance_parent => $instance, indent_long_output => $indent_long_output); } elsif ($group->{type} == 0) { - $self->run_global(config => $group, multiple_parent => $multiple, called_multiple => 1, force_instance => $instance); + $self->run_global(config => $group, multiple_parent => $multiple, called_multiple => 1, force_instance => $instance, indent_long_output => $indent_long_output); } } }