From 7b8e678c5662e53b2b0b4302f1063ef7072cb9b5 Mon Sep 17 00:00:00 2001 From: qgarnier Date: Tue, 8 Mar 2022 11:17:24 +0100 Subject: [PATCH] (plugin) apps::microsoft::hyperv::2012::local - some cleaning (#3529) --- .../2012/local/mode/nodeintegrationservice.pm | 95 ++++++++----------- .../hyperv/2012/local/mode/nodesnapshot.pm | 36 +++---- .../hyperv/2012/local/mode/nodevmstatus.pm | 17 +--- .../local/mode/scvmmintegrationservice.pm | 52 ++++------ .../hyperv/2012/local/mode/scvmmsnapshot.pm | 24 ++--- .../hyperv/2012/local/mode/scvmmvmstatus.pm | 23 ++--- 6 files changed, 104 insertions(+), 143 deletions(-) diff --git a/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/nodeintegrationservice.pm b/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/nodeintegrationservice.pm index 8c11da9ef..670755aa8 100644 --- a/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/nodeintegrationservice.pm +++ b/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/nodeintegrationservice.pm @@ -27,7 +27,7 @@ use warnings; use centreon::plugins::misc; use centreon::common::powershell::hyperv::2012::nodeintegrationservice; use apps::microsoft::hyperv::2012::local::mode::resources::types qw($node_vm_state $node_vm_integration_service_operational_status); -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); use JSON::XS; sub custom_service_status_output { @@ -42,36 +42,6 @@ sub custom_global_status_output { return 'state/version: ' . $self->{result_values}->{integration_service_state} . '/' . $self->{result_values}->{integration_service_version}; } -sub set_counters { - my ($self, %options) = @_; - - $self->{maps_counters_type} = [ - { name => 'vm', type => 2, cb_prefix_output => 'prefix_vm_output', cb_long_output => 'vm_long_output', message_multiple => 'All integration services are ok', - group => [ { name => 'global', cb_prefix_output => 'prefix_global_output' }, { name => 'service', cb_prefix_output => 'prefix_service_output' } ] - } - ]; - - $self->{maps_counters}->{global} = [ - { label => 'global-status', threshold => 0, set => { - key_values => [ { name => 'integration_service_state' }, { name => 'integration_service_version' }, { name => 'state' }, { name => 'vm' } ], - closure_custom_output => $self->can('custom_global_status_output'), - closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold - } - } - ]; - - $self->{maps_counters}->{service} = [ - { label => 'service-status', threshold => 0, set => { - key_values => [ { name => 'primary_status' }, { name => 'secondary_status' }, { name => 'enabled' }, { name => 'vm' }, { name => 'service' } ], - closure_custom_output => $self->can('custom_service_status_output'), - closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold - } - } - ]; -} - sub vm_long_output { my ($self, %options) = @_; @@ -96,38 +66,57 @@ sub prefix_global_output { return "global virtual machine '" . $options{instance_value}->{vm} . "' integration service "; } +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'vm', type => 2, cb_prefix_output => 'prefix_vm_output', cb_long_output => 'vm_long_output', message_multiple => 'All integration services are ok', + group => [ { name => 'global', cb_prefix_output => 'prefix_global_output' }, { name => 'service', cb_prefix_output => 'prefix_service_output' } ] + } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'global-status', type => 2, warning_default => '%{integration_service_state} =~ /Update required/i', set => { + key_values => [ { name => 'integration_service_state' }, { name => 'integration_service_version' }, { name => 'state' }, { name => 'vm' } ], + closure_custom_output => $self->can('custom_global_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold_ng + } + } + ]; + + $self->{maps_counters}->{service} = [ + { label => 'service-status', type => 2, critical_default => '%{primary_status} !~ /Ok/i', set => { + key_values => [ { name => 'primary_status' }, { name => 'secondary_status' }, { name => 'enabled' }, { name => 'vm' }, { name => 'service' } ], + closure_custom_output => $self->can('custom_service_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold_ng + } + } + ]; +} + sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; $options{options}->add_options(arguments => { - 'timeout:s' => { name => 'timeout', default => 50 }, - 'command:s' => { name => 'command', default => 'powershell.exe' }, - 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, - 'no-ps' => { name => 'no_ps' }, - 'ps-exec-only' => { name => 'ps_exec_only' }, - 'ps-display' => { name => 'ps_display' }, - 'filter-vm:s' => { name => 'filter_vm' }, - 'filter-note:s' => { name => 'filter_note' }, - 'filter-status:s' => { name => 'filter_status', default => 'running' }, - 'warning-global-status:s' => { name => 'warning_global_status', default => '%{integration_service_state} =~ /Update required/i' }, - 'critical-global-status:s' => { name => 'critical_global_status', default => '' }, - 'warning-service-status:s' => { name => 'warning_service_status', default => '' }, - 'critical-service-status:s' => { name => 'critical_service_status', default => '%{primary_status} !~ /Ok/i' } + 'timeout:s' => { name => 'timeout', default => 50 }, + 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'no-ps' => { name => 'no_ps' }, + 'ps-exec-only' => { name => 'ps_exec_only' }, + 'ps-display' => { name => 'ps_display' }, + 'filter-vm:s' => { name => 'filter_vm' }, + 'filter-note:s' => { name => 'filter_note' }, + 'filter-status:s' => { name => 'filter_status', default => 'running' } }); return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['warning_service_status', 'critical_service_status', 'warning_global_status', 'critical_global_status']); -} - sub manage_selection { my ($self, %options) = @_; @@ -242,7 +231,7 @@ sub manage_selection { }; $id2++; } - + $id++; } } diff --git a/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/nodesnapshot.pm b/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/nodesnapshot.pm index 949fbbfae..d3bbc1ec4 100644 --- a/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/nodesnapshot.pm +++ b/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/nodesnapshot.pm @@ -29,6 +29,24 @@ use centreon::common::powershell::hyperv::2012::nodesnapshot; use apps::microsoft::hyperv::2012::local::mode::resources::types qw($node_vm_state); use JSON::XS; +sub custom_snapshot_output { + my ($self, %options) = @_; + + return "checkpoint started " . centreon::plugins::misc::change_seconds(value => $self->{result_values}->{snapshot}) . " ago"; +} + +sub custom_backing_output { + my ($self, %options) = @_; + + return "backing started " . centreon::plugins::misc::change_seconds(value => $self->{result_values}->{backing}) . " ago"; +} + +sub prefix_vm_output { + my ($self, %options) = @_; + + return "VM '" . $options{instance_value}->{display} . "' [status = " . $options{instance_value}->{status} . '] '; +} + sub set_counters { my ($self, %options) = @_; @@ -52,24 +70,6 @@ sub set_counters { ]; } -sub custom_snapshot_output { - my ($self, %options) = @_; - - return "checkpoint started " . centreon::plugins::misc::change_seconds(value => $self->{result_values}->{snapshot}) . " ago"; -} - -sub custom_backing_output { - my ($self, %options) = @_; - - return "backing started " . centreon::plugins::misc::change_seconds(value => $self->{result_values}->{backing}) . " ago"; -} - -sub prefix_vm_output { - my ($self, %options) = @_; - - return "VM '" . $options{instance_value}->{display} . "' [status = " . $options{instance_value}->{status} . '] '; -} - sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); diff --git a/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/nodevmstatus.pm b/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/nodevmstatus.pm index d3b35b74c..4b00b45d3 100644 --- a/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/nodevmstatus.pm +++ b/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/nodevmstatus.pm @@ -26,7 +26,7 @@ use strict; use warnings; use centreon::plugins::misc; use centreon::common::powershell::hyperv::2012::nodevmstatus; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); use apps::microsoft::hyperv::2012::local::mode::resources::types qw($node_vm_state); use JSON::XS; @@ -43,11 +43,11 @@ sub set_counters { { 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, critical_default => '%{status} !~ /Operating normally/i', set => { key_values => [ { name => 'vm' }, { name => 'state' }, { name => 'status' }, { name => 'is_clustered' } ], 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,21 +73,12 @@ sub new { 'ps-exec-only' => { name => 'ps_exec_only' }, 'ps-display' => { name => 'ps_display' }, 'filter-vm:s' => { name => 'filter_vm' }, - 'filter-note:s' => { name => 'filter_note' }, - 'warning-status:s' => { name => 'warning_status', default => '' }, - 'critical-status:s' => { name => 'critical_status', default => '%{status} !~ /Operating normally/i' } + 'filter-note:s' => { name => 'filter_note' } }); return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['warning_status', 'critical_status']); -} - sub manage_selection { my ($self, %options) = @_; diff --git a/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/scvmmintegrationservice.pm b/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/scvmmintegrationservice.pm index 7bc3c3ec9..aea96c54e 100644 --- a/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/scvmmintegrationservice.pm +++ b/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/scvmmintegrationservice.pm @@ -27,7 +27,7 @@ use warnings; use centreon::plugins::misc; use centreon::common::powershell::hyperv::2012::scvmmintegrationservice; use apps::microsoft::hyperv::2012::local::mode::resources::types qw($scvmm_vm_status); -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); use JSON::XS; sub custom_status_output { @@ -74,59 +74,61 @@ sub set_counters { ]; $self->{maps_counters}->{vm} = [ - { label => 'status', threshold => 0, set => { - key_values => [ { name => 'vm' }, { name => 'status' }, { name => 'vm_addition' }, + { label => 'status', type => 2, critical_default => '%{vmaddition} =~ /not detected/i', set => { + key_values => [ + { name => 'vm' }, { name => 'status' }, { name => 'vm_addition' }, { name => 'operating_system_shutdown_enabled' }, { name => 'time_synchronization_enabled' }, - { name => 'data_exchange_enabled' }, { name => 'heartbeat_enabled' }, { name => 'backup_enabled' } ], + { name => 'data_exchange_enabled' }, { name => 'heartbeat_enabled' }, { name => 'backup_enabled' } + ], 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 => 'osshutdown-status', threshold => 0, set => { + { label => 'osshutdown-status', type => 2, set => { key_values => [ { name => 'status' }, { name => 'vm' }, { name => 'operating_system_shutdown_enabled' } ], closure_custom_calc => $self->can('custom_integrationservice_calc'), closure_custom_calc_extra_options => { output_label => 'operating system shutdown', name_status => 'operating_system_shutdown_enabled' }, closure_custom_output => $self->can('custom_integrationservice_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold + closure_custom_threshold_check => \&catalog_status_threshold_ng } }, - { label => 'timesync-status', threshold => 0, set => { + { label => 'timesync-status', type => 2, set => { key_values => [ { name => 'status' }, { name => 'vm' }, { name => 'time_synchronization_enabled' } ], closure_custom_calc => $self->can('custom_integrationservice_calc'), closure_custom_calc_extra_options => { output_label => 'time synchronization', name_status => 'time_synchronization_enabled' }, closure_custom_output => $self->can('custom_integrationservice_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold + closure_custom_threshold_check => \&catalog_status_threshold_ng } }, - { label => 'dataexchange-status', threshold => 0, set => { + { label => 'dataexchange-status', type => 2, set => { key_values => [ { name => 'status' }, { name => 'vm' }, { name => 'data_exchange_enabled' } ], closure_custom_calc => $self->can('custom_integrationservice_calc'), closure_custom_calc_extra_options => { output_label => 'data exchange', name_status => 'data_exchange_enabled' }, closure_custom_output => $self->can('custom_integrationservice_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold + closure_custom_threshold_check => \&catalog_status_threshold_ng } }, - { label => 'heartbeat-status', threshold => 0, set => { + { label => 'heartbeat-status', type => 2, set => { key_values => [ { name => 'status' }, { name => 'vm' }, { name => 'heartbeat_enabled' } ], closure_custom_calc => $self->can('custom_integrationservice_calc'), closure_custom_calc_extra_options => { output_label => 'heartbeat', name_status => 'heartbeat_enabled' }, closure_custom_output => $self->can('custom_integrationservice_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold + closure_custom_threshold_check => \&catalog_status_threshold_ng } }, - { label => 'backup-status', threshold => 0, set => { + { label => 'backup-status', type => 2, set => { key_values => [ { name => 'status' }, { name => 'vm' }, { name => 'backup_enabled' } ], closure_custom_calc => $self->can('custom_integrationservice_calc'), closure_custom_calc_extra_options => { output_label => 'backup', name_status => 'backup_enabled' }, closure_custom_output => $self->can('custom_integrationservice_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold + closure_custom_threshold_check => \&catalog_status_threshold_ng } } ]; @@ -158,19 +160,7 @@ sub new { 'filter-vm:s' => { name => 'filter_vm' }, 'filter-description:s' => { name => 'filter_description' }, 'filter-hostgroup:s' => { name => 'filter_hostgroup' }, - 'filter-status:s' => { name => 'filter_status' }, - 'warning-status:s' => { name => 'warning_status', default => '' }, - 'critical-status:s' => { name => 'critical_status', default => '%{vmaddition} =~ /not detected/i' }, - 'warning-osshutdown-status:s' => { name => 'warning_osshutdown_status', default => '' }, - 'critical-osshutdown-status:s' => { name => 'critical_osshutdown_status', default => '' }, - 'warning-timesync-status:s' => { name => 'warning_timesync_status', default => '' }, - 'critical-timesync-status:s' => { name => 'critical_timesync_status', default => '' }, - 'warning-dataexchange-status:s' => { name => 'warning_dataexchange_status', default => '' }, - 'critical-dataexchange-status:s' => { name => 'critical_dataexchange_status', default => '' }, - 'warning-heartbeat-status:s' => { name => 'warning_heartbeat_status', default => '' }, - 'critical-heartbeat-status:s' => { name => 'critical_heartbeat_status', default => '' }, - 'warning-backup-status:s' => { name => 'warning_backup_status', default => '' }, - 'critical-backup-status:s' => { name => 'critical_backup_status', default => '' } + 'filter-status:s' => { name => 'filter_status' } }); return $self; @@ -188,12 +178,6 @@ sub check_options { $self->{output}->option_exit(); } } - - $self->change_macros(macros => [ - 'warning_status', 'critical_status', 'warning_osshutdown_status', 'critical_osshutdown_status', - 'warning_timesync_status', 'critical_timesync_status', 'warning_dataexchange_status', 'critical_dataexchange_status', - 'warning_heartbeat_status', 'critical_heartbeat_status', 'warning_backup_status', 'critical_backup_status' - ]); } sub manage_selection { diff --git a/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/scvmmsnapshot.pm b/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/scvmmsnapshot.pm index 89233fd2d..735a5082b 100644 --- a/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/scvmmsnapshot.pm +++ b/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/scvmmsnapshot.pm @@ -29,6 +29,18 @@ use centreon::common::powershell::hyperv::2012::scvmmsnapshot; use apps::microsoft::hyperv::2012::local::mode::resources::types qw($scvmm_vm_status); use JSON::XS; +sub custom_vm_output { + my ($self, %options) = @_; + + return 'checkpoint started since: ' . centreon::plugins::misc::change_seconds(value => $self->{result_values}->{snapshot}); +} + +sub prefix_vm_output { + my ($self, %options) = @_; + + return "VM '" . $options{instance_value}->{display} . "' "; +} + sub set_counters { my ($self, %options) = @_; @@ -45,18 +57,6 @@ sub set_counters { ]; } -sub custom_vm_output { - my ($self, %options) = @_; - - return 'checkpoint started since: ' . centreon::plugins::misc::change_seconds(value => $self->{result_values}->{snapshot}); -} - -sub prefix_vm_output { - my ($self, %options) = @_; - - return "VM '" . $options{instance_value}->{display} . "' "; -} - sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); diff --git a/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/scvmmvmstatus.pm b/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/scvmmvmstatus.pm index 4b97e5a4a..0039daa3a 100644 --- a/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/scvmmvmstatus.pm +++ b/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/scvmmvmstatus.pm @@ -27,7 +27,7 @@ use warnings; use centreon::plugins::misc; use centreon::common::powershell::hyperv::2012::scvmmvmstatus; use apps::microsoft::hyperv::2012::local::mode::resources::types qw($scvmm_vm_status); -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); use JSON::XS; sub custom_status_output { @@ -36,6 +36,12 @@ sub custom_status_output { return 'status: ' . $self->{result_values}->{status}; } +sub prefix_vm_output { + my ($self, %options) = @_; + + return "VM '" . $options{instance_value}->{vm} . "' "; +} + sub set_counters { my ($self, %options) = @_; @@ -44,22 +50,16 @@ sub set_counters { ]; $self->{maps_counters}->{vm} = [ - { label => 'status', threshold => 0, set => { + { label => 'status', type => 2, critical_default => '%{status} !~ /Running|Stopped/i', set => { key_values => [ { name => 'vm' }, { name => 'hostgroup' }, { name => 'status' } ], 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 } } ]; } -sub prefix_vm_output { - my ($self, %options) = @_; - - return "VM '" . $options{instance_value}->{vm} . "' "; -} - sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); @@ -79,9 +79,7 @@ sub new { 'ps-display' => { name => 'ps_display' }, 'filter-vm:s' => { name => 'filter_vm' }, 'filter-description:s' => { name => 'filter_description' }, - 'filter-hostgroup:s' => { name => 'filter_hostgroup' }, - 'warning-status:s' => { name => 'warning_status', default => '' }, - 'critical-status:s' => { name => 'critical_status', default => '%{status} !~ /Running|Stopped/i' } + 'filter-hostgroup:s' => { name => 'filter_hostgroup' } }); return $self; @@ -99,7 +97,6 @@ sub check_options { $self->{output}->option_exit(); } } - $self->change_macros(macros => ['warning_status', 'critical_status']); } sub manage_selection {