From eca3644d598e0b0faaff37ddada226112da56be6 Mon Sep 17 00:00:00 2001 From: omercier <32134301+omercier@users.noreply.github.com> Date: Mon, 1 Jul 2024 10:18:56 +0200 Subject: [PATCH] Ctor 146 escalation microsoft hyperv 2012 add option for powershell module version in node integration service mode (#5080) --- .github/scripts/pod_spell_check.t | 7 +- .../2012/local/mode/nodeintegrationservice.pm | 23 +- src/apps/trendmicro/iwsva/snmp/plugin.pm | 2 +- .../hyperv/2012/nodeintegrationservice.pm | 16 +- tests/resources/spellcheck/stopwords.t | 10 +- .../local/nodeintegrationservice-2022.json | 407 ++++++++++++++++++ .../2012/local/nodeintegrationservice.robot | 37 ++ 7 files changed, 489 insertions(+), 13 deletions(-) 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/.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/microsoft/hyperv/2012/local/mode/nodeintegrationservice.pm b/src/apps/microsoft/hyperv/2012/local/mode/nodeintegrationservice.pm index 1061317e7b..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,16 +249,13 @@ sub manage_selection { my $services = (ref($node->{services}) eq 'ARRAY') ? $node->{services} : [ $node->{services} ]; foreach my $service (@$services) { + $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 => determine_operational_status($service->{primary_operational_status}), + secondary_status => determine_operational_status($service->{secondary_operational_status}) }; $id2++; } 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/src/centreon/common/powershell/hyperv/2012/nodeintegrationservice.pm b/src/centreon/common/powershell/hyperv/2012/nodeintegrationservice.pm index a85f509617..245b37c518 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 (($service.PrimaryStatusDescription -ne $null) -and ($service.PrimaryStatusDescription -ne "")) { + $item_service.primary_operational_status = $service.PrimaryStatusDescription + } + if (($service.SecondaryStatusDescription -ne $null) -and ($service.SecondaryStatusDescription -ne "")) { + $item_service.secondary_operational_status = $service.SecondaryStatusDescription + } + $services.Add($item_service) } @@ -96,6 +110,6 @@ __END__ =head1 DESCRIPTION -Method to get hyper-v informations. +Method to get Hyper-V information. =cut diff --git a/tests/resources/spellcheck/stopwords.t b/tests/resources/spellcheck/stopwords.t index b7ffac982d..6219228ef4 100644 --- a/tests/resources/spellcheck/stopwords.t +++ b/tests/resources/spellcheck/stopwords.t @@ -13,6 +13,7 @@ --exclude-fs --filter-fs --filter-vdom +--filter-vm --force-counters32 --force-counters64 --force-oid @@ -37,6 +38,9 @@ --oid-filter --urlpath --warning-bytesallocatedpercentage +-EncodedCommand +-InputFormat +-NoLogo 2c ADSL Avigilon @@ -64,10 +68,11 @@ SSH Sansymphony SureBackup TCP -TendMicro +TrendMicro VDSL2 -VPN +VM Veeam +VPN WSMAN XPath api.meraki.com @@ -95,6 +100,7 @@ out-mcast out-ucast perfdata powershell +powershell.exe proto psu queue-messages-inflighted 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 +