From a25c71c91c7896c4e63c58dc7fd05f6705a8873e Mon Sep 17 00:00:00 2001 From: omercier Date: Mon, 3 Jun 2024 17:54:12 +0200 Subject: [PATCH 1/8] enh(plugin): adapted powershell to make it compatible with hyperv 2022 --- .../hyperv/2012/nodeintegrationservice.pm | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/centreon/common/powershell/hyperv/2012/nodeintegrationservice.pm b/src/centreon/common/powershell/hyperv/2012/nodeintegrationservice.pm index a85f509617..0b0f97ae20 100644 --- a/src/centreon/common/powershell/hyperv/2012/nodeintegrationservice.pm +++ b/src/centreon/common/powershell/hyperv/2012/nodeintegrationservice.pm @@ -35,6 +35,9 @@ $culture = new-object "System.Globalization.CultureInfo" "en-us" $ps .= centreon::common::powershell::functions::escape_jsonstring(%options); $ps .= centreon::common::powershell::functions::convert_to_json(%options); + # if the version of HyperV Powershell module is higher than 2.0.0 and not compatible with + # the following script, then use this Import-Module instead: + # Import-Module -Name "Hyper-V" -MaximumVersion "2.0.0" $ps .= ' $ProgressPreference = "SilentlyContinue" @@ -68,8 +71,19 @@ Try { $item_service.service = $service.Name $item_service.enabled = $service.Enabled + + # this works for sure on v1.1 of HyperV Powershell module $item_service.primary_operational_status = $service.PrimaryOperationalStatus.value__ $item_service.secondary_operational_status = $service.SecondaryOperationalStatus.value__ + + # this works for sure on v2.0.0 of HyperV Powershell module + if (($vm.PrimaryStatusDescription -ne $null) -and ($vm.PrimaryStatusDescription -ne "")) { + $item_service.primary_operational_status = $vm.PrimaryStatusDescription + } + if (($vm.SecondaryStatusDescription -ne $null) -and ($vm.SecondaryStatusDescription -ne "")) { + $item_service.secondary_operational_status = $vm.SecondaryStatusDescription + } + $services.Add($item_service) } From 78de5c5c635fde40a28e66efed68cdfa1d93ffd1 Mon Sep 17 00:00:00 2001 From: omercier Date: Tue, 11 Jun 2024 11:50:34 +0200 Subject: [PATCH 2/8] fix(powershell): bad source for data --- .../powershell/hyperv/2012/nodeintegrationservice.pm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/centreon/common/powershell/hyperv/2012/nodeintegrationservice.pm b/src/centreon/common/powershell/hyperv/2012/nodeintegrationservice.pm index 0b0f97ae20..7446ddb1ca 100644 --- a/src/centreon/common/powershell/hyperv/2012/nodeintegrationservice.pm +++ b/src/centreon/common/powershell/hyperv/2012/nodeintegrationservice.pm @@ -77,11 +77,11 @@ Try { $item_service.secondary_operational_status = $service.SecondaryOperationalStatus.value__ # this works for sure on v2.0.0 of HyperV Powershell module - if (($vm.PrimaryStatusDescription -ne $null) -and ($vm.PrimaryStatusDescription -ne "")) { - $item_service.primary_operational_status = $vm.PrimaryStatusDescription + if (($service.PrimaryStatusDescription -ne $null) -and ($service.PrimaryStatusDescription -ne "")) { + $item_service.primary_operational_status = $service.PrimaryStatusDescription } - if (($vm.SecondaryStatusDescription -ne $null) -and ($vm.SecondaryStatusDescription -ne "")) { - $item_service.secondary_operational_status = $vm.SecondaryStatusDescription + if (($service.SecondaryStatusDescription -ne $null) -and ($service.SecondaryStatusDescription -ne "")) { + $item_service.secondary_operational_status = $service.SecondaryStatusDescription } $services.Add($item_service) From 9f9314d410101a32b4569bfded701469241f75c5 Mon Sep 17 00:00:00 2001 From: omercier Date: Fri, 21 Jun 2024 10:26:28 +0200 Subject: [PATCH 3/8] wip: attempt to fix without breaking the former behaviour --- .../2012/local/mode/nodeintegrationservice.pm | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/apps/microsoft/hyperv/2012/local/mode/nodeintegrationservice.pm b/src/apps/microsoft/hyperv/2012/local/mode/nodeintegrationservice.pm index 1061317e7b..fe9f43471b 100644 --- a/src/apps/microsoft/hyperv/2012/local/mode/nodeintegrationservice.pm +++ b/src/apps/microsoft/hyperv/2012/local/mode/nodeintegrationservice.pm @@ -235,16 +235,34 @@ sub manage_selection { my $services = (ref($node->{services}) eq 'ARRAY') ? $node->{services} : [ $node->{services} ]; foreach my $service (@$services) { + my $primary_status; + my $secondary_status; + if ( defined($service->{primary_operational_status}) ) { + if ( defined($node_vm_integration_service_operational_status->{ $service->{primary_operational_status}}) ) { + $primary_status = $node_vm_integration_service_operational_status->{ $service->{primary_operational_status} }; + } else { + $primary_status = $service->{primary_operational_status}; + } + } else { + $primary_status = '-'; + } + if ( defined($service->{secondary_operational_status}) ) { + if ( defined($node_vm_integration_service_operational_status->{ $service->{secondary_operational_status}}) ) { + $secondary_status = $node_vm_integration_service_operational_status->{ $service->{secondary_operational_status} }; + } else { + $secondary_status = $service->{secondary_operational_status}; + } + } else { + $secondary_status = '-'; + } + + $self->{vm}->{$id}->{service}->{$id2} = { vm => $node->{name}, service => $service->{service}, enabled => $service->{enabled} =~ /True|1/i ? 1 : 0, - primary_status => - defined($service->{primary_operational_status}) && defined($node_vm_integration_service_operational_status->{ $service->{primary_operational_status} }) ? - $node_vm_integration_service_operational_status->{ $service->{primary_operational_status} } : '-', - secondary_status => - defined($service->{secondary_operational_status}) && defined($node_vm_integration_service_operational_status->{ $service->{secondary_operational_status} }) ? - $node_vm_integration_service_operational_status->{ $service->{secondary_operational_status} } : '-' + primary_status => $primary_status, + secondary_status => $secondary_status }; $id2++; } From 691ac78fa48ec3d363e65d426fc341eb4cf6fc64 Mon Sep 17 00:00:00 2001 From: omercier Date: Mon, 24 Jun 2024 15:26:38 +0200 Subject: [PATCH 4/8] add(tests): added tests for hyperv 2022 --- .../local/nodeintegrationservice-2022.json | 407 ++++++++++++++++++ .../2012/local/nodeintegrationservice.robot | 37 ++ 2 files changed, 444 insertions(+) create mode 100644 tests/robot/apps/microsoft/hyperv/2012/local/nodeintegrationservice-2022.json create mode 100644 tests/robot/apps/microsoft/hyperv/2012/local/nodeintegrationservice.robot diff --git a/tests/robot/apps/microsoft/hyperv/2012/local/nodeintegrationservice-2022.json b/tests/robot/apps/microsoft/hyperv/2012/local/nodeintegrationservice-2022.json new file mode 100644 index 0000000000..0434e275ab --- /dev/null +++ b/tests/robot/apps/microsoft/hyperv/2012/local/nodeintegrationservice-2022.json @@ -0,0 +1,407 @@ +[ + { + "note": "", + "integration_services_state": "", + "state": 3, + "name": "VSERVER01", + "services": [ + { + "primary_operational_status": null, + "secondary_operational_status": null, + "service": "Guest Service Interface", + "enabled": true + }, + { + "primary_operational_status": null, + "secondary_operational_status": null, + "service": "Heartbeat", + "enabled": true + }, + { + "primary_operational_status": null, + "secondary_operational_status": null, + "service": "Key-Value Pair Exchange", + "enabled": true + }, + { + "primary_operational_status": null, + "secondary_operational_status": null, + "service": "Shutdown", + "enabled": true + }, + { + "primary_operational_status": null, + "secondary_operational_status": null, + "service": "Time Synchronization", + "enabled": false + }, + { + "primary_operational_status": null, + "secondary_operational_status": null, + "service": "VSS", + "enabled": true + } + ], + "integration_services_version": "0.0" + }, + { + "note": "", + "integration_services_state": "", + "state": 3, + "name": "VSERVER02", + "services": [ + { + "primary_operational_status": null, + "secondary_operational_status": null, + "service": "Guest Service Interface", + "enabled": true + }, + { + "primary_operational_status": null, + "secondary_operational_status": null, + "service": "Heartbeat", + "enabled": true + }, + { + "primary_operational_status": null, + "secondary_operational_status": null, + "service": "Key-Value Pair Exchange", + "enabled": true + }, + { + "primary_operational_status": null, + "secondary_operational_status": null, + "service": "Shutdown", + "enabled": true + }, + { + "primary_operational_status": null, + "secondary_operational_status": null, + "service": "Time Synchronization", + "enabled": false + }, + { + "primary_operational_status": null, + "secondary_operational_status": null, + "service": "VSS", + "enabled": true + } + ], + "integration_services_version": "0.0" + }, + { + "note": "", + "integration_services_state": "", + "state": 3, + "name": "VSERVER03", + "services": [ + { + "primary_operational_status": null, + "secondary_operational_status": null, + "service": "Guest Service Interface", + "enabled": true + }, + { + "primary_operational_status": null, + "secondary_operational_status": null, + "service": "Heartbeat", + "enabled": true + }, + { + "primary_operational_status": null, + "secondary_operational_status": null, + "service": "Key-Value Pair Exchange", + "enabled": true + }, + { + "primary_operational_status": null, + "secondary_operational_status": null, + "service": "Shutdown", + "enabled": true + }, + { + "primary_operational_status": null, + "secondary_operational_status": null, + "service": "Time Synchronization", + "enabled": false + }, + { + "primary_operational_status": null, + "secondary_operational_status": null, + "service": "VSS", + "enabled": true + } + ], + "integration_services_version": "0.0" + }, + { + "note": "", + "integration_services_state": "", + "state": 3, + "name": "VSERVER04", + "services": [ + { + "primary_operational_status": null, + "secondary_operational_status": null, + "service": "Guest Service Interface", + "enabled": true + }, + { + "primary_operational_status": null, + "secondary_operational_status": null, + "service": "Heartbeat", + "enabled": true + }, + { + "primary_operational_status": null, + "secondary_operational_status": null, + "service": "Key-Value Pair Exchange", + "enabled": true + }, + { + "primary_operational_status": null, + "secondary_operational_status": null, + "service": "Shutdown", + "enabled": true + }, + { + "primary_operational_status": null, + "secondary_operational_status": null, + "service": "Time Synchronization", + "enabled": false + }, + { + "primary_operational_status": null, + "secondary_operational_status": null, + "service": "VSS", + "enabled": true + } + ], + "integration_services_version": "0.0" + }, + { + "note": "", + "integration_services_state": "", + "state": 2, + "name": "VSERVER05", + "services": [ + { + "primary_operational_status": "OK", + "secondary_operational_status": null, + "service": "Guest Service Interface", + "enabled": false + }, + { + "primary_operational_status": "OK", + "secondary_operational_status": null, + "service": "Heartbeat", + "enabled": true + }, + { + "primary_operational_status": "OK", + "secondary_operational_status": null, + "service": "Key-Value Pair Exchange", + "enabled": true + }, + { + "primary_operational_status": "OK", + "secondary_operational_status": null, + "service": "Shutdown", + "enabled": true + }, + { + "primary_operational_status": "OK", + "secondary_operational_status": null, + "service": "Time Synchronization", + "enabled": false + }, + { + "primary_operational_status": "OK", + "secondary_operational_status": null, + "service": "VSS", + "enabled": false + } + ], + "integration_services_version": "0.0" + }, + { + "note": "", + "integration_services_state": "", + "state": 3, + "name": "VSERVER06", + "services": [ + { + "primary_operational_status": null, + "secondary_operational_status": null, + "service": "Guest Service Interface", + "enabled": true + }, + { + "primary_operational_status": null, + "secondary_operational_status": null, + "service": "Heartbeat", + "enabled": true + }, + { + "primary_operational_status": null, + "secondary_operational_status": null, + "service": "Key-Value Pair Exchange", + "enabled": true + }, + { + "primary_operational_status": null, + "secondary_operational_status": null, + "service": "Shutdown", + "enabled": true + }, + { + "primary_operational_status": null, + "secondary_operational_status": null, + "service": "Time Synchronization", + "enabled": false + }, + { + "primary_operational_status": null, + "secondary_operational_status": null, + "service": "VSS", + "enabled": true + } + ], + "integration_services_version": "0.0" + }, + { + "note": "", + "integration_services_state": "", + "state": 2, + "name": "VSERVER07", + "services": [ + { + "primary_operational_status": "OK", + "secondary_operational_status": null, + "service": "Guest Service Interface", + "enabled": false + }, + { + "primary_operational_status": "Error", + "secondary_operational_status": "OK", + "service": "Heartbeat", + "enabled": true + }, + { + "primary_operational_status": "OK", + "secondary_operational_status": null, + "service": "Key-Value Pair Exchange", + "enabled": true + }, + { + "primary_operational_status": "OK", + "secondary_operational_status": null, + "service": "Shutdown", + "enabled": true + }, + { + "primary_operational_status": "OK", + "secondary_operational_status": null, + "service": "Time Synchronization", + "enabled": false + }, + { + "primary_operational_status": "OK", + "secondary_operational_status": null, + "service": "VSS", + "enabled": false + } + ], + "integration_services_version": "0.0" + }, + { + "note": "", + "integration_services_state": "", + "state": 3, + "name": "VSERVER07", + "services": [ + { + "primary_operational_status": null, + "secondary_operational_status": null, + "service": "Guest Service Interface", + "enabled": true + }, + { + "primary_operational_status": null, + "secondary_operational_status": null, + "service": "Heartbeat", + "enabled": true + }, + { + "primary_operational_status": null, + "secondary_operational_status": null, + "service": "Key-Value Pair Exchange", + "enabled": true + }, + { + "primary_operational_status": null, + "secondary_operational_status": null, + "service": "Shutdown", + "enabled": true + }, + { + "primary_operational_status": null, + "secondary_operational_status": null, + "service": "Time Synchronization", + "enabled": false + }, + { + "primary_operational_status": null, + "secondary_operational_status": null, + "service": "VSS", + "enabled": true + } + ], + "integration_services_version": "0.0" + }, + { + "note": "", + "integration_services_state": "", + "state": 3, + "name": "VSERVER08", + "services": [ + { + "primary_operational_status": null, + "secondary_operational_status": null, + "service": "Guest Service Interface", + "enabled": false + }, + { + "primary_operational_status": null, + "secondary_operational_status": null, + "service": "Heartbeat", + "enabled": true + }, + { + "primary_operational_status": null, + "secondary_operational_status": null, + "service": "Key-Value Pair Exchange", + "enabled": true + }, + { + "primary_operational_status": null, + "secondary_operational_status": null, + "service": "Shutdown", + "enabled": true + }, + { + "primary_operational_status": null, + "secondary_operational_status": null, + "service": "Time Synchronization", + "enabled": true + }, + { + "primary_operational_status": null, + "secondary_operational_status": null, + "service": "VSS", + "enabled": true + } + ], + "integration_services_version": "0.0" + } +] diff --git a/tests/robot/apps/microsoft/hyperv/2012/local/nodeintegrationservice.robot b/tests/robot/apps/microsoft/hyperv/2012/local/nodeintegrationservice.robot new file mode 100644 index 0000000000..7cd3da3d88 --- /dev/null +++ b/tests/robot/apps/microsoft/hyperv/2012/local/nodeintegrationservice.robot @@ -0,0 +1,37 @@ +*** Settings *** +Documentation Application Microsoft HyperV 2022 + +Resource ${CURDIR}${/}..${/}..${/}..${/}..${/}..${/}..${/}resources/import.resource + +Test Timeout 120s + + +*** Variables *** +${CMD} ${CENTREON_PLUGINS} +... --plugin=apps::microsoft::hyperv::2012::local::plugin +... --mode=node-integration-service +... --command=cat +... --command-path=/usr/bin +... --no-ps +... --command-options=nodeintegrationservice-2022.json + +*** Test Cases *** +HyperV 2022 ${tc}/3 + [Documentation] Apps Microsoft HyperV 2022 + [Tags] applications microsoft hyperv virtualization + ${command} Catenate + ... ${CMD} + ... --filter-vm='${filter_vm}' + + ${output} Run ${command} + ${output} Strip String ${output} + Should Be Equal As Strings + ... ${output} + ... ${expected_result} + ... \nWrong output result for command:\n${command}\n\nExpected:\n${expected_result}\nCommand output:\n${output}\n\n + + Examples: tc filter_vm expected_result -- + ... 1 ${EMPTY} CRITICAL: 1 problem(s) detected + ... 2 VSERVER05 OK: VM 'VSERVER05' 0 problem(s) detected - VM 'VSERVER05' 0 problem(s) detected + ... 3 VSERVER07 CRITICAL: VM 'VSERVER07' 1 problem(s) detected + From 6eeb1b121c9ab5830c1d883153bb50ba72e88cba Mon Sep 17 00:00:00 2001 From: omercier Date: Mon, 24 Jun 2024 16:22:08 +0200 Subject: [PATCH 5/8] fix(tests): various changes - improved troubkeshooting of pod_spell_check.t - fixed a typo on TRendMicro - Added missing stopwords for HyperV --- .github/scripts/pod_spell_check.t | 7 ++++--- src/apps/trendmicro/iwsva/snmp/plugin.pm | 2 +- tests/resources/spellcheck/stopwords.t | 7 +++++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/scripts/pod_spell_check.t b/.github/scripts/pod_spell_check.t index 3aef6bb8a2..8d6790446f 100644 --- a/.github/scripts/pod_spell_check.t +++ b/.github/scripts/pod_spell_check.t @@ -5,7 +5,7 @@ use Test::More; use Test::Spelling; if (!@ARGV) { - die "Missing perl file to check."; + die "Usage: perl pod_spell_check.t module.pm stopwords.t"; } my $stopword_filename='tests/resources/spellcheck/stopwords.t'; @@ -14,9 +14,10 @@ if(defined($ARGV[1])){ } open(FILE, "<", $stopword_filename) or die "Could not open $stopword_filename"; -printf("stopword file use : ".$stopword_filename." \n"); +printf("Using dictionary: ".$stopword_filename." \n"); add_stopwords(); +close(FILE); set_spell_cmd('hunspell -l'); all_pod_files_spelling_ok($ARGV[0]); -close(FILE); + diff --git a/src/apps/trendmicro/iwsva/snmp/plugin.pm b/src/apps/trendmicro/iwsva/snmp/plugin.pm index 2e46ac9a7e..17075b4581 100644 --- a/src/apps/trendmicro/iwsva/snmp/plugin.pm +++ b/src/apps/trendmicro/iwsva/snmp/plugin.pm @@ -50,6 +50,6 @@ __END__ =head1 PLUGIN DESCRIPTION -Check TendMicro Iwsva equipments in SNMP. +Check TrendMicro Iwsva equipments in SNMP. =cut diff --git a/tests/resources/spellcheck/stopwords.t b/tests/resources/spellcheck/stopwords.t index 6dd7131a0c..2c8e1f2319 100644 --- a/tests/resources/spellcheck/stopwords.t +++ b/tests/resources/spellcheck/stopwords.t @@ -11,6 +11,7 @@ --exclude-fs --filter-fs --filter-vdom +--filter-vm --force-counters32 --force-counters64 --force-oid @@ -34,6 +35,9 @@ --oid-filter --urlpath --warning-bytesallocatedpercentage +-EncodedCommand +-InputFormat +-NoLogo 2c ADSL Avigilon @@ -60,7 +64,9 @@ SSH Sansymphony SureBackup TendMicro +TrendMicro VDSL2 +VM Veeam WSMAN XPath @@ -86,6 +92,7 @@ out-mcast out-ucast perfdata powershell +powershell.exe proto psu queue-messages-inflighted From d02ee6d71e3faca62c7f1cf3557a5acccb5dbf0c Mon Sep 17 00:00:00 2001 From: omercier Date: Mon, 24 Jun 2024 17:00:19 +0200 Subject: [PATCH 6/8] fix(pod): fixed typos --- .../common/powershell/hyperv/2012/nodeintegrationservice.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/centreon/common/powershell/hyperv/2012/nodeintegrationservice.pm b/src/centreon/common/powershell/hyperv/2012/nodeintegrationservice.pm index 7446ddb1ca..245b37c518 100644 --- a/src/centreon/common/powershell/hyperv/2012/nodeintegrationservice.pm +++ b/src/centreon/common/powershell/hyperv/2012/nodeintegrationservice.pm @@ -110,6 +110,6 @@ __END__ =head1 DESCRIPTION -Method to get hyper-v informations. +Method to get Hyper-V information. =cut From f28dc8129ccbc3d1b9946acec0c4b33870086779 Mon Sep 17 00:00:00 2001 From: omercier Date: Fri, 28 Jun 2024 09:00:07 +0200 Subject: [PATCH 7/8] enh(coding): refactored code after review --- .../2012/local/mode/nodeintegrationservice.pm | 39 ++++++++----------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/src/apps/microsoft/hyperv/2012/local/mode/nodeintegrationservice.pm b/src/apps/microsoft/hyperv/2012/local/mode/nodeintegrationservice.pm index fe9f43471b..68c154ecd7 100644 --- a/src/apps/microsoft/hyperv/2012/local/mode/nodeintegrationservice.pm +++ b/src/apps/microsoft/hyperv/2012/local/mode/nodeintegrationservice.pm @@ -134,6 +134,20 @@ sub check_options { if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); } +sub determine_operational_status { + my ($operational_status) = @_; + + if ( defined($operational_status) ) { + if ( defined($node_vm_integration_service_operational_status->{ $operational_status}) ) { + return $node_vm_integration_service_operational_status->{ $operational_status }; + } else { + return $operational_status; + } + } else { + return '-'; + } +} + sub manage_selection { my ($self, %options) = @_; @@ -235,34 +249,13 @@ sub manage_selection { my $services = (ref($node->{services}) eq 'ARRAY') ? $node->{services} : [ $node->{services} ]; foreach my $service (@$services) { - my $primary_status; - my $secondary_status; - if ( defined($service->{primary_operational_status}) ) { - if ( defined($node_vm_integration_service_operational_status->{ $service->{primary_operational_status}}) ) { - $primary_status = $node_vm_integration_service_operational_status->{ $service->{primary_operational_status} }; - } else { - $primary_status = $service->{primary_operational_status}; - } - } else { - $primary_status = '-'; - } - if ( defined($service->{secondary_operational_status}) ) { - if ( defined($node_vm_integration_service_operational_status->{ $service->{secondary_operational_status}}) ) { - $secondary_status = $node_vm_integration_service_operational_status->{ $service->{secondary_operational_status} }; - } else { - $secondary_status = $service->{secondary_operational_status}; - } - } else { - $secondary_status = '-'; - } - $self->{vm}->{$id}->{service}->{$id2} = { vm => $node->{name}, service => $service->{service}, enabled => $service->{enabled} =~ /True|1/i ? 1 : 0, - primary_status => $primary_status, - secondary_status => $secondary_status + primary_status => determine_operational_status($service->{primary_operational_status}), + secondary_status => determine_operational_status($service->{secondary_operational_status}) }; $id2++; } From 1c513d5e57472aa940178069e3a6b14c11a380e1 Mon Sep 17 00:00:00 2001 From: omercier <32134301+omercier@users.noreply.github.com> Date: Fri, 28 Jun 2024 09:02:46 +0200 Subject: [PATCH 8/8] Update stopwords.t --- tests/resources/spellcheck/stopwords.t | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/resources/spellcheck/stopwords.t b/tests/resources/spellcheck/stopwords.t index 2c8e1f2319..dc9f0fcc89 100644 --- a/tests/resources/spellcheck/stopwords.t +++ b/tests/resources/spellcheck/stopwords.t @@ -63,7 +63,6 @@ SNMP SSH Sansymphony SureBackup -TendMicro TrendMicro VDSL2 VM