diff --git a/apps/vmware/connector/mode/alarmdatacenter.pm b/apps/vmware/connector/mode/alarmdatacenter.pm index c82c08c02..965aa113d 100644 --- a/apps/vmware/connector/mode/alarmdatacenter.pm +++ b/apps/vmware/connector/mode/alarmdatacenter.pm @@ -27,7 +27,7 @@ use warnings; use centreon::plugins::misc; use centreon::plugins::statefile; -sub catalog_status_threshold { +sub custom_status_threshold { my ($self, %options) = @_; my $status = 'ok'; my $message; @@ -58,7 +58,8 @@ sub catalog_status_threshold { sub custom_status_output { my ($self, %options) = @_; - my $msg = sprintf("alarm [%s] [%s] [%s] [%s] %s/%s", + my $msg = sprintf( + 'alarm [%s] [%s] [%s] [%s] %s/%s', $self->{result_values}->{status}, $self->{result_values}->{type}, $self->{result_values}->{entity_name}, @@ -105,7 +106,7 @@ sub set_counters { { name => 'datacenter', type => 2, cb_prefix_output => 'prefix_datacenter_output', cb_long_output => 'datacenter_long_output', message_multiple => 'All datacenters are ok', group => [ { name => 'alarm', cb_init => 'alarm_reset', skipped_code => { -11 => 1 } }, - { name => 'dc_metrics', display => 0, skipped_code => { -11 => 1 } }, + { name => 'dc_metrics', display => 0, skipped_code => { -11 => 1 } } ] } ]; @@ -115,27 +116,29 @@ sub set_counters { key_values => [ { name => 'yellow' } ], output_template => '%s warning alarm(s) found(s)', perfdatas => [ - { label => 'total_alarm_warning', value => 'yellow', template => '%s', min => 0 }, - ], + { label => 'total_alarm_warning', template => '%s', min => 0 } + ] } }, { label => 'total-alarm-critical', nlabel => 'datacenter.alarms.critical.current.count', set => { key_values => [ { name => 'red' } ], output_template => '%s critical alarm(s) found(s)', perfdatas => [ - { label => 'total_alarm_critical', value => 'red', template => '%s', min => 0 }, - ], + { label => 'total_alarm_critical', template => '%s', min => 0 } + ] } - }, + } ]; $self->{maps_counters}->{alarm} = [ { label => 'status', threshold => 0, set => { - key_values => [ { name => 'entity_name' }, { name => 'status' }, - { name => 'time' }, { name => 'description' }, { name => 'name' }, { name => 'type' }, { name => 'since' } ], + key_values => [ + { name => 'entity_name' }, { name => 'status' }, + { name => 'time' }, { name => 'description' }, { name => 'name' }, { name => 'type' }, { name => 'since' } + ], closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => $self->can('custom_status_threshold') } }, ]; @@ -146,7 +149,7 @@ sub set_counters { output_template => '', closure_custom_threshold_check => sub { return 'ok' }, closure_custom_calc => $self->can('custom_dcmetrics_calc'), closure_custom_calc_extra_options => { label_ref => 'warning' }, - closure_custom_perfdata => $self->can('custom_dcmetrics_perfdata'), + closure_custom_perfdata => $self->can('custom_dcmetrics_perfdata') } }, { label => 'alarm-critical', threshold => 0, set => { @@ -154,9 +157,9 @@ sub set_counters { output_template => '', closure_custom_threshold_check => sub { return 'ok' }, closure_custom_calc => $self->can('custom_dcmetrics_calc'), closure_custom_calc_extra_options => { label_ref => 'critical' }, - closure_custom_perfdata => $self->can('custom_dcmetrics_perfdata'), + closure_custom_perfdata => $self->can('custom_dcmetrics_perfdata') } - }, + } ]; } diff --git a/apps/vmware/connector/mode/alarmhost.pm b/apps/vmware/connector/mode/alarmhost.pm index 07be989fd..372ff50da 100644 --- a/apps/vmware/connector/mode/alarmhost.pm +++ b/apps/vmware/connector/mode/alarmhost.pm @@ -27,7 +27,7 @@ use warnings; use centreon::plugins::misc; use centreon::plugins::statefile; -sub catalog_status_threshold { +sub custom_status_threshold { my ($self, %options) = @_; my $status = 'ok'; my $message; @@ -104,7 +104,7 @@ sub set_counters { { name => 'esxhost', type => 2, cb_prefix_output => 'prefix_esxhost_output', cb_long_output => 'esxhost_long_output', message_multiple => 'All hosts are ok', group => [ { name => 'alarm', cb_init => 'alarm_reset', skipped_code => { -11 => 1 } }, - { name => 'esxhost_metrics', display => 0, skipped_code => { -11 => 1 } }, + { name => 'esxhost_metrics', display => 0, skipped_code => { -11 => 1 } } ] } ]; @@ -114,18 +114,18 @@ sub set_counters { key_values => [ { name => 'yellow' } ], output_template => '%s warning alarm(s) found(s)', perfdatas => [ - { label => 'total_alarm_warning', value => 'yellow', template => '%s', min => 0 }, - ], + { label => 'total_alarm_warning', template => '%s', min => 0 } + ] } }, { label => 'total-alarm-critical', nlabel => 'host.alarms.critical.current.count', set => { key_values => [ { name => 'red' } ], output_template => '%s critical alarm(s) found(s)', perfdatas => [ - { label => 'total_alarm_critical', value => 'red', template => '%s', min => 0 }, - ], + { label => 'total_alarm_critical', template => '%s', min => 0 } + ] } - }, + } ]; $self->{maps_counters}->{alarm} = [ @@ -134,9 +134,9 @@ sub set_counters { { name => 'time' }, { name => 'description' }, { name => 'name' }, { name => 'type' }, { name => 'since' } ], closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => $self->can('custom_status_threshold') } - }, + } ]; $self->{maps_counters}->{esxhost_metrics} = [ @@ -145,7 +145,7 @@ sub set_counters { output_template => '', closure_custom_threshold_check => sub { return 'ok' }, closure_custom_calc => $self->can('custom_esxhost_calc'), closure_custom_calc_extra_options => { label_ref => 'warning' }, - closure_custom_perfdata => $self->can('custom_esxhost_perfdata'), + closure_custom_perfdata => $self->can('custom_esxhost_perfdata') } }, { label => 'alarm-critical', threshold => 0, set => { @@ -153,9 +153,9 @@ sub set_counters { output_template => '', closure_custom_threshold_check => sub { return 'ok' }, closure_custom_calc => $self->can('custom_esxhost_calc'), closure_custom_calc_extra_options => { label_ref => 'critical' }, - closure_custom_perfdata => $self->can('custom_esxhost_perfdata'), + closure_custom_perfdata => $self->can('custom_esxhost_perfdata') } - }, + } ]; } diff --git a/apps/vmware/connector/mode/countvmhost.pm b/apps/vmware/connector/mode/countvmhost.pm index 9e64cc18e..55f5656dd 100644 --- a/apps/vmware/connector/mode/countvmhost.pm +++ b/apps/vmware/connector/mode/countvmhost.pm @@ -24,7 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); sub custom_status_output { my ($self, %options) = @_; @@ -75,12 +75,14 @@ sub set_counters { ]; $self->{maps_counters}->{host} = [ - { label => 'status', threshold => 0, set => { + { + label => 'status', type => 2, unknown_default => '%{status} !~ /^connected$/i', + set => { key_values => [ { name => 'state' } ], closure_custom_calc => $self->can('custom_status_calc'), closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold + closure_custom_threshold_check => \&catalog_status_threshold_ng } }, { label => 'on', nlabel => 'host.vm.poweredon.current.count', set => { @@ -125,22 +127,12 @@ sub new { 'esx-hostname:s' => { name => 'esx_hostname' }, 'filter' => { name => 'filter' }, 'scope-datacenter:s' => { name => 'scope_datacenter' }, - 'scope-cluster:s' => { name => 'scope_cluster' }, - 'unknown-status:s' => { name => 'unknown_status', default => '%{status} !~ /^connected$/i' }, - 'warning-status:s' => { name => 'warning_status', default => '' }, - 'critical-status:s' => { name => 'critical_status', default => '' } + 'scope-cluster:s' => { name => 'scope_cluster' } }); return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); -} - sub manage_selection { my ($self, %options) = @_; diff --git a/apps/vmware/connector/mode/cpuhost.pm b/apps/vmware/connector/mode/cpuhost.pm index 08f9efa19..bc459b408 100644 --- a/apps/vmware/connector/mode/cpuhost.pm +++ b/apps/vmware/connector/mode/cpuhost.pm @@ -24,7 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); sub custom_status_output { my ($self, %options) = @_; @@ -48,20 +48,22 @@ sub set_counters { 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 } }, - { name => 'cpu', display_long => 0, cb_prefix_output => 'prefix_cpu_output', message_multiple => 'All CPUs are ok', type => 1, skipped_code => { -10 => 1 } }, + { name => 'cpu', display_long => 0, cb_prefix_output => 'prefix_cpu_output', message_multiple => 'All CPUs are ok', type => 1, skipped_code => { -10 => 1 } } ] } ]; $self->{maps_counters}->{global} = [ - { label => 'status', threshold => 0, set => { + { + label => 'status', type => 2, unknown_default => '%{status} !~ /^connected$/i', + set => { key_values => [ { name => 'state' } ], closure_custom_calc => $self->can('custom_status_calc'), closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold_ng } - }, + } ]; $self->{maps_counters}->{global_cpu} = [ @@ -69,20 +71,20 @@ sub set_counters { key_values => [ { name => 'cpu_average' } ], output_template => '%s %%', perfdatas => [ - { label => 'cpu_total', value => 'cpu_average', template => '%s', unit => '%', - min => 0, max => 100, label_extra_instance => 1 }, - ], + { label => 'cpu_total', template => '%s', unit => '%', + min => 0, max => 100, label_extra_instance => 1 } + ] } }, { label => 'total-cpu-mhz', nlabel => 'host.cpu.utilization.mhz', set => { key_values => [ { name => 'cpu_average_mhz' }, { name => 'cpu_average_mhz_max' } ], output_template => '%s MHz', perfdatas => [ - { label => 'cpu_total_MHz', value => 'cpu_average_mhz', template => '%s', unit => 'MHz', - min => 0, max => 'cpu_average_mhz_max', label_extra_instance => 1 }, - ], + { label => 'cpu_total_MHz', template => '%s', unit => 'MHz', + min => 0, max => 'cpu_average_mhz_max', label_extra_instance => 1 } + ] } - }, + } ]; $self->{maps_counters}->{cpu} = [ @@ -90,11 +92,11 @@ sub set_counters { key_values => [ { name => 'cpu_usage' }, { name => 'display' } ], output_template => 'usage : %s', perfdatas => [ - { label => 'cpu', value => 'cpu_usage', template => '%s', unit => '%', - min => 0, max => 100, label_extra_instance => 1 }, - ], + { label => 'cpu', template => '%s', unit => '%', + min => 0, max => 100, label_extra_instance => 1 } + ] } - }, + } ]; } @@ -131,19 +133,10 @@ sub new { "esx-hostname:s" => { name => 'esx_hostname' }, "filter" => { name => 'filter' }, "scope-datacenter:s" => { name => 'scope_datacenter' }, - "scope-cluster:s" => { name => 'scope_cluster' }, - "unknown-status:s" => { name => 'unknown_status', default => '%{status} !~ /^connected$/i' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '' }, + "scope-cluster:s" => { name => 'scope_cluster' } }); - return $self; -} -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); + return $self; } sub manage_selection { diff --git a/apps/vmware/connector/mode/cpuvm.pm b/apps/vmware/connector/mode/cpuvm.pm index 6c7712633..d406af463 100644 --- a/apps/vmware/connector/mode/cpuvm.pm +++ b/apps/vmware/connector/mode/cpuvm.pm @@ -24,7 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); sub custom_status_output { my ($self, %options) = @_; @@ -33,14 +33,6 @@ sub custom_status_output { return $msg; } -sub custom_status_calc { - my ($self, %options) = @_; - - $self->{result_values}->{connection_state} = $options{new_datas}->{$self->{instance} . '_connection_state'}; - $self->{result_values}->{power_state} = $options{new_datas}->{$self->{instance} . '_power_state'}; - return 0; -} - sub set_counters { my ($self, %options) = @_; @@ -49,20 +41,21 @@ sub set_counters { 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 } }, - { name => 'cpu', display_long => 0, cb_prefix_output => 'prefix_cpu_output', message_multiple => 'All CPUs are ok', type => 1, skipped_code => { -10 => 1 } }, + { name => 'cpu', display_long => 0, cb_prefix_output => 'prefix_cpu_output', message_multiple => 'All CPUs are ok', type => 1, skipped_code => { -10 => 1 } } ] } ]; $self->{maps_counters}->{global} = [ - { label => 'status', threshold => 0, set => { + { + label => 'status', type => 2, unknown_default => '%{connection_state} !~ /^connected$/i or %{power_state} !~ /^poweredOn$/i', + set => { key_values => [ { name => 'connection_state' }, { name => 'power_state' } ], - closure_custom_calc => $self->can('custom_status_calc'), closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold_ng } - }, + } ]; $self->{maps_counters}->{global_cpu} = [ @@ -70,29 +63,29 @@ sub set_counters { key_values => [ { name => 'cpu_average' } ], output_template => '%s %%', perfdatas => [ - { label => 'cpu_total', value => 'cpu_average', template => '%s', unit => '%', - min => 0, max => 100, label_extra_instance => 1 }, - ], + { label => 'cpu_total', template => '%s', unit => '%', + min => 0, max => 100, label_extra_instance => 1 } + ] } }, { label => 'total-cpu-mhz', nlabel => 'vm.cpu.utilization.mhz', set => { key_values => [ { name => 'cpu_average_mhz' } ], output_template => '%s MHz', perfdatas => [ - { label => 'cpu_total_MHz', value => 'cpu_average_mhz', template => '%s', unit => 'MHz', - min => 0, label_extra_instance => 1 }, - ], + { label => 'cpu_total_MHz', template => '%s', unit => 'MHz', + min => 0, label_extra_instance => 1 } + ] } }, { label => 'cpu-ready', nlabel => 'vm.cpu.ready.percentage', set => { key_values => [ { name => 'cpu_ready' } ], output_template => 'ready %s %%', perfdatas => [ - { label => 'cpu_ready', value => 'cpu_ready', template => '%s', unit => '%', - min => 0, max => 100, label_extra_instance => 1 }, - ], + { label => 'cpu_ready', template => '%s', unit => '%', + min => 0, max => 100, label_extra_instance => 1 } + ] } - }, + } ]; $self->{maps_counters}->{cpu} = [ @@ -100,11 +93,11 @@ sub set_counters { key_values => [ { name => 'cpu_usage' }, { name => 'display' } ], output_template => 'usage : %s MHz', perfdatas => [ - { label => 'cpu', value => 'cpu_usage', template => '%s', unit => 'MHz', - min => 0, label_extra_instance => 1 }, - ], + { label => 'cpu', template => '%s', unit => 'MHz', + min => 0, label_extra_instance => 1 } + ] } - }, + } ]; } @@ -149,36 +142,28 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "vm-hostname:s" => { name => 'vm_hostname' }, - "filter" => { name => 'filter' }, - "scope-datacenter:s" => { name => 'scope_datacenter' }, - "scope-cluster:s" => { name => 'scope_cluster' }, - "scope-host:s" => { name => 'scope_host' }, - "display-description" => { name => 'display_description' }, - "filter-description:s" => { name => 'filter_description' }, - "filter-os:s" => { name => 'filter_os' }, - "filter-uuid:s" => { name => 'filter_uuid' }, - "unknown-status:s" => { name => 'unknown_status', default => '%{connection_state} !~ /^connected$/i or %{power_state} !~ /^poweredOn$/i' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '' }, + 'vm-hostname:s' => { name => 'vm_hostname' }, + 'filter' => { name => 'filter' }, + 'scope-datacenter:s' => { name => 'scope_datacenter' }, + 'scope-cluster:s' => { name => 'scope_cluster' }, + 'scope-host:s' => { name => 'scope_host' }, + 'display-description' => { name => 'display_description' }, + 'filter-description:s' => { name => 'filter_description' }, + 'filter-os:s' => { name => 'filter_os' }, + 'filter-uuid:s' => { name => 'filter_uuid' } }); return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); -} - sub manage_selection { my ($self, %options) = @_; $self->{vm} = {}; - my $response = $options{custom}->execute(params => $self->{option_results}, - command => 'cpuvm'); + my $response = $options{custom}->execute( + params => $self->{option_results}, + command => 'cpuvm' + ); foreach my $vm_id (keys %{$response->{data}}) { my $vm_name = $response->{data}->{$vm_id}->{name}; diff --git a/apps/vmware/connector/mode/datastorecountvm.pm b/apps/vmware/connector/mode/datastorecountvm.pm index 72a95d4f3..3eecb2e3d 100644 --- a/apps/vmware/connector/mode/datastorecountvm.pm +++ b/apps/vmware/connector/mode/datastorecountvm.pm @@ -25,20 +25,12 @@ 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); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); 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; + return 'accessible ' . $self->{result_values}->{accessible}; } sub set_counters { @@ -46,7 +38,7 @@ sub set_counters { $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' }, + { name => 'datastore', type => 1, cb_prefix_output => 'prefix_datastore_output', message_multiple => 'All Datastores are ok' } ]; $self->{maps_counters}->{global} = [ @@ -54,67 +46,68 @@ sub set_counters { key_values => [ { name => 'poweredon' }, { name => 'total' } ], output_template => '%s VM(s) poweredon', perfdatas => [ - { label => 'poweredon', value => 'poweredon', template => '%s', - min => 0, max => 'total' }, - ], + { label => 'poweredon', template => '%s', + min => 0, max => 'total' } + ] } }, { label => 'total-off', nlabel => 'datastore.vm.poweredoff.current.count', set => { key_values => [ { name => 'poweredoff' }, { name => 'total' } ], output_template => '%s VM(s) poweredoff', perfdatas => [ - { label => 'poweredoff', value => 'poweredoff', template => '%s', - min => 0, max => 'total' }, - ], + { label => 'poweredoff', template => '%s', + min => 0, max => 'total' } + ] } }, { label => 'total-suspended', nlabel => 'datastore.vm.suspended.current.count', set => { key_values => [ { name => 'suspended' }, { name => 'total' } ], output_template => '%s VM(s) suspended', perfdatas => [ - { label => 'suspended', value => 'suspended', template => '%s', - min => 0, max => 'total' }, - ], + { label => 'suspended', template => '%s', + min => 0, max => 'total' } + ] } - }, + } ]; $self->{maps_counters}->{datastore} = [ - { label => 'status', threshold => 0, set => { + { + label => 'status', type => 2, unknown_default => '%{accessible} !~ /^true|1$/i', + 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, + closure_custom_threshold_check => \&catalog_status_threshold_ng } }, { label => 'on', nlabel => 'datastore.vm.poweredon.current.count', set => { key_values => [ { name => 'poweredon' }, { name => 'total' } ], output_template => '%s VM(s) poweredon', perfdatas => [ - { label => 'poweredon', value => 'poweredon', template => '%s', - min => 0, max => 'total', label_extra_instance => 1 }, - ], + { label => 'poweredon', template => '%s', + min => 0, max => 'total', label_extra_instance => 1 } + ] } }, { label => 'off', nlabel => 'datastore.vm.poweredoff.current.count', set => { key_values => [ { name => 'poweredoff' }, { name => 'total' } ], output_template => '%s VM(s) poweredoff', perfdatas => [ - { label => 'poweredoff', value => 'poweredoff', template => '%s', - min => 0, max => 'total', label_extra_instance => 1 }, - ], + { label => 'poweredoff', template => '%s', + min => 0, max => 'total', label_extra_instance => 1 } + ] } }, { label => 'suspended', nlabel => 'datastore.vm.suspended.current.count', set => { key_values => [ { name => 'suspended' }, { name => 'total' } ], output_template => '%s VM(s) suspended', perfdatas => [ - { label => 'suspended', value => 'suspended', template => '%s', - min => 0, max => 'total', label_extra_instance => 1 }, - ], + { label => 'suspended', template => '%s', + min => 0, max => 'total', label_extra_instance => 1 } + ] } - }, + } ]; } @@ -130,31 +123,23 @@ sub new { bless $self, $class; $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 => '' }, + 'datastore-name:s' => { name => 'datastore_name' }, + 'filter' => { name => 'filter' }, + 'scope-datacenter:s' => { name => 'scope_datacenter' } }); return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); -} - sub manage_selection { my ($self, %options) = @_; $self->{global} = { poweredon => 0, poweredoff => 0, suspended => 0, total => 0 }; $self->{datastore} = {}; - my $response = $options{custom}->execute(params => $self->{option_results}, - command => 'datastorecountvm'); + 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}; diff --git a/apps/vmware/connector/mode/datastorehost.pm b/apps/vmware/connector/mode/datastorehost.pm index 0e25fdd74..91ee393d8 100644 --- a/apps/vmware/connector/mode/datastorehost.pm +++ b/apps/vmware/connector/mode/datastorehost.pm @@ -25,13 +25,12 @@ 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); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); 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 { @@ -48,20 +47,22 @@ sub set_counters { { 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 } }, + { 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 => { + { + label => 'status', type => 2, unknown_default => '%{status} !~ /^connected$/i', + set => { key_values => [ { name => 'state' } ], closure_custom_calc => $self->can('custom_status_calc'), closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold_ng } - }, + } ]; $self->{maps_counters}->{datastore} = [ @@ -69,20 +70,20 @@ sub set_counters { key_values => [ { name => 'read_latency' }, { name => 'display' } ], output_template => 'read : %s ms', perfdatas => [ - { label => 'trl', value => 'read_latency', template => '%s', unit => 'ms', - min => 0, label_extra_instance => 1 }, - ], + { label => 'trl', template => '%s', unit => 'ms', + min => 0, label_extra_instance => 1 } + ] } }, { label => 'write-latency', nlabel => 'host.datastore.latency.write.milliseconds', set => { key_values => [ { name => 'write_latency' }, { name => 'display' } ], output_template => 'write : %s ms', perfdatas => [ - { label => 'twl', value => 'write_latency', template => '%s', unit => 'ms', - min => 0, label_extra_instance => 1 }, - ], + { label => 'twl', template => '%s', unit => 'ms', + min => 0, label_extra_instance => 1 } + ] } - }, + } ]; } @@ -110,33 +111,25 @@ sub new { bless $self, $class; $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 => '' }, + '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' } }); return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); -} - sub manage_selection { my ($self, %options) = @_; $self->{host} = {}; - my $response = $options{custom}->execute(params => $self->{option_results}, - command => 'datastorehost'); + 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}; diff --git a/apps/vmware/connector/mode/datastoreio.pm b/apps/vmware/connector/mode/datastoreio.pm index b8db9e28a..036e7e335 100644 --- a/apps/vmware/connector/mode/datastoreio.pm +++ b/apps/vmware/connector/mode/datastoreio.pm @@ -24,20 +24,12 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); 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; + return 'accessible ' . $self->{result_values}->{accessible}; } sub set_counters { @@ -45,7 +37,7 @@ sub set_counters { $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' }, + { name => 'datastore', type => 1, cb_prefix_output => 'prefix_datastore_output', message_multiple => 'All datastores are ok' } ]; $self->{maps_counters}->{global} = [ @@ -54,9 +46,9 @@ sub set_counters { output_template => 'Total rate of reading data: %s %s/s', output_change_bytes => 1, perfdatas => [ - { label => 'total_read_rate', value => 'read', template => '%s', - unit => 'B/s', min => 0 }, - ], + { label => 'total_read_rate', template => '%s', + unit => 'B/s', min => 0 } + ] } }, { label => 'total-write', nlabel => 'datastore.write.usage.bytespersecond', set => { @@ -64,20 +56,21 @@ sub set_counters { output_template => 'Total rate of writing data: %s %s/s', output_change_bytes => 1, perfdatas => [ - { label => 'total_write_rate', value => 'write', template => '%s', - unit => 'B/s', min => 0 }, - ], + { label => 'total_write_rate', template => '%s', + unit => 'B/s', min => 0 } + ] } - }, + } ]; $self->{maps_counters}->{datastore} = [ - { label => 'status', threshold => 0, set => { + { + label => 'status', type => 2, unknown_default => '%{accessible} !~ /^true|1$/i', + 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, + closure_custom_threshold_check => \&catalog_status_threshold_ng } }, { label => 'read', nlabel => 'datastore.read.usage.bytespersecond', set => { @@ -85,9 +78,9 @@ sub set_counters { output_template => 'rate of reading data: %s %s/s', output_change_bytes => 1, perfdatas => [ - { label => 'read_rate', value => 'read', template => '%s', - unit => 'B/s', min => 0, label_extra_instance => 1 }, - ], + { label => 'read_rate', template => '%s', + unit => 'B/s', min => 0, label_extra_instance => 1 } + ] } }, { label => 'write', nlabel => 'datastore.write.usage.bytespersecond', set => { @@ -95,11 +88,11 @@ sub set_counters { output_template => 'rate of writing data: %s %s/s', output_change_bytes => 1, perfdatas => [ - { label => 'write_rate', value => 'write', template => '%s', - unit => 'B/s', min => 0, label_extra_instance => 1 }, - ], + { label => 'write_rate', template => '%s', + unit => 'B/s', min => 0, label_extra_instance => 1 } + ] } - }, + } ]; } @@ -115,22 +108,12 @@ sub new { bless $self, $class; $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 => '' }, + 'datastore-name:s' => { name => 'datastore_name' }, + 'filter' => { name => 'filter' }, + 'scope-datacenter:s' => { name => 'scope_datacenter' } }); - - return $self; -} -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); + return $self; } sub manage_selection { @@ -138,8 +121,10 @@ sub manage_selection { $self->{global} = { read => 0, write => 0 }; $self->{datastore} = {}; - my $response = $options{custom}->execute(params => $self->{option_results}, - command => 'datastoreio'); + 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}; diff --git a/apps/vmware/connector/mode/datastoreiops.pm b/apps/vmware/connector/mode/datastoreiops.pm index 776cfae85..b95044430 100644 --- a/apps/vmware/connector/mode/datastoreiops.pm +++ b/apps/vmware/connector/mode/datastoreiops.pm @@ -25,20 +25,12 @@ 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); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); 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; + return 'accessible ' . $self->{result_values}->{accessible}; } sub set_counters { @@ -49,20 +41,21 @@ sub set_counters { 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 } }, + { 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 => { + { + label => 'status', type => 2, unknown_default => '%{accessible} !~ /^true|1$/i', + 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, + closure_custom_threshold_check => \&catalog_status_threshold_ng } - }, + } ]; $self->{maps_counters}->{global_iops} = [ @@ -70,20 +63,20 @@ sub set_counters { key_values => [ { name => 'read' } ], output_template => '%s read iops', perfdatas => [ - { label => 'riops', value => 'read', template => '%s', unit => 'iops', - min => 0, label_extra_instance => 1 }, - ], + { label => 'riops', template => '%s', unit => 'iops', + min => 0, label_extra_instance => 1 } + ] } }, { label => 'write', nlabel => 'datastore.write.usage.iops', set => { key_values => [ { name => 'write' } ], output_template => '%s write iops', perfdatas => [ - { label => 'wiops', value => 'write', template => '%s', unit => 'iops', - min => 0, max => 'write', label_extra_instance => 1 }, - ], + { label => 'wiops', template => '%s', unit => 'iops', + min => 0, label_extra_instance => 1 } + ] } - }, + } ]; $self->{maps_counters}->{vm} = [ @@ -91,20 +84,20 @@ sub set_counters { key_values => [ { name => 'read' } ], output_template => '%s read iops', perfdatas => [ - { label => 'vm_riops', value => 'read', template => '%s', unit => 'iops', - min => 0, label_extra_instance => 1 }, - ], + { label => 'vm_riops', template => '%s', unit => 'iops', + min => 0, label_extra_instance => 1 } + ] } }, { label => 'write-vm', nlabel => 'datastore.vm.write.usage.iops', set => { key_values => [ { name => 'write' } ], output_template => '%s write iops', perfdatas => [ - { label => 'vm_wiops', value => 'write', template => '%s', unit => 'iops', - min => 0, max => 'write', label_extra_instance => 1 }, - ], + { label => 'vm_wiops', template => '%s', unit => 'iops', + min => 0, label_extra_instance => 1 } + ] } - }, + } ]; } @@ -130,25 +123,15 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $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::check_options(%options); - - $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); + $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 } + }); + + return $self; } sub manage_selection { diff --git a/apps/vmware/connector/mode/datastoresnapshot.pm b/apps/vmware/connector/mode/datastoresnapshot.pm index 0055afb9f..6fbc19a9e 100644 --- a/apps/vmware/connector/mode/datastoresnapshot.pm +++ b/apps/vmware/connector/mode/datastoresnapshot.pm @@ -25,20 +25,12 @@ 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); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); 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; + return 'accessible ' . $self->{result_values}->{accessible}; } sub set_counters { @@ -49,20 +41,21 @@ sub set_counters { group => [ { name => 'global', type => 0, skipped_code => { -10 => 1 } }, { name => 'global_snapshot', type => 0, skipped_code => { -10 => 1 } }, - { name => 'files', cb_prefix_output => 'prefix_files_output', message_multiple => 'All snapshot files are ok', type => 1, skipped_code => { -10 => 1 } }, + { name => 'files', cb_prefix_output => 'prefix_files_output', message_multiple => 'All snapshot files are ok', type => 1, skipped_code => { -10 => 1 } } ] } ]; $self->{maps_counters}->{global} = [ - { label => 'status', threshold => 0, set => { + { + label => 'status', type => 2, unknown_default => '%{accessible} !~ /^true|1$/i', + 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, + closure_custom_threshold_check => \&catalog_status_threshold_ng } - }, + } ]; $self->{maps_counters}->{global_snapshot} = [ @@ -71,21 +64,21 @@ sub set_counters { output_template => 'total snapshots [size = %s %s]', output_change_bytes => 1, perfdatas => [ - { label => 'total_size', value => 'total', template => '%s', unit => 'B', - min => 0, label_extra_instance => 1 }, - ], + { label => 'total_size', template => '%s', unit => 'B', + min => 0, label_extra_instance => 1 } + ] } - }, + } ]; $self->{maps_counters}->{files} = [ { label => 'snapshot', nlabel => 'datastore.snapshot.usage.bytes', set => { - key_values => [ { name => 'total' } ], + key_values => [ { name => 'total' } ] output_template => '[size = %s %s]', output_change_bytes => 1, - closure_custom_perfdata => sub { return 0; }, + closure_custom_perfdata => sub { return 0; } } - }, + } ]; } @@ -111,32 +104,24 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $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::check_options(%options); - - $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); + $options{options}->add_options(arguments => { + 'datastore-name:s' => { name => 'datastore_name' }, + 'filter' => { name => 'filter' }, + 'scope-datacenter:s' => { name => 'scope_datacenter' } + }); + + return $self; } sub manage_selection { my ($self, %options) = @_; $self->{datastore} = {}; - my $response = $options{custom}->execute(params => $self->{option_results}, - command => 'datastoresnapshot'); + my $response = $options{custom}->execute( + params => $self->{option_results}, + command => 'datastoresnapshot' + ); my $i = 0; foreach my $ds_id (keys %{$response->{data}}) { @@ -148,14 +133,14 @@ sub manage_selection { }, global_snapshot => { total => 0 - }, + } }; foreach (@{$response->{data}->{$ds_id}->{snapshost}}) { $self->{datastore}->{$ds_name}->{files}->{$i} = { folder_path => $_->{folder_path}, path => $_->{path}, - total => $_->{size}, + total => $_->{size} }; $self->{datastore}->{$ds_name}->{global_snapshot}->{total} += $_->{size}; $i++; diff --git a/apps/vmware/connector/mode/datastoreusage.pm b/apps/vmware/connector/mode/datastoreusage.pm index c03815b50..d7eebf783 100644 --- a/apps/vmware/connector/mode/datastoreusage.pm +++ b/apps/vmware/connector/mode/datastoreusage.pm @@ -24,13 +24,12 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); sub custom_status_output { my ($self, %options) = @_; - my $msg = 'accessible ' . $self->{result_values}->{accessible}; - return $msg; + return 'accessible ' . $self->{result_values}->{accessible}; } sub custom_usage_output { @@ -85,38 +84,40 @@ sub set_counters { ]; $self->{maps_counters}->{datastore} = [ - { label => 'status', threshold => 0, set => { + { + label => 'status', type => 2, unknown_default => '%{accessible} !~ /^true|1$/i', + set => { key_values => [ { name => 'accessible' }, { name => 'display' } ], closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold_ng } }, { label => 'usage', nlabel => 'datastore.space.usage.bytes', set => { key_values => [ { name => 'used_space' }, { name => 'free_space' }, { name => 'prct_used_space' }, { name => 'prct_free_space' }, { name => 'total_space' }, { name => 'display' }, ], closure_custom_output => $self->can('custom_usage_output'), perfdatas => [ - { label => 'used', value => 'used_space', template => '%d', min => 0, max => 'total_space', - unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display' }, - ], + { label => 'used', template => '%d', min => 0, max => 'total_space', + unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display' } + ] } }, { label => 'usage-free', nlabel => 'datastore.space.free.bytes', display_ok => 0, set => { key_values => [ { name => 'free_space' }, { name => 'used_space' }, { name => 'prct_used_space' }, { name => 'prct_free_space' }, { name => 'total_space' }, { name => 'display' }, ], closure_custom_output => $self->can('custom_usage_output'), perfdatas => [ - { label => 'free', value => 'free_space', template => '%d', min => 0, max => 'total_space', - unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display' }, - ], + { label => 'free', template => '%d', min => 0, max => 'total_space', + unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display' } + ] } }, { label => 'usage-prct', nlabel => 'datastore.space.usage.percentage', display_ok => 0, set => { key_values => [ { name => 'prct_used_space' }, { name => 'display' } ], - output_template => 'used : %.2f %%', + output_template => 'used: %.2f %%', perfdatas => [ - { label => 'used_prct', value => 'prct_used_space', template => '%.2f', min => 0, max => 100, - unit => '%', label_extra_instance => 1, instance_use => 'display' }, - ], + { label => 'used_prct', template => '%.2f', min => 0, max => 100, + unit => '%', label_extra_instance => 1, instance_use => 'display' } + ] } }, { label => 'provisioned', nlabel => 'datastore.space.provisioned.bytes', set => { @@ -126,8 +127,8 @@ sub set_counters { threshold_use => 'prct_uncommitted', perfdatas => [ { label => 'provisioned', value => 'total_uncommitted', template => '%s', unit => 'B', - min => 0, max => 'total_space', label_extra_instance => 1 }, - ], + min => 0, max => 'total_space', label_extra_instance => 1 } + ] } } ]; @@ -149,12 +150,9 @@ sub new { 'filter' => { name => 'filter' }, 'scope-datacenter:s' => { name => 'scope_datacenter' }, 'units:s' => { name => 'units', default => '%' }, - 'free' => { name => 'free' }, - '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 => '' } + 'free' => { name => 'free' } }); - + return $self; } @@ -175,7 +173,6 @@ sub check_options { $self->SUPER::check_options(%options); - $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); if (!defined($self->{option_results}->{units}) || $self->{option_results}->{units} !~ /^(%|B)$/) { $self->{output}->add_option_msg(short_msg => "Wrong units option '" . $self->{option_results}->{units} . "'."); $self->{output}->option_exit(); diff --git a/apps/vmware/connector/mode/datastorevm.pm b/apps/vmware/connector/mode/datastorevm.pm index 6f74e6646..f64851aba 100644 --- a/apps/vmware/connector/mode/datastorevm.pm +++ b/apps/vmware/connector/mode/datastorevm.pm @@ -25,13 +25,12 @@ 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); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); sub custom_status_output { my ($self, %options) = @_; - my $msg = '[connection state ' . $self->{result_values}->{connection_state} . '][power state ' . $self->{result_values}->{power_state} . ']'; - return $msg; + return '[connection state ' . $self->{result_values}->{connection_state} . '][power state ' . $self->{result_values}->{power_state} . ']'; } sub set_counters { @@ -42,19 +41,21 @@ sub set_counters { group => [ { name => 'global', type => 0, skipped_code => { -10 => 1 } }, { name => 'global_vm', type => 0, skipped_code => { -10 => 1 } }, - { name => 'datastore', cb_prefix_output => 'prefix_datastore_output', message_multiple => 'All datastores are ok', type => 1, skipped_code => { -10 => 1 } }, + { name => 'datastore', cb_prefix_output => 'prefix_datastore_output', message_multiple => 'All datastores are ok', type => 1, skipped_code => { -10 => 1 } } ] } ]; $self->{maps_counters}->{global} = [ - { label => 'status', threshold => 0, set => { + { + label => 'status', type => 2, unknown_default => '%{connection_state} !~ /^connected$/i or %{power_state} !~ /^poweredOn$/i', + set => { key_values => [ { name => 'connection_state' }, { name => 'power_state' } ], closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold_ng } - }, + } ]; $self->{maps_counters}->{global_vm} = [ @@ -62,11 +63,11 @@ sub set_counters { key_values => [ { name => 'total_latency' } ], output_template => 'max total latency is %s ms', perfdatas => [ - { label => 'max_total_latency', value => 'total_latency', template => '%s', unit => 'ms', - min => 0, label_extra_instance => 1 }, - ], + { label => 'max_total_latency', template => '%s', unit => 'ms', + min => 0, label_extra_instance => 1 } + ] } - }, + } ]; $self->{maps_counters}->{datastore} = [ @@ -74,20 +75,20 @@ sub set_counters { key_values => [ { name => 'read' } ], output_template => '%s read iops', perfdatas => [ - { label => 'riops', value => 'read', template => '%s', unit => 'iops', - min => 0, label_extra_instance => 1 }, - ], + { label => 'riops', template => '%s', unit => 'iops', + min => 0, label_extra_instance => 1 } + ] } }, { label => 'write', nlabel => 'vm.datastore.write.usage.iops', set => { key_values => [ { name => 'write' } ], output_template => '%s write iops', perfdatas => [ - { label => 'wiops', value => 'write', template => '%s', unit => 'iops', - min => 0, max => 'write', label_extra_instance => 1 }, - ], + { label => 'wiops', template => '%s', unit => 'iops', + min => 0, max => 'write', label_extra_instance => 1 } + ] } - }, + } ]; } @@ -99,7 +100,7 @@ sub prefix_vm_output { $msg .= ' [annotation: ' . $options{instance_value}->{config_annotation} . ']'; } $msg .= ' : '; - + return $msg; } @@ -110,7 +111,7 @@ sub vm_long_output { if (defined($options{instance_value}->{config_annotation})) { $msg .= ' [annotation: ' . $options{instance_value}->{config_annotation} . ']'; } - + return $msg; } @@ -124,7 +125,7 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - + $options{options}->add_options(arguments => { 'vm-hostname:s' => { name => 'vm_hostname' }, 'filter' => { name => 'filter' }, @@ -136,22 +137,12 @@ sub new { 'filter-uuid:s' => { name => 'filter_uuid' }, 'display-description' => { name => 'display_description' }, 'datastore-name:s' => { name => 'datastore_name' }, - 'filter-datastore:s' => { name => 'filter_datastore' }, - 'unknown-status:s' => { name => 'unknown_status', default => '%{connection_state} !~ /^connected$/i or %{power_state} !~ /^poweredOn$/i' }, - 'warning-status:s' => { name => 'warning_status', default => '' }, - 'critical-status:s' => { name => 'critical_status', default => '' }, + 'filter-datastore:s' => { name => 'filter_datastore' } }); - + return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); -} - sub manage_selection { my ($self, %options) = @_; @@ -172,7 +163,7 @@ sub manage_selection { foreach my $vm_id (keys %{$response->{data}}) { my $vm_name = $response->{data}->{$vm_id}->{name}; - + $self->{vm}->{$vm_name} = { display => $vm_name, datastore => {}, global => { @@ -181,7 +172,7 @@ sub manage_selection { }, global_vm => { total_latency => $response->{data}->{$vm_id}->{'disk.maxTotalLatency.latest'}, - }, + } }; if (defined($self->{option_results}->{display_description})) { diff --git a/apps/vmware/connector/mode/devicevm.pm b/apps/vmware/connector/mode/devicevm.pm index 3693db2da..52981d2f8 100644 --- a/apps/vmware/connector/mode/devicevm.pm +++ b/apps/vmware/connector/mode/devicevm.pm @@ -24,20 +24,18 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); sub custom_status_output { my ($self, %options) = @_; - my $msg = '[connection state ' . $self->{result_values}->{connection_state} . '][power state ' . $self->{result_values}->{power_state} . ']'; - return $msg; + return '[connection state ' . $self->{result_values}->{connection_state} . '][power state ' . $self->{result_values}->{power_state} . ']'; } sub custom_device_output { my ($self, %options) = @_; - my $msg = sprintf("%s %s device connected", $self->{result_values}->{device_connected}, $self->{instance_mode}->{option_results}->{device}); - return $msg; + return sprintf("%s %s device connected", $self->{result_values}->{device_connected}, $self->{instance_mode}->{option_results}->{device}); } sub set_counters { @@ -45,7 +43,7 @@ sub set_counters { $self->{maps_counters_type} = [ { name => 'global', type => 0, skipped_code => { -10 => 1 } }, - { name => 'vm', type => 1, cb_prefix_output => 'prefix_vm_output', message_multiple => 'All virtual machines are ok' }, + { name => 'vm', type => 1, cb_prefix_output => 'prefix_vm_output', message_multiple => 'All virtual machines are ok' } ]; $self->{maps_counters}->{global} = [ @@ -53,30 +51,32 @@ sub set_counters { key_values => [ { name => 'device_connected' } ], closure_custom_output => $self->can('custom_device_output'), perfdatas => [ - { label => 'total_device_connected', value => 'device_connected', template => '%s', - min => 0 }, - ], + { label => 'total_device_connected', template => '%s', + min => 0 } + ] } - }, + } ]; $self->{maps_counters}->{vm} = [ - { label => 'status', threshold => 0, set => { + { + label => 'status', type => 2, unknown_default => '%{connection_state} !~ /^connected$/i', + set => { key_values => [ { name => 'connection_state' }, { name => 'power_state' } ], closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold_ng } }, { label => 'device-connected', nlabel => 'vm.devices.connected.count', set => { key_values => [ { name => 'device_connected' }, { name => 'display' } ], oclosure_custom_output => $self->can('custom_device_output'), perfdatas => [ - { label => 'device_connected', value => 'device_connected', template => '%s', - min => 0, label_extra_instance => 1 }, - ], + { label => 'device_connected', template => '%s', + min => 0, label_extra_instance => 1 } + ] } - }, + } ]; } @@ -88,7 +88,7 @@ sub prefix_vm_output { $msg .= ' [annotation: ' . $options{instance_value}->{config_annotation} . ']'; } $msg .= ' : '; - + return $msg; } @@ -96,7 +96,7 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - + $options{options}->add_options(arguments => { "vm-hostname:s" => { name => 'vm_hostname' }, "filter" => { name => 'filter' }, @@ -107,10 +107,7 @@ sub new { "filter-os:s" => { name => 'filter_os' }, "filter-uuid:s" => { name => 'filter_uuid' }, "display-description" => { name => 'display_description' }, - "device:s" => { name => 'device' }, - "unknown-status:s" => { name => 'unknown_status', default => '%{connection_state} !~ /^connected$/i' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '' }, + "device:s" => { name => 'device' } }); return $self; @@ -119,10 +116,9 @@ sub new { sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); + if (!defined($self->{option_results}->{device}) || $self->{option_results}->{device} eq '') { - $self->{output}->add_option_msg(short_msg => "Please set device option."); + $self->{output}->add_option_msg(short_msg => 'Please set device option.'); $self->{output}->option_exit(); } } @@ -132,8 +128,10 @@ sub manage_selection { $self->{global} = { device_connected => 0 }; $self->{vm} = {}; - my $response = $options{custom}->execute(params => $self->{option_results}, - command => 'devicevm'); + my $response = $options{custom}->execute( + params => $self->{option_results}, + command => 'devicevm' + ); foreach my $vm_id (keys %{$response->{data}}) { my $vm_name = $response->{data}->{$vm_id}->{name}; @@ -141,13 +139,13 @@ sub manage_selection { display => $vm_name, connection_state => $response->{data}->{$vm_id}->{connection_state}, power_state => $response->{data}->{$vm_id}->{power_state}, - device_connected => $response->{data}->{$vm_id}->{total_device_connected}, + device_connected => $response->{data}->{$vm_id}->{total_device_connected} }; - + if (defined($self->{option_results}->{display_description})) { $self->{vm}->{$vm_name}->{config_annotation} = $options{custom}->strip_cr(value => $response->{data}->{$vm_id}->{'config.annotation'}); } - + $self->{global}->{device_connected} += $self->{vm}->{$vm_name}->{device_connected}; } } diff --git a/apps/vmware/connector/mode/healthhost.pm b/apps/vmware/connector/mode/healthhost.pm index ad7254413..ff578d445 100644 --- a/apps/vmware/connector/mode/healthhost.pm +++ b/apps/vmware/connector/mode/healthhost.pm @@ -24,13 +24,12 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); 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 { @@ -61,7 +60,7 @@ sub set_counters { group => [ { name => 'global_host', type => 0, skipped_code => { -10 => 1 } }, { name => 'global_problems', type => 0, skipped_code => { -10 => 1 } }, - { name => 'global_summary', type => 1 }, + { name => 'global_summary', type => 1 } ] } ]; @@ -71,22 +70,24 @@ sub set_counters { key_values => [ { name => 'total_problems' }, { name => 'total' } ], output_template => '%s total health issue(s) found', perfdatas => [ - { label => 'total_problems', value => 'total_problems', template => '%s', - min => 0, max => 'total' }, - ], + { label => 'total_problems', template => '%s', + min => 0, max => 'total' } + ] } - }, + } ]; $self->{maps_counters}->{global_host} = [ - { label => 'status', threshold => 0, set => { + { + label => 'status', type => 2, unknown_default => '%{status} !~ /^connected$/i', + set => { key_values => [ { name => 'state' } ], closure_custom_calc => $self->can('custom_status_calc'), closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold_ng } - }, + } ]; $self->{maps_counters}->{global_problems} = [ @@ -100,27 +101,27 @@ sub set_counters { key_values => [ { name => 'total_problems' }, { name => 'total' } ], output_template => '%s total health issue(s) found', perfdatas => [ - { label => 'problems', value => 'total_problems', template => '%s', - min => 0, max => 'total', label_extra_instance => 1 }, - ], + { label => 'problems', template => '%s', + min => 0, max => 'total', label_extra_instance => 1 } + ] } }, { label => 'problems-yellow', nlabel => 'host.health.yellow.current.count', set => { key_values => [ { name => 'yellow' }, { name => 'total' } ], output_template => '%s yellow health issue(s) found', perfdatas => [ - { label => 'problems_yellow', value => 'yellow', template => '%s', - min => 0, max => 'total', label_extra_instance => 1 }, - ], + { label => 'problems_yellow', template => '%s', + min => 0, max => 'total', label_extra_instance => 1 } + ] } }, { label => 'problems-red', nlabel => 'host.health.red.current.count', set => { key_values => [ { name => 'red' }, { name => 'total' } ], output_template => '%s red health issue(s) found', perfdatas => [ - { label => 'problems_red', value => 'red', template => '%s', - min => 0, max => 'total', label_extra_instance => 1 }, - ], + { label => 'problems_red', template => '%s', + min => 0, max => 'total', label_extra_instance => 1 } + ] } }, ]; @@ -129,9 +130,9 @@ sub set_counters { { label => 'global-summary', threshold => 0, set => { key_values => [ { name => 'type' }, { name => 'name' }, { name => 'summary' } ], closure_custom_output => $self->can('custom_summary_output'), - closure_custom_perfdata => sub { return 0; }, + closure_custom_perfdata => sub { return 0; } } - }, + } ]; } @@ -163,26 +164,16 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $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' }, - "storage-status" => { name => 'storage_status' }, - "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::check_options(%options); - - $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); + $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' }, + 'storage-status' => { name => 'storage_status' } + }); + + return $self; } sub manage_selection { @@ -190,8 +181,10 @@ sub manage_selection { $self->{global} = { total_problems => 0, total => 0 }; $self->{host} = {}; - my $response = $options{custom}->execute(params => $self->{option_results}, - command => 'healthhost'); + my $response = $options{custom}->execute( + params => $self->{option_results}, + command => 'healthhost' + ); foreach my $host_id (keys %{$response->{data}}) { my $host_name = $response->{data}->{$host_id}->{name}; @@ -201,8 +194,8 @@ sub manage_selection { }, global_summary => {}, global_problems => { - ok => 0, total_problems => 0, red => 0, yellow => 0, total => 0, - }, + ok => 0, total_problems => 0, red => 0, yellow => 0, total => 0 + } }; my $i = 0; @@ -219,7 +212,7 @@ sub manage_selection { $self->{host}->{$host_name}->{global_summary}->{$i} = { type => defined($entry->{type}) ? $entry->{type} : '', name => $entry->{name}, - summary => $entry->{summary}, + summary => $entry->{summary} }; } } @@ -227,7 +220,7 @@ sub manage_selection { $i++; } } - + $self->{global}->{total_problems} += $self->{host}->{$host_name}->{global_problems}->{red} + $self->{host}->{$host_name}->{global_problems}->{yellow}; $self->{global}->{total} += $self->{host}->{$host_name}->{global_problems}->{total}; } diff --git a/apps/vmware/connector/mode/limitvm.pm b/apps/vmware/connector/mode/limitvm.pm index ba1450052..94634f8d9 100644 --- a/apps/vmware/connector/mode/limitvm.pm +++ b/apps/vmware/connector/mode/limitvm.pm @@ -24,7 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); sub custom_limit_output { my ($self, %options) = @_; @@ -47,7 +47,7 @@ sub custom_limit_calc { $self->{result_values}->{connection_state} = $options{new_datas}->{$self->{instance} . '_connection_state'}; $self->{result_values}->{power_state} = $options{new_datas}->{$self->{instance} . '_power_state'}; $self->{result_values}->{name} = $options{new_datas}->{$self->{instance} . '_name'}; - + return 0; } @@ -63,38 +63,46 @@ sub set_counters { }, { name => 'disk_alarms', type => 2, cb_long_output => 'disk_long_output', message_multiple => '0 disk limit problem(s) detected', format_output => '%s disk limit problem(s) detected', display_counter_problem => { label => 'disk_alerts', nlabel => 'vm.limit.disk.alerts.count', min => 0 }, group => [ { name => 'disk_alarm', cb_prefix_output => 'prefix_vm_output', skipped_code => { -11 => 1 } } ] - }, + } ]; $self->{maps_counters}->{cpu_alarm} = [ - { label => 'cpu-status', threshold => 0, set => { + { + label => 'cpu-status', type => 2, critical_default => '%{connection_state} !~ /^connected$/i || %{limit} != -1', + set => { key_values => [ { name => 'name' }, { name => 'connection_state' }, { name => 'power_state' }, { name => 'cpu_limit' } ], closure_custom_calc => $self->can('custom_limit_calc'), closure_custom_calc_extra_options => { label_ref => 'cpu' }, closure_custom_output => $self->can('custom_limit_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold_ng } - }, + } ]; + $self->{maps_counters}->{memory_alarm} = [ - { label => 'memory-status', threshold => 0, set => { + { + label => 'memory-status', type => 2, critical_default => '%{connection_state} !~ /^connected$/i || %{limit} != -1', + set => { key_values => [ { name => 'name' }, { name => 'connection_state' }, { name => 'power_state' }, { name => 'memory_limit' } ], closure_custom_calc => $self->can('custom_limit_calc'), closure_custom_calc_extra_options => { label_ref => 'memory' }, closure_custom_output => $self->can('custom_limit_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold_ng } - }, + } ]; + $self->{maps_counters}->{disk_alarm} = [ - { label => 'disk-status', threshold => 0, set => { + { + label => 'disk-status', type => 2, critical_default => '%{connection_state} !~ /^connected$/i || %{limit} != -1', + set => { key_values => [ { name => 'name' }, { name => 'connection_state' }, { name => 'power_state' }, { name => 'disk_limit' } ], closure_custom_calc => $self->can('custom_limit_calc'), closure_custom_calc_extra_options => { label_ref => 'disk' }, closure_custom_output => $self->can('custom_limit_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold_ng } - }, + } ]; } @@ -134,37 +142,25 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "vm-hostname:s" => { name => 'vm_hostname' }, - "filter" => { name => 'filter' }, - "filter-description:s" => { name => 'filter_description' }, - "filter-os:s" => { name => 'filter_os' }, - "filter-uuid:s" => { name => 'filter_uuid' }, - "display-description" => { name => 'display_description' }, - "check-disk-limit" => { name => 'check_disk_limit' }, - "warning-disk-status:s" => { name => 'warning_disk_status', default => '' }, - "critical-disk-status:s" => { name => 'critical_disk_status', default => '%{connection_state} !~ /^connected$/i || %{limit} != -1' }, - "warning-cpu-status:s" => { name => 'warning_cpu_status', default => '' }, - "critical-cpu-status:s" => { name => 'critical_cpu_status', default => '%{connection_state} !~ /^connected$/i || %{limit} != -1' }, - "warning-memory-status:s" => { name => 'warning_memory_status', default => '' }, - "critical-memory-status:s" => { name => 'critical_memory_status', default => '%{connection_state} !~ /^connected$/i || %{limit} != -1' }, + 'vm-hostname:s' => { name => 'vm_hostname' }, + 'filter' => { name => 'filter' }, + 'filter-description:s' => { name => 'filter_description' }, + 'filter-os:s' => { name => 'filter_os' }, + 'filter-uuid:s' => { name => 'filter_uuid' }, + 'display-description' => { name => 'display_description' }, + 'check-disk-limit' => { name => 'check_disk_limit' } }); return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['warning_disk_status', 'critical_disk_status','warning_memory_status', 'critical_memory_status', - 'warning_cpu_status', 'critical_cpu_status']); -} - sub manage_selection { my ($self, %options) = @_; - my $response = $options{custom}->execute(params => $self->{option_results}, - command => 'limitvm'); + my $response = $options{custom}->execute( + params => $self->{option_results}, + command => 'limitvm' + ); my $i = 0; $self->{cpu_alarms}->{global} = { cpu_alarm => {} }; @@ -172,7 +168,7 @@ sub manage_selection { $self->{disk_alarms}->{global} = { disk_alarm => {} } if (defined($self->{option_results}->{check_disk_limit})); foreach my $vm_id (keys %{$response->{data}}) { my $vm_name = $response->{data}->{$vm_id}->{name}; - + $self->{cpu_alarms}->{global}->{cpu_alarm}->{$i} = { name => $vm_name, config_annotation => defined($self->{option_results}->{display_description}) ? $options{custom}->strip_cr(value => $response->{data}->{$vm_id}->{'config.annotation'}) : undef, @@ -187,7 +183,7 @@ sub manage_selection { power_state => $response->{data}->{$vm_id}->{power_state}, memory_limit => $response->{data}->{$vm_id}->{'config.memoryAllocation.limit'} }; - + if (defined($self->{option_results}->{check_disk_limit})) { $self->{disk_alarms}->{global}->{disk_alarm}->{$i} = { name => $vm_name, @@ -196,14 +192,14 @@ sub manage_selection { power_state => $response->{data}->{$vm_id}->{power_state}, disk_limit => -1 }; - + foreach (@{$response->{data}->{$vm_id}->{'config.storageIOAllocation.limit'}}) { if ($_->{limit} != -1) { $self->{disk_alarms}->{global}->{disk_alarm}->{$i}->{disk_limit} = 1; } } } - + $i++; } } diff --git a/apps/vmware/connector/mode/maintenancehost.pm b/apps/vmware/connector/mode/maintenancehost.pm index 22572d5f0..6626d7243 100644 --- a/apps/vmware/connector/mode/maintenancehost.pm +++ b/apps/vmware/connector/mode/maintenancehost.pm @@ -24,13 +24,12 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); sub custom_status_output { my ($self, %options) = @_; - my $msg = 'status ' . $self->{result_values}->{status}; - return $msg; + return 'status ' . $self->{result_values}->{status}; } sub custom_status_calc { @@ -43,33 +42,36 @@ sub custom_status_calc { sub custom_maintenance_output { my ($self, %options) = @_; - my $msg = 'maintenance mode is ' . $self->{result_values}->{maintenance}; - return $msg; + return 'maintenance mode is ' . $self->{result_values}->{maintenance}; } sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'host', type => 1, cb_prefix_output => 'prefix_host_output', message_multiple => 'All ESX Hosts are ok' }, + { name => 'host', type => 1, cb_prefix_output => 'prefix_host_output', message_multiple => 'All ESX Hosts are ok' } ]; $self->{maps_counters}->{host} = [ - { label => 'status', threshold => 0, set => { + { + label => 'status', type => 2, unknown_default => '%{status} !~ /^connected$/i', + set => { key_values => [ { name => 'state' } ], closure_custom_calc => $self->can('custom_status_calc'), closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold_ng } }, - { label => 'maintenance-status', threshold => 0, set => { + { + label => 'maintenance-status', type => 2, critical_default => '%{maintenance} !~ /false/', + set => { key_values => [ { name => 'maintenance' } ], closure_custom_output => $self->can('custom_maintenance_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold_ng } - }, + } ]; } @@ -83,43 +85,32 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $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' }, - "unknown-status:s" => { name => 'unknown_status', default => '%{status} !~ /^connected$/i' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '' }, - "warning-maintenance-status:s" => { name => 'warning_maintenance_status', default => '' }, - "critical-maintenance-status:s" => { name => 'critical_maintenance_status', default => '%{maintenance} !~ /false/' }, - }); - - return $self; -} -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status', - 'warning_maintenance_status', 'critical_maintenance_status']); + $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' } + }); + + return $self; } sub manage_selection { my ($self, %options) = @_; $self->{host} = {}; - my $response = $options{custom}->execute(params => $self->{option_results}, - command => 'maintenancehost'); + my $response = $options{custom}->execute( + params => $self->{option_results}, + command => 'maintenancehost' + ); foreach my $host_id (keys %{$response->{data}}) { my $host_name = $response->{data}->{$host_id}->{name}; $self->{host}->{$host_name} = { display => $host_name, state => $response->{data}->{$host_id}->{state}, - maintenance => $response->{data}->{$host_id}->{inMaintenanceMode}, + maintenance => $response->{data}->{$host_id}->{inMaintenanceMode} }; } } diff --git a/apps/vmware/connector/mode/memoryhost.pm b/apps/vmware/connector/mode/memoryhost.pm index 1ad760d86..3694f873e 100644 --- a/apps/vmware/connector/mode/memoryhost.pm +++ b/apps/vmware/connector/mode/memoryhost.pm @@ -24,13 +24,12 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); 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 { @@ -87,10 +86,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 'consumed' 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}); + my $msg = sprintf( + "Memory 'consumed' 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; } @@ -117,16 +118,16 @@ sub custom_overhead_output { my ($self, %options) = @_; my ($overhead_value, $overhead_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{overhead}); - my $msg = sprintf("Memory Overhead: %s", - $overhead_value . " " . $overhead_unit); - return $msg; + return sprintf( + "Memory Overhead: %s", + $overhead_value . " " . $overhead_unit + ); } sub custom_memstate_output { my ($self, %options) = @_; - my $msg = 'Memory state is ' . $self->{result_values}->{mem_state_str}; - return $msg; + return 'Memory state is ' . $self->{result_values}->{mem_state_str}; } sub set_counters { @@ -137,12 +138,14 @@ sub set_counters { ]; $self->{maps_counters}->{host} = [ - { label => 'status', threshold => 0, set => { + { + label => 'status', type => 2, unknown_default => '%{status} !~ /^connected$/i', + set => { key_values => [ { name => 'state' }, { name => 'display' } ], closure_custom_calc => $self->can('custom_status_calc'), closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold_ng } }, { label => 'consumed-memory', nlabel => 'host.memory.usage.bytes', set => { @@ -150,27 +153,27 @@ sub set_counters { closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_output => $self->can('custom_usage_output'), closure_custom_perfdata => $self->can('custom_usage_perfdata'), - closure_custom_threshold_check => $self->can('custom_usage_threshold'), + closure_custom_threshold_check => $self->can('custom_usage_threshold') } }, { label => 'overhead-memory', nlabel => 'host.memory.overhead.bytes', set => { key_values => [ { name => 'overhead' }, { name => 'display' } ], closure_custom_output => $self->can('custom_overhead_output'), perfdatas => [ - { label => 'overhead', value => 'overhead', template => '%s', unit => 'B', - min => 0, label_extra_instance => 1 }, - ], + { label => 'overhead', template => '%s', unit => 'B', + min => 0, label_extra_instance => 1 } + ] } }, { label => 'state-memory', nlabel => 'host.memory.state.count', set => { key_values => [ { name => 'mem_state' }, { name => 'mem_state_str' }, { name => 'display' } ], closure_custom_output => $self->can('custom_memstate_output'), perfdatas => [ - { label => 'state', value => 'mem_state', template => '%s', - min => 0, max => 3, label_extra_instance => 1 }, - ], + { label => 'state', template => '%s', + min => 0, max => 3, label_extra_instance => 1 } + ] } - }, + } ]; } @@ -186,35 +189,27 @@ sub new { bless $self, $class; $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' }, - "units:s" => { name => 'units', default => '%' }, - "free" => { name => 'free' }, - "no-memory-state" => { name => 'no_memory_state' }, - "unknown-status:s" => { name => 'unknown_status', default => '%{status} !~ /^connected$/i' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '' }, + 'esx-hostname:s' => { name => 'esx_hostname' }, + 'filter' => { name => 'filter' }, + 'scope-datacenter:s' => { name => 'scope_datacenter' }, + 'scope-cluster:s' => { name => 'scope_cluster' }, + 'units:s' => { name => 'units', default => '%' }, + 'free' => { name => 'free' }, + 'no-memory-state' => { name => 'no_memory_state' } }); - - return $self; -} -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); + return $self; } sub manage_selection { my ($self, %options) = @_; $self->{host} = {}; - my $response = $options{custom}->execute(params => $self->{option_results}, - command => 'memhost'); - + my $response = $options{custom}->execute( + params => $self->{option_results}, + command => 'memhost' + ); + foreach my $host_id (keys %{$response->{data}}) { my $host_name = $response->{data}->{$host_id}->{name}; $self->{host}->{$host_name} = { @@ -224,7 +219,7 @@ sub manage_selection { overhead => $response->{data}->{$host_id}->{'mem.overhead.average'}, mem_state => $response->{data}->{$host_id}->{mem_state}, mem_state_str => $response->{data}->{$host_id}->{mem_state_str}, - total => $response->{data}->{$host_id}->{mem_size}, + total => $response->{data}->{$host_id}->{mem_size} }; } } diff --git a/apps/vmware/connector/mode/memoryvm.pm b/apps/vmware/connector/mode/memoryvm.pm index 8f7841083..ea617b49b 100644 --- a/apps/vmware/connector/mode/memoryvm.pm +++ b/apps/vmware/connector/mode/memoryvm.pm @@ -24,13 +24,12 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); sub custom_status_output { my ($self, %options) = @_; - my $msg = '[connection state ' . $self->{result_values}->{connection_state} . '][power state ' . $self->{result_values}->{power_state} . ']'; - return $msg; + return '[connection state ' . $self->{result_values}->{connection_state} . '][power state ' . $self->{result_values}->{power_state} . ']'; } sub custom_usage_perfdata { @@ -141,17 +140,19 @@ sub set_counters { { name => 'global_active', type => 0, skipped_code => { -10 => 1 } }, { name => 'global_overhead', type => 0, skipped_code => { -10 => 1 } }, { name => 'global_vmmemctl', type => 0, skipped_code => { -10 => 1 } }, - { name => 'global_shared', type => 0, skipped_code => { -10 => 1 } }, + { name => 'global_shared', type => 0, skipped_code => { -10 => 1 } } ] } ]; $self->{maps_counters}->{global} = [ - { label => 'status', threshold => 0, set => { + { + label => 'status', type => 2, unknown_default => '%{connection_state} !~ /^connected$/i or %{power_state} !~ /^poweredOn$/i', + set => { key_values => [ { name => 'connection_state' }, { name => 'power_state' } ], closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold + closure_custom_threshold_check => \&catalog_status_threshold_ng } } ]; @@ -166,6 +167,7 @@ sub set_counters { } } ]; + $self->{maps_counters}->{global_active} = [ { label => 'active', nlabel => 'vm.memory.active.usage.bytes', set => { key_values => [ { name => 'active' }, { name => 'total' } ], @@ -176,34 +178,37 @@ sub set_counters { } } ]; + $self->{maps_counters}->{global_overhead} = [ { label => 'overhead', nlabel => 'vm.memory.overhead.bytes', set => { key_values => [ { name => 'overhead' } ], closure_custom_output => $self->can('custom_overhead_output'), perfdatas => [ - { label => 'overhead', value => 'overhead', template => '%s', unit => 'B', + { label => 'overhead', template => '%s', unit => 'B', min => 0, label_extra_instance => 1 } ] } } ]; + $self->{maps_counters}->{global_vmmemctl} = [ { label => 'ballooning', nlabel => 'vm.memory.ballooning.bytes', set => { key_values => [ { name => 'vmmemctl' } ], closure_custom_output => $self->can('custom_ballooning_output'), perfdatas => [ - { label => 'ballooning', value => 'vmmemctl', template => '%s', unit => 'B', + { label => 'ballooning', template => '%s', unit => 'B', min => 0, label_extra_instance => 1 } ] } } ]; + $self->{maps_counters}->{global_shared} = [ { label => 'shared', nlabel => 'vm.memory.shared.bytes', set => { key_values => [ { name => 'shared' } ], closure_custom_output => $self->can('custom_shared_output'), perfdatas => [ - { label => 'shared', value => 'shared', template => '%s', unit => 'B', + { label => 'shared', template => '%s', unit => 'B', min => 0, label_extra_instance => 1 } ] } @@ -240,30 +245,20 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - 'vm-hostname:s' => { name => 'vm_hostname' }, - 'filter' => { name => 'filter' }, - 'scope-datacenter:s' => { name => 'scope_datacenter' }, - 'scope-cluster:s' => { name => 'scope_cluster' }, - 'scope-host:s' => { name => 'scope_host' }, - 'filter-description:s' => { name => 'filter_description' }, - 'filter-os:s' => { name => 'filter_os' }, - 'filter-uuid:s' => { name => 'filter_uuid' }, - 'display-description' => { name => 'display_description' }, - 'units:s' => { name => 'units', default => '%' }, - 'free' => { name => 'free' }, - 'unknown-status:s' => { name => 'unknown_status', default => '%{connection_state} !~ /^connected$/i or %{power_state} !~ /^poweredOn$/i' }, - 'warning-status:s' => { name => 'warning_status', default => '' }, - 'critical-status:s' => { name => 'critical_status', default => '' }, + 'vm-hostname:s' => { name => 'vm_hostname' }, + 'filter' => { name => 'filter' }, + 'scope-datacenter:s' => { name => 'scope_datacenter' }, + 'scope-cluster:s' => { name => 'scope_cluster' }, + 'scope-host:s' => { name => 'scope_host' }, + 'filter-description:s' => { name => 'filter_description' }, + 'filter-os:s' => { name => 'filter_os' }, + 'filter-uuid:s' => { name => 'filter_uuid' }, + 'display-description' => { name => 'display_description' }, + 'units:s' => { name => 'units', default => '%' }, + 'free' => { name => 'free' } }); - - return $self; -} -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); + return $self; } sub manage_selection { @@ -281,8 +276,8 @@ sub manage_selection { $self->{vm}->{$vm_name} = { display => $vm_name, global => { connection_state => $response->{data}->{$vm_id}->{connection_state}, - power_state => $response->{data}->{$vm_id}->{power_state}, - }, + power_state => $response->{data}->{$vm_id}->{power_state} + } }; foreach (('consumed', 'active', 'overhead', 'vmmemctl', 'shared')) { diff --git a/apps/vmware/connector/mode/nethost.pm b/apps/vmware/connector/mode/nethost.pm index 8569339ed..732067f19 100644 --- a/apps/vmware/connector/mode/nethost.pm +++ b/apps/vmware/connector/mode/nethost.pm @@ -24,7 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); sub custom_status_output { my ($self, %options) = @_; @@ -116,12 +116,14 @@ sub set_counters { ]; $self->{maps_counters}->{global} = [ - { label => 'status', threshold => 0, set => { + { + label => 'status', type => 2, unknown_default => '%{status} !~ /^connected$/i', + set => { key_values => [ { name => 'state' } ], closure_custom_calc => $self->can('custom_status_calc'), closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold + closure_custom_threshold_check => \&catalog_status_threshold_ng } } ]; @@ -132,7 +134,7 @@ sub set_counters { output_template => 'host traffic in : %s %s/s', output_change_bytes => 2, perfdatas => [ - { label => 'host_traffic_in', value => 'traffic_in', template => '%s', + { label => 'host_traffic_in', template => '%s', unit => 'b/s', min => 0, label_extra_instance => 1 } ] } @@ -142,7 +144,7 @@ sub set_counters { output_template => 'host traffic out : %s %s/s', output_change_bytes => 2, perfdatas => [ - { label => 'host_traffic_out', value => 'traffic_out', template => '%s', + { label => 'host_traffic_out', template => '%s', unit => 'b/s', min => 0, label_extra_instance => 1 } ] } @@ -155,7 +157,7 @@ sub set_counters { output_template => 'traffic in : %s %s/s', output_change_bytes => 2, perfdatas => [ - { label => 'vswitch_traffic_in', value => 'traffic_in', template => '%s', + { label => 'vswitch_traffic_in', template => '%s', unit => 'b/s', min => 0, label_extra_instance => 1 }, ], } @@ -165,7 +167,7 @@ sub set_counters { output_template => 'traffic out : %s %s/s', output_change_bytes => 2, perfdatas => [ - { label => 'vswitch_traffic_out', value => 'traffic_out', template => '%s', + { label => 'vswitch_traffic_out', template => '%s', unit => 'b/s', min => 0, label_extra_instance => 1 } ] } @@ -173,12 +175,14 @@ sub set_counters { ]; $self->{maps_counters}->{pnic} = [ - { label => 'link-status', threshold => 0, set => { + { + label => 'link-status', type => 2, critical_default => '%{link_status} !~ /up/', + set => { key_values => [ { name => 'status' }, { name => 'display' } ], closure_custom_calc => $self->can('custom_linkstatus_calc'), closure_custom_output => $self->can('custom_linkstatus_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold + closure_custom_threshold_check => \&catalog_status_threshold_ng } }, { label => 'link-traffic-in', nlabel => 'host.traffic.in.bitsperseconds', set => { @@ -258,39 +262,25 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - 'esx-hostname:s' => { name => 'esx_hostname' }, - 'nic-name:s' => { name => 'nic_name' }, - 'filter' => { name => 'filter' }, - 'scope-datacenter:s' => { name => 'scope_datacenter' }, - 'scope-cluster:s' => { name => 'scope_cluster' }, - 'no-proxyswitch' => { name => 'no_proxyswitch' }, - 'unknown-status:s' => { name => 'unknown_status', default => '%{status} !~ /^connected$/i' }, - 'warning-status:s' => { name => 'warning_status', default => '' }, - 'critical-status:s' => { name => 'critical_status', default => '' }, - 'unknown-link-status:s' => { name => 'unknown_link_status', default => '' }, - 'warning-link-status:s' => { name => 'warning_link_status', default => '' }, - 'critical-link-status:s' => { name => 'critical_link_status', default => '%{link_status} !~ /up/' } + 'esx-hostname:s' => { name => 'esx_hostname' }, + 'nic-name:s' => { name => 'nic_name' }, + 'filter' => { name => 'filter' }, + 'scope-datacenter:s' => { name => 'scope_datacenter' }, + 'scope-cluster:s' => { name => 'scope_cluster' }, + 'no-proxyswitch' => { name => 'no_proxyswitch' } }); return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => [ - 'unknown_status', 'warning_status', 'critical_status', - 'unknown_link_status', 'warning_link_status', 'critical_link_status' - ]); -} - sub manage_selection { my ($self, %options) = @_; $self->{host} = {}; - my $response = $options{custom}->execute(params => $self->{option_results}, - command => 'nethost'); + my $response = $options{custom}->execute( + params => $self->{option_results}, + command => 'nethost' + ); foreach my $host_id (keys %{$response->{data}}) { my $host_name = $response->{data}->{$host_id}->{name}; @@ -301,8 +291,8 @@ sub manage_selection { }, global_host => { traffic_in => 0, - traffic_out => 0, - }, + traffic_out => 0 + } }; foreach my $pnic_name (sort keys %{$response->{data}->{$host_id}->{pnic}}) { @@ -319,7 +309,7 @@ sub manage_selection { packets_in => $response->{data}->{$host_id}->{pnic}->{$pnic_name}->{'net.packetsRx.summation'}, packets_out => $response->{data}->{$host_id}->{pnic}->{$pnic_name}->{'net.packetsTx.summation'}, dropped_in => $response->{data}->{$host_id}->{pnic}->{$pnic_name}->{'net.droppedRx.summation'}, - dropped_out => $response->{data}->{$host_id}->{pnic}->{$pnic_name}->{'net.droppedTx.summation'}, + dropped_out => $response->{data}->{$host_id}->{pnic}->{$pnic_name}->{'net.droppedTx.summation'} }; next if (!defined($response->{data}->{$host_id}->{pnic}->{$pnic_name}->{speed})); diff --git a/apps/vmware/connector/mode/servicehost.pm b/apps/vmware/connector/mode/servicehost.pm index 56ec777ff..2068bade0 100644 --- a/apps/vmware/connector/mode/servicehost.pm +++ b/apps/vmware/connector/mode/servicehost.pm @@ -24,13 +24,12 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); sub custom_status_output { my ($self, %options) = @_; - my $msg = 'status ' . $self->{result_values}->{status} . ', maintenance mode is ' . $self->{result_values}->{maintenance}; - return $msg; + return 'status ' . $self->{result_values}->{status} . ', maintenance mode is ' . $self->{result_values}->{maintenance}; } sub custom_status_calc { @@ -44,8 +43,7 @@ sub custom_status_calc { sub custom_service_output { my ($self, %options) = @_; - my $msg = '[policy ' . $self->{result_values}->{policy} . '][running ' . $self->{result_values}->{running} . ']'; - return $msg; + return '[policy ' . $self->{result_values}->{policy} . '][running ' . $self->{result_values}->{running} . ']'; } sub set_counters { @@ -55,30 +53,34 @@ sub set_counters { { 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 => 'service', cb_prefix_output => 'prefix_service_output', message_multiple => 'All services are ok', type => 1, skipped_code => { -10 => 1 } }, + { name => 'service', cb_prefix_output => 'prefix_service_output', message_multiple => 'All services are ok', type => 1, skipped_code => { -10 => 1 } } ] } ]; $self->{maps_counters}->{global} = [ - { label => 'status', threshold => 0, set => { + { + label => 'status', type => 2, unknown_default => '%{status} !~ /^connected$/i && %{maintenance} =~ /false/i', + set => { key_values => [ { name => 'state' }, { name => 'maintenance' } ], closure_custom_calc => $self->can('custom_status_calc'), closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold_ng } - }, + } ]; $self->{maps_counters}->{service} = [ - { label => 'service-status', threshold => 0, set => { + { + label => 'service-status', type => 2, critical_default => '%{policy} =~ /^on|automatic/i && !%{running}', + set => { key_values => [ { name => 'display' }, { name => 'policy' }, { name => 'running' }, { name => 'key' } ], closure_custom_output => $self->can('custom_service_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold_ng } - }, + } ]; } @@ -106,49 +108,38 @@ sub new { bless $self, $class; $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' }, - "filter-services:s" => { name => 'filter_services' }, - "unknown-status:s" => { name => 'unknown_status', default => '%{status} !~ /^connected$/i && %{maintenance} =~ /false/i' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '' }, - "warning-service-status:s" => { name => 'warning_service_status', default => '' }, - "critical-service-status:s" => { name => 'critical_service_status', default => '%{policy} =~ /^on|automatic/i && !%{running}' }, + 'esx-hostname:s' => { name => 'esx_hostname' }, + 'filter' => { name => 'filter' }, + 'scope-datacenter:s' => { name => 'scope_datacenter' }, + 'scope-cluster:s' => { name => 'scope_cluster' }, + 'filter-services:s' => { name => 'filter_services' } }); return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status', - 'warning_service_status', 'critical_service_status']); -} - sub manage_selection { my ($self, %options) = @_; $self->{host} = {}; - my $response = $options{custom}->execute(params => $self->{option_results}, - command => 'servicehost'); - + my $response = $options{custom}->execute( + params => $self->{option_results}, + command => 'servicehost' + ); + foreach my $host_id (keys %{$response->{data}}) { my $host_name = $response->{data}->{$host_id}->{name}; $self->{host}->{$host_name} = { display => $host_name, global => { state => $response->{data}->{$host_id}->{state}, - maintenance => $response->{data}->{$host_id}->{inMaintenanceMode}, - }, + maintenance => $response->{data}->{$host_id}->{inMaintenanceMode} + } }; - + foreach (@{$response->{data}->{$host_id}->{services}}) { next if (defined($self->{option_results}->{filter_services}) && $self->{option_results}->{filter_services} ne '' && $_->{key} !~ /$self->{option_results}->{filter_services}/); - + $self->{host}->{$host_name}->{service} = {} if (!defined($self->{host}->{$host_name}->{service})); $self->{host}->{$host_name}->{service}->{$_->{label}} = { display => $_->{label}, policy => $_->{policy}, running => $_->{running}, key => $_->{key} }; } diff --git a/apps/vmware/connector/mode/statconnectors.pm b/apps/vmware/connector/mode/statconnectors.pm index efd1f3b30..a183f3b36 100644 --- a/apps/vmware/connector/mode/statconnectors.pm +++ b/apps/vmware/connector/mode/statconnectors.pm @@ -31,31 +31,29 @@ sub set_counters { $self->{maps_counters_type} = [ { name => 'global', type => 0, skipped_code => { -10 => 1 } }, - { name => 'container', type => 1, cb_prefix_output => 'prefix_container_output', message_multiple => 'All containers are ok' }, + { name => 'container', type => 1, cb_prefix_output => 'prefix_container_output', message_multiple => 'All containers are ok' } ]; $self->{maps_counters}->{global} = [ { label => 'total-requests', nlabel => 'connector.requests.total.count', set => { - key_values => [ { name => 'requests', diff => 1 } ], + key_values => [ { name => 'requests', diff => 1 } ], output_template => 'Total %s requests', perfdatas => [ - { label => 'requests', value => 'requests', template => '%s', - min => 0, label_extra_instance => 1 }, - ], + { label => 'requests', template => '%s', min => 0, label_extra_instance => 1 } + ] } - }, + } ]; $self->{maps_counters}->{container} = [ { label => 'requests', nlabel => 'connector.requests.total.count', set => { - key_values => [ { name => 'requests', diff => 1 } ], + key_values => [ { name => 'requests', diff => 1 } ], output_template => '%s requests', perfdatas => [ - { label => 'requests', value => 'requests', template => '%s', - min => 0, label_extra_instance => 1 }, - ], + { label => 'requests', template => '%s', min => 0, label_extra_instance => 1 } + ] } - }, + } ]; } @@ -69,7 +67,7 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - + $options{options}->add_options(arguments => { }); @@ -81,8 +79,10 @@ sub manage_selection { $self->{global} = { requests => 0 }; $self->{container} = {}; - my $response = $options{custom}->execute(params => $self->{option_results}, - command => 'stats'); + my $response = $options{custom}->execute( + params => $self->{option_results}, + command => 'stats' + ); foreach my $container_name (keys %{$response->{data}}) { $self->{container}->{$container_name} = { diff --git a/apps/vmware/connector/mode/statuscluster.pm b/apps/vmware/connector/mode/statuscluster.pm index c195c0214..c1f4a8926 100644 --- a/apps/vmware/connector/mode/statuscluster.pm +++ b/apps/vmware/connector/mode/statuscluster.pm @@ -24,7 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); sub custom_status_output { my ($self, %options) = @_; @@ -44,7 +44,12 @@ sub set_counters { ]; $self->{maps_counters}->{cluster} = [ - { label => 'status', threshold => 0, set => { + { + label => 'status', type => 2, + unknown_default => '%{overall_status} =~ /gray/i || %{vsan_status} =~ /gray/i', + warning_default => '%{overall_status} =~ /yellow/i || %{vsan_status} =~ /yellow/i', + critical_default => '%{overall_status} =~ /red/i || %{vsan_status} =~ /red/i', + set => { key_values => [ { name => 'overall_status' }, { name => 'vsan_status' }, @@ -52,10 +57,9 @@ sub set_counters { { name => 'drs_enabled' }, { name => 'display' } ], - closure_custom_calc => \&catalog_status_calc, closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold + closure_custom_threshold_check => \&catalog_status_threshold_ng } } ]; @@ -73,24 +77,14 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - 'cluster-name:s' => { name => 'cluster_name' }, - 'filter' => { name => 'filter' }, - 'scope-datacenter:s' => { name => 'scope_datacenter' }, - 'unknown-status:s' => { name => 'unknown_status', default => '%{overall_status} =~ /gray/i || %{vsan_status} =~ /gray/i' }, - 'warning-status:s' => { name => 'warning_status', default => '%{overall_status} =~ /yellow/i || %{vsan_status} =~ /yellow/i' }, - 'critical-status:s' => { name => 'critical_status', default => '%{overall_status} =~ /red/i || %{vsan_status} =~ /red/i' } + 'cluster-name:s' => { name => 'cluster_name' }, + 'filter' => { name => 'filter' }, + 'scope-datacenter:s' => { name => 'scope_datacenter' } }); return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); -} - sub manage_selection { my ($self, %options) = @_; diff --git a/apps/vmware/connector/mode/statushost.pm b/apps/vmware/connector/mode/statushost.pm index 754fc6ee1..099c3ff73 100644 --- a/apps/vmware/connector/mode/statushost.pm +++ b/apps/vmware/connector/mode/statushost.pm @@ -24,13 +24,12 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); sub custom_status_output { my ($self, %options) = @_; - my $msg = 'status ' . $self->{result_values}->{status}; - return $msg; + return 'status ' . $self->{result_values}->{status}; } sub custom_status_calc { @@ -43,41 +42,39 @@ sub custom_status_calc { sub custom_overall_output { my ($self, %options) = @_; - my $msg = 'overall status is ' . $self->{result_values}->{overall_status}; - return $msg; -} - -sub custom_overall_calc { - my ($self, %options) = @_; - - $self->{result_values}->{overall_status} = $options{new_datas}->{$self->{instance} . '_overall_status'}; - return 0; + return 'overall status is ' . $self->{result_values}->{overall_status}; } sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'host', type => 1, cb_prefix_output => 'prefix_host_output', message_multiple => 'All ESX Hosts are ok' }, + { name => 'host', type => 1, cb_prefix_output => 'prefix_host_output', message_multiple => 'All ESX Hosts are ok' } ]; $self->{maps_counters}->{host} = [ - { label => 'status', threshold => 0, set => { + { + label => 'status', type => 2, unknow_default => '%{status} !~ /^connected$/i', + set => { key_values => [ { name => 'state' } ], closure_custom_calc => $self->can('custom_status_calc'), closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold_ng } }, - { label => 'overall-status', threshold => 0, set => { + { + label => 'overall-status', type => 2, + unknown_default => '%{overall_status} =~ /gray/i', + warning_default => '%{overall_status} =~ /yellow/i', + critical_default => '%{overall_status} =~ /red/i', + set => { key_values => [ { name => 'overall_status' } ], - closure_custom_calc => $self->can('custom_overall_calc'), closure_custom_output => $self->can('custom_overall_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold_ng } - }, + } ]; } @@ -93,42 +90,30 @@ sub new { bless $self, $class; $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' }, - "unknown-status:s" => { name => 'unknown_status', default => '%{status} !~ /^connected$/i' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '' }, - "unknown-overall-status:s" => { name => 'unknown_overall_status', default => '%{overall_status} =~ /gray/i' }, - "warning-overall-status:s" => { name => 'warning_overall_status', default => '%{overall_status} =~ /yellow/i' }, - "critical-overall-status:s" => { name => 'critical_overall_status', default => '%{overall_status} =~ /red/i' }, + 'esx-hostname:s' => { name => 'esx_hostname' }, + 'filter' => { name => 'filter' }, + 'scope-datacenter:s' => { name => 'scope_datacenter' }, + 'scope-cluster:s' => { name => 'scope_cluster' } }); return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status', - 'unknown_overall_status', 'warning_overall_status', 'critical_overall_status']); -} - sub manage_selection { my ($self, %options) = @_; $self->{host} = {}; - my $response = $options{custom}->execute(params => $self->{option_results}, - command => 'statushost'); + my $response = $options{custom}->execute( + params => $self->{option_results}, + command => 'statushost' + ); foreach my $host_id (keys %{$response->{data}}) { my $host_name = $response->{data}->{$host_id}->{name}; $self->{host}->{$host_name} = { display => $host_name, state => $response->{data}->{$host_id}->{state}, - overall_status => $response->{data}->{$host_id}->{overall_status}, + overall_status => $response->{data}->{$host_id}->{overall_status} }; } } diff --git a/apps/vmware/connector/mode/statusvm.pm b/apps/vmware/connector/mode/statusvm.pm index 0f1b1f3ad..380c3a2dc 100644 --- a/apps/vmware/connector/mode/statusvm.pm +++ b/apps/vmware/connector/mode/statusvm.pm @@ -24,52 +24,49 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); sub custom_status_output { my ($self, %options) = @_; - my $msg = 'status ' . $self->{result_values}->{connection_state}; - return $msg; + return 'status ' . $self->{result_values}->{connection_state}; } sub custom_overall_output { my ($self, %options) = @_; - my $msg = 'overall status is ' . $self->{result_values}->{overall_status}; - return $msg; -} - -sub custom_overall_calc { - my ($self, %options) = @_; - - $self->{result_values}->{overall_status} = $options{new_datas}->{$self->{instance} . '_overall_status'}; - return 0; + return 'overall status is ' . $self->{result_values}->{overall_status}; } 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' }, + { name => 'vm', type => 1, cb_prefix_output => 'prefix_vm_output', message_multiple => 'All virtual machines are ok' } ]; $self->{maps_counters}->{vm} = [ - { label => 'status', threshold => 0, set => { + { + label => 'status', type => 2, unknown_default => '%{connection_state} !~ /^connected$/i', + set => { key_values => [ { name => 'connection_state' } ], closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold_ng } }, - { label => 'overall-status', threshold => 0, set => { + { + label => 'overall-status', type => 2, + unknown_default => '%{overall_status} =~ /gray/i', + warning_default => '%{overall_status} =~ /yellow/i', + critical_default => '%{overall_status} =~ /red/i', + set => { key_values => [ { name => 'overall_status' } ], - closure_custom_calc => $self->can('custom_overall_calc'), closure_custom_output => $self->can('custom_overall_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold_ng } - }, + } ]; } @@ -91,50 +88,38 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "vm-hostname:s" => { name => 'vm_hostname' }, - "filter" => { name => 'filter' }, - "scope-datacenter:s" => { name => 'scope_datacenter' }, - "scope-cluster:s" => { name => 'scope_cluster' }, - "scope-host:s" => { name => 'scope_host' }, - "filter-description:s" => { name => 'filter_description' }, - "filter-os:s" => { name => 'filter_os' }, - "filter-uuid:s" => { name => 'filter_uuid' }, - "display-description" => { name => 'display_description' }, - "unknown-status:s" => { name => 'unknown_status', default => '%{connection_state} !~ /^connected$/i' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '' }, - "unknown-overall-status:s" => { name => 'unknown_overall_status', default => '%{overall_status} =~ /gray/i' }, - "warning-overall-status:s" => { name => 'warning_overall_status', default => '%{overall_status} =~ /yellow/i' }, - "critical-overall-status:s" => { name => 'critical_overall_status', default => '%{overall_status} =~ /red/i' }, + 'vm-hostname:s' => { name => 'vm_hostname' }, + 'filter' => { name => 'filter' }, + 'scope-datacenter:s' => { name => 'scope_datacenter' }, + 'scope-cluster:s' => { name => 'scope_cluster' }, + 'scope-host:s' => { name => 'scope_host' }, + 'filter-description:s' => { name => 'filter_description' }, + 'filter-os:s' => { name => 'filter_os' }, + 'filter-uuid:s' => { name => 'filter_uuid' }, + 'display-description' => { name => 'display_description' } }); - - return $self; -} -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status', - 'unknown_overall_status', 'warning_overall_status', 'critical_overall_status']); + return $self; } sub manage_selection { my ($self, %options) = @_; $self->{vm} = {}; - my $response = $options{custom}->execute(params => $self->{option_results}, - command => 'statusvm'); + my $response = $options{custom}->execute( + params => $self->{option_results}, + command => 'statusvm' + ); foreach my $vm_id (keys %{$response->{data}}) { my $vm_name = $response->{data}->{$vm_id}->{name}; $self->{vm}->{$vm_name} = { display => $vm_name, connection_state => $response->{data}->{$vm_id}->{connection_state}, - overall_status => $response->{data}->{$vm_id}->{overall_status}, + overall_status => $response->{data}->{$vm_id}->{overall_status} }; - - if (defined($self->{option_results}->{display_description})) { + + if (defined($self->{option_results}->{display_description})) { $self->{vm}->{$vm_name}->{config_annotation} = $options{custom}->strip_cr(value => $response->{data}->{$vm_id}->{'config.annotation'}); } } diff --git a/apps/vmware/connector/mode/swaphost.pm b/apps/vmware/connector/mode/swaphost.pm index 21b540c25..e38fbd112 100644 --- a/apps/vmware/connector/mode/swaphost.pm +++ b/apps/vmware/connector/mode/swaphost.pm @@ -24,13 +24,12 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); 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 { @@ -48,12 +47,14 @@ sub set_counters { ]; $self->{maps_counters}->{host} = [ - { label => 'status', threshold => 0, set => { + { + label => 'status', type => 2, unknown_default => '%{status} !~ /^connected$/i', + set => { key_values => [ { name => 'state' }, { name => 'display' } ], closure_custom_calc => $self->can('custom_status_calc'), closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold_ng } }, { label => 'swap-in', nlabel => 'host.swap.in.usage.bytespersecond', set => { @@ -61,9 +62,9 @@ sub set_counters { output_template => 'Swap In: %s %s/s', output_change_bytes => 1, perfdatas => [ - { label => 'swap_in', value => 'swap_in', template => '%s', - unit => 'B/s', min => 0, label_extra_instance => 1 }, - ], + { label => 'swap_in', template => '%s', + unit => 'B/s', min => 0, label_extra_instance => 1 } + ] } }, { label => 'swap-out', nlabel => 'host.swap.out.usage.bytespersecond', set => { @@ -71,11 +72,11 @@ sub set_counters { output_template => 'Swap Out: %s %s/s', output_change_bytes => 1, perfdatas => [ - { label => 'swap_out', value => 'swap_out', template => '%s', - unit => 'B/s', min => 0, label_extra_instance => 1 }, - ], + { label => 'swap_out', template => '%s', + unit => 'B/s', min => 0, label_extra_instance => 1 } + ] } - }, + } ]; } @@ -91,39 +92,31 @@ sub new { bless $self, $class; $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' }, - "unknown-status:s" => { name => 'unknown_status', default => '%{status} !~ /^connected$/i' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '' }, + 'esx-hostname:s' => { name => 'esx_hostname' }, + 'filter' => { name => 'filter' }, + 'scope-datacenter:s' => { name => 'scope_datacenter' }, + 'scope-cluster:s' => { name => 'scope_cluster' } }); - - return $self; -} -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); + return $self; } sub manage_selection { my ($self, %options) = @_; $self->{host} = {}; - my $response = $options{custom}->execute(params => $self->{option_results}, - command => 'swaphost'); - + my $response = $options{custom}->execute( + params => $self->{option_results}, + command => 'swaphost' + ); + foreach my $host_id (keys %{$response->{data}}) { my $host_name = $response->{data}->{$host_id}->{name}; $self->{host}->{$host_name} = { display => $host_name, state => $response->{data}->{$host_id}->{state}, swap_in => $response->{data}->{$host_id}->{'mem.swapinRate.average'}, - swap_out => $response->{data}->{$host_id}->{'mem.swapoutRate.average'}, + swap_out => $response->{data}->{$host_id}->{'mem.swapoutRate.average'} }; } } diff --git a/apps/vmware/connector/mode/swapvm.pm b/apps/vmware/connector/mode/swapvm.pm index 23680dd7f..68c9a43f1 100644 --- a/apps/vmware/connector/mode/swapvm.pm +++ b/apps/vmware/connector/mode/swapvm.pm @@ -24,13 +24,12 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); sub custom_status_output { my ($self, %options) = @_; - my $msg = '[connection state ' . $self->{result_values}->{connection_state} . '][power state ' . $self->{result_values}->{power_state} . ']'; - return $msg; + return '[connection state ' . $self->{result_values}->{connection_state} . '][power state ' . $self->{result_values}->{power_state} . ']'; } sub set_counters { @@ -39,13 +38,15 @@ sub set_counters { $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 => 'status', threshold => 0, set => { + { + label => 'status', type => 2, unknown_default => '%{connection_state} !~ /^connected$/i or %{power_state} !~ /^poweredOn$/i', + set => { key_values => [ { name => 'connection_state' }, { name => 'power_state' } ], closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold_ng } }, { label => 'swap-in', nlabel => 'vm.swap.in.usage.bytespersecond', set => { @@ -53,8 +54,8 @@ sub set_counters { output_template => 'Swap In: %s %s/s', output_change_bytes => 1, perfdatas => [ - { label => 'swap_in', value => 'swap_in', template => '%s', - unit => 'B/s', min => 0, label_extra_instance => 1 }, + { label => 'swap_in', template => '%s', + unit => 'B/s', min => 0, label_extra_instance => 1 } ], } }, @@ -63,11 +64,11 @@ sub set_counters { output_template => 'Swap Out: %s %s/s', output_change_bytes => 1, perfdatas => [ - { label => 'swap_out', value => 'swap_out', template => '%s', - unit => 'B/s', min => 0, label_extra_instance => 1 }, - ], + { label => 'swap_out', template => '%s', + unit => 'B/s', min => 0, label_extra_instance => 1 } + ] } - }, + } ]; } @@ -89,36 +90,28 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "vm-hostname:s" => { name => 'vm_hostname' }, - "filter" => { name => 'filter' }, - "scope-datacenter:s" => { name => 'scope_datacenter' }, - "scope-cluster:s" => { name => 'scope_cluster' }, - "scope-host:s" => { name => 'scope_host' }, - "filter-description:s" => { name => 'filter_description' }, - "filter-os:s" => { name => 'filter_os' }, - "filter-uuid:s" => { name => 'filter_uuid' }, - "display-description" => { name => 'display_description' }, - "unknown-status:s" => { name => 'unknown_status', default => '%{connection_state} !~ /^connected$/i or %{power_state} !~ /^poweredOn$/i' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '' }, + 'vm-hostname:s' => { name => 'vm_hostname' }, + 'filter' => { name => 'filter' }, + 'scope-datacenter:s' => { name => 'scope_datacenter' }, + 'scope-cluster:s' => { name => 'scope_cluster' }, + 'scope-host:s' => { name => 'scope_host' }, + 'filter-description:s' => { name => 'filter_description' }, + 'filter-os:s' => { name => 'filter_os' }, + 'filter-uuid:s' => { name => 'filter_uuid' }, + 'display-description' => { name => 'display_description' } }); - - return $self; -} -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); + return $self; } sub manage_selection { my ($self, %options) = @_; $self->{vm} = {}; - my $response = $options{custom}->execute(params => $self->{option_results}, - command => 'swapvm'); + my $response = $options{custom}->execute( + params => $self->{option_results}, + command => 'swapvm' + ); foreach my $vm_id (keys %{$response->{data}}) { my $vm_name = $response->{data}->{$vm_id}->{name}; @@ -128,9 +121,9 @@ sub manage_selection { connection_state => $response->{data}->{$vm_id}->{connection_state}, power_state => $response->{data}->{$vm_id}->{power_state}, swap_in => $response->{data}->{$vm_id}->{'mem.swapinRate.average'}, - swap_out => $response->{data}->{$vm_id}->{'mem.swapoutRate.average'}, + swap_out => $response->{data}->{$vm_id}->{'mem.swapoutRate.average'} }; - + if (defined($self->{option_results}->{display_description})) { $self->{vm}->{$vm_name}->{config_annotation} = $options{custom}->strip_cr(value => $response->{data}->{$vm_id}->{'config.annotation'}); } diff --git a/apps/vmware/connector/mode/timehost.pm b/apps/vmware/connector/mode/timehost.pm index 1fa2d2de9..9a6f800c7 100644 --- a/apps/vmware/connector/mode/timehost.pm +++ b/apps/vmware/connector/mode/timehost.pm @@ -25,13 +25,12 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; use Date::Parse; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); 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 { @@ -44,9 +43,10 @@ sub custom_status_calc { sub custom_time_output { my ($self, %options) = @_; - my $msg = sprintf("time offset %d second(s) : %s", - $self->{result_values}->{offset}, $self->{result_values}->{date}); - return $msg; + return sprintf( + 'time offset %d second(s) : %s', + $self->{result_values}->{offset}, $self->{result_values}->{date} + ); } sub set_counters { @@ -57,23 +57,25 @@ sub set_counters { ]; $self->{maps_counters}->{host} = [ - { label => 'status', threshold => 0, set => { + { + label => 'status', type => 2, unknown_default => '%{status} !~ /^connected$/i', + set => { key_values => [ { name => 'state' }, { name => 'display' } ], closure_custom_calc => $self->can('custom_status_calc'), closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold_ng } }, { label => 'time', nlabel => 'host.time.offset.seconds', set => { key_values => [ { name => 'offset' }, { name => 'date' }, { name => 'display' } ], closure_custom_output => $self->can('custom_time_output'), perfdatas => [ - { label => 'offset', value => 'offset', template => '%.2f', - unit => 's', label_extra_instance => 1 }, - ], + { label => 'offset', template => '%.2f', + unit => 's', label_extra_instance => 1 } + ] } - }, + } ]; } @@ -87,34 +89,26 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $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' }, - "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::check_options(%options); - - $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); + $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' } + }); + + return $self; } sub manage_selection { my ($self, %options) = @_; $self->{host} = {}; - my $response = $options{custom}->execute(params => $self->{option_results}, - command => 'timehost'); - + my $response = $options{custom}->execute( + params => $self->{option_results}, + command => 'timehost' + ); + foreach my $host_id (keys %{$response->{data}}) { my $host_name = $response->{data}->{$host_id}->{name}; @@ -128,7 +122,7 @@ sub manage_selection { display => $host_name, state => $response->{data}->{$host_id}->{state}, offset => $offset, - date => $response->{data}->{$host_id}->{current_time}, + date => $response->{data}->{$host_id}->{current_time} }; } } diff --git a/apps/vmware/connector/mode/uptimehost.pm b/apps/vmware/connector/mode/uptimehost.pm index e36edebee..21e663054 100644 --- a/apps/vmware/connector/mode/uptimehost.pm +++ b/apps/vmware/connector/mode/uptimehost.pm @@ -25,13 +25,12 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; use Date::Parse; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); 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 { @@ -44,9 +43,10 @@ sub custom_status_calc { sub custom_time_output { my ($self, %options) = @_; - my $msg = sprintf("Uptime: %s day(s)", - int($self->{result_values}->{offset} / 60 / 60 / 24)); - return $msg; + return sprintf( + 'Uptime: %s day(s)', + int($self->{result_values}->{offset} / 60 / 60 / 24) + ); } sub set_counters { @@ -57,23 +57,25 @@ sub set_counters { ]; $self->{maps_counters}->{host} = [ - { label => 'status', threshold => 0, set => { + { + label => 'status', type => 2, unknown_default => '%{status} !~ /^connected$/i', + set => { key_values => [ { name => 'state' }, { name => 'display' } ], closure_custom_calc => $self->can('custom_status_calc'), closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold_ng } }, { label => 'time', nlabel => 'host.uptime.offset.seconds', set => { key_values => [ { name => 'offset' }, { name => 'date' }, { name => 'display' } ], closure_custom_output => $self->can('custom_time_output'), perfdatas => [ - { label => 'uptime', value => 'offset', template => '%.2f', - unit => 's', label_extra_instance => 1 }, - ], + { label => 'uptime', template => '%.2f', + unit => 's', label_extra_instance => 1 } + ] } - }, + } ]; } @@ -87,48 +89,40 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $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' }, - "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::check_options(%options); - - $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); + $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' } + }); + + return $self; } sub manage_selection { my ($self, %options) = @_; $self->{host} = {}; - my $response = $options{custom}->execute(params => $self->{option_results}, - command => 'uptimehost'); - + my $response = $options{custom}->execute( + params => $self->{option_results}, + command => 'uptimehost' + ); + foreach my $host_id (keys %{$response->{data}}) { my $host_name = $response->{data}->{$host_id}->{name}; - + my $offset; if (defined($response->{data}->{$host_id}->{boot_time})) { my $timestamp = Date::Parse::str2time($response->{data}->{$host_id}->{boot_time}); $offset = time() - $timestamp; } - + $self->{host}->{$host_name} = { display => $host_name, state => $response->{data}->{$host_id}->{state}, offset => $offset, - date => $response->{data}->{$host_id}->{boot_time}, + date => $response->{data}->{$host_id}->{boot_time} }; } } diff --git a/apps/vmware/connector/mode/vmoperationcluster.pm b/apps/vmware/connector/mode/vmoperationcluster.pm index e0a95b6ad..8ac11e9e4 100644 --- a/apps/vmware/connector/mode/vmoperationcluster.pm +++ b/apps/vmware/connector/mode/vmoperationcluster.pm @@ -35,32 +35,29 @@ sub set_counters { $self->{maps_counters}->{cluster} = [ { label => 'svmotion', nlabel => 'cluster.operations.svmotion.current.count', set => { - key_values => [ { name => 'numSVMotion', diff => 1 }, { name => 'display' } ], + key_values => [ { name => 'numSVMotion', diff => 1 }, { name => 'display' } ], output_template => 'SVMotion %s', perfdatas => [ - { label => 'svmotion', value => 'numSVMotion', template => '%s', - label_extra_instance => 1 }, - ], + { label => 'svmotion', template => '%s', min => 0, label_extra_instance => 1 } + ] } }, { label => 'vmotion', nlabel => 'cluster.operations.vmotion.current.count', set => { - key_values => [ { name => 'numVMotion', diff => 1 }, { name => 'display' } ], + key_values => [ { name => 'numVMotion', diff => 1 }, { name => 'display' } ], output_template => 'VMotion %s', perfdatas => [ - { label => 'vmotion', value => 'numVMotion', template => '%s', - label_extra_instance => 1 }, - ], + { label => 'vmotion', template => '%s', min => 0, label_extra_instance => 1 } + ] } }, { label => 'clone', nlabel => 'cluster.operations.clone.current.count', set => { - key_values => [ { name => 'numClone', diff => 1 }, { name => 'display' } ], + key_values => [ { name => 'numClone', diff => 1 }, { name => 'display' } ], output_template => 'Clone %s', perfdatas => [ - { label => 'clone', value => 'numClone', template => '%s', - label_extra_instance => 1 }, - ], + { label => 'clone', template => '%s', min => 0, label_extra_instance => 1 } + ] } - }, + } ]; } @@ -76,9 +73,9 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "cluster:s" => { name => 'cluster' }, - "filter" => { name => 'filter' }, - "scope-datacenter:s" => { name => 'scope_datacenter' }, + 'cluster:s' => { name => 'cluster' }, + 'filter' => { name => 'filter' }, + 'scope-datacenter:s' => { name => 'scope_datacenter' } }); return $self; @@ -88,16 +85,18 @@ sub manage_selection { my ($self, %options) = @_; $self->{cluster} = {}; - my $response = $options{custom}->execute(params => $self->{option_results}, - command => 'vmoperationcluster'); - + my $response = $options{custom}->execute( + params => $self->{option_results}, + command => 'vmoperationcluster' + ); + foreach my $cluster_id (keys %{$response->{data}}) { my $cluster_name = $response->{data}->{$cluster_id}->{name}; $self->{cluster}->{$cluster_name} = { display => $cluster_name, numVMotion => $response->{data}->{$cluster_id}->{'vmop.numVMotion.latest'}, numClone => $response->{data}->{$cluster_id}->{'vmop.numClone.latest'}, - numSVMotion => $response->{data}->{$cluster_id}->{'vmop.numSVMotion.latest'}, + numSVMotion => $response->{data}->{$cluster_id}->{'vmop.numSVMotion.latest'} }; } diff --git a/apps/vmware/connector/mode/vsanclusterusage.pm b/apps/vmware/connector/mode/vsanclusterusage.pm index 3783afd81..8ee4f2948 100644 --- a/apps/vmware/connector/mode/vsanclusterusage.pm +++ b/apps/vmware/connector/mode/vsanclusterusage.pm @@ -29,7 +29,7 @@ sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'cluster', type => 1, cb_prefix_output => 'prefix_cluster_output', message_multiple => 'All clusters are ok' }, + { name => 'cluster', type => 1, cb_prefix_output => 'prefix_cluster_output', message_multiple => 'All clusters are ok' } ]; $self->{maps_counters}->{cluster} = [ @@ -37,32 +37,32 @@ sub set_counters { key_values => [ { name => 'iopsRead' } ], output_template => 'read IOPS: %s', perfdatas => [ - { value => 'iopsRead', template => '%s', unit => 'iops', min => 0 }, - ], + { template => '%s', unit => 'iops', min => 0 } + ] } }, { label => 'backend-write-usage', nlabel => 'cluster.vsan.backend.write.usage.iops', set => { key_values => [ { name => 'iopsWrite' } ], output_template => 'write IOPS: %s', perfdatas => [ - { value => 'iopsWrite', template => '%s', unit => 'iops', min => 0 }, - ], + { template => '%s', unit => 'iops', min => 0 } + ] } }, { label => 'backend-congestions', nlabel => 'cluster.vsan.backend.congestions.count', set => { key_values => [ { name => 'congestion' } ], output_template => 'congestions: %s', perfdatas => [ - { value => 'congestion', template => '%s', min => 0 }, - ], + { template => '%s', min => 0 } + ] } }, { label => 'backend-outstanding-io', nlabel => 'cluster.vsan.backend.outstanding.io.count', set => { key_values => [ { name => 'oio' } ], output_template => 'outstanding IO: %s', perfdatas => [ - { value => 'oio', template => '%s', min => 0 }, - ], + { template => '%s', min => 0 } + ] } }, { label => 'backend-throughput-read', nlabel => 'cluster.vsan.backend.throughput.read.bytespersecond', display_ok => 0, set => { @@ -70,8 +70,8 @@ sub set_counters { output_template => 'read throughput: %s %s/s', output_change_bytes => 1, perfdatas => [ - { value => 'throughputRead', template => '%s', unit => 'B/s', min => 0 }, - ], + { template => '%s', unit => 'B/s', min => 0 } + ] } }, { label => 'backend-throughput-write', nlabel => 'cluster.vsan.backend.throughput.write.bytespersecond', display_ok => 0, set => { @@ -79,26 +79,26 @@ sub set_counters { output_template => 'write throughput: %s %s/s', output_change_bytes => 1, perfdatas => [ - { value => 'throughputWrite', template => '%s', unit => 'B/s', min => 0 }, - ], + { template => '%s', unit => 'B/s', min => 0 } + ] } }, { label => 'backend-latency-read', nlabel => 'cluster.vsan.backend.latency.read.milliseconds', display_ok => 0, set => { key_values => [ { name => 'latencyAvgRead' } ], output_template => 'read latency: %s ms', perfdatas => [ - { value => 'latencyAvgRead', template => '%s', unit => 'ms', min => 0 }, - ], + { template => '%s', unit => 'ms', min => 0 } + ] } }, { label => 'backend-latency-write', nlabel => 'cluster.vsan.backend.latency.write.milliseconds', display_ok => 0, set => { key_values => [ { name => 'latencyAvgWrite' } ], output_template => 'write latency: %s ms', perfdatas => [ - { value => 'latencyAvgWrite', template => '%s', unit => 'ms', min => 0 }, - ], + { template => '%s', unit => 'ms', min => 0 } + ] } - }, + } ]; } diff --git a/apps/vmware/connector/plugin.pm b/apps/vmware/connector/plugin.pm index e9b37b475..e70de5287 100644 --- a/apps/vmware/connector/plugin.pm +++ b/apps/vmware/connector/plugin.pm @@ -30,7 +30,7 @@ sub new { bless $self, $class; $self->{version} = '0.1'; - %{$self->{modes}} = ( + $self->{modes} = { 'alarm-datacenter' => 'apps::vmware::connector::mode::alarmdatacenter', 'alarm-host' => 'apps::vmware::connector::mode::alarmhost', 'countvm-host' => 'apps::vmware::connector::mode::countvmhost', @@ -70,9 +70,9 @@ sub new { 'uptime-host' => 'apps::vmware::connector::mode::uptimehost', 'vmoperation-cluster' => 'apps::vmware::connector::mode::vmoperationcluster', 'vsan-cluster-usage' => 'apps::vmware::connector::mode::vsanclusterusage', - ); + }; - $self->{custom_modes}{connector} = 'apps::vmware::connector::custom::connector'; + $self->{custom_modes}->{connector} = 'apps::vmware::connector::custom::connector'; return $self; }