From 6773f1c6445336ab803b4b69448e7175dc12e931 Mon Sep 17 00:00:00 2001 From: itoussies <65223458+itoussies@users.noreply.github.com> Date: Thu, 14 Aug 2025 14:45:37 +0200 Subject: [PATCH] fix(apps::microsoft::hyperv::2012::local): fix discovery stats in scvmm-discovery (#5707) Refs: CTOR-1852 --- .../hyperv/2012/local/mode/scvmmdiscovery.pm | 38 ++++++++++--------- .../hyperv/2012/local/scvmmdiscovery.json | 25 ++++++++++++ .../hyperv/2012/local/scvmmdiscovery.robot | 35 +++++++++++++++++ tests/resources/spellcheck/stopwords.txt | 1 + 4 files changed, 81 insertions(+), 18 deletions(-) create mode 100644 tests/apps/microsoft/hyperv/2012/local/scvmmdiscovery.json create mode 100644 tests/apps/microsoft/hyperv/2012/local/scvmmdiscovery.robot diff --git a/src/apps/microsoft/hyperv/2012/local/mode/scvmmdiscovery.pm b/src/apps/microsoft/hyperv/2012/local/mode/scvmmdiscovery.pm index 26b967b7d..07ccc7150 100644 --- a/src/apps/microsoft/hyperv/2012/local/mode/scvmmdiscovery.pm +++ b/src/apps/microsoft/hyperv/2012/local/mode/scvmmdiscovery.pm @@ -146,6 +146,10 @@ sub powershell_exec { sub run { my ($self, %options) = @_; + my $disco_data; + my $disco_stats; + $disco_stats->{start_time} = time(); + my $decoded = $self->powershell_exec(); my $hosts = {}; @@ -154,8 +158,6 @@ sub run { $hosts->{ $entry->{id} } = { cluster_name => $entry->{clusterName}, name => $entry->{name} }; } - my $disco_data; - my $disco_stats; foreach my $entry (@$decoded) { my $item = {}; @@ -215,63 +217,63 @@ __END__ =head1 MODE -Resources discovery. +SCVMM resources discovery. =over 8 =item B<--prettify> -Prettify JSON output. +Prettify the JSON output. =item B<--resource-type> -Choose the type of resources -to discover (can be: 'host', 'vm') (mandatory). +Choose the type of resources to discover (can be: C, C) (required). =item B<--scvmm-hostname> -SCVMM hostname. +Set the SCVMM hostname. =item B<--scvmm-username> -SCVMM username (required). +Set the SCVMM username (required). =item B<--scvmm-password> -SCVMM password (required). +Set the SCVMM password (required). =item B<--scvmm-port> -SCVMM port (default: 8100). +Set the SCVMM port (default: 8100). =item B<--timeout> -Set timeout time for command execution (default: 90 sec) +Set timeout time for command execution (default: 90 sec). =item B<--no-ps> -Don't encode powershell. To be used with --command and 'type' command. +Don't encode powershell. To be used with C<--command> and 'type' command. =item B<--command> -Command to get information (default: 'powershell.exe'). -Can be changed if you have output in a file. To be used with --no-ps option!!! +Set the command to get information (default: 'powershell.exe'). +It can be used if you have the information in a file. +This option should be used with C<--no-ps> option!!! =item B<--command-path> -Command path (default: none). +Set the command path (default: none). =item B<--command-options> -Command options (default: '-InputFormat none -NoLogo -EncodedCommand'). +Set the command options (default: C<-InputFormat none -NoLogo -EncodedCommand>). =item B<--ps-display> -Display powershell script. +Display the powershell script. =item B<--ps-exec-only> -Print powershell output. +Print the powershell output. =back diff --git a/tests/apps/microsoft/hyperv/2012/local/scvmmdiscovery.json b/tests/apps/microsoft/hyperv/2012/local/scvmmdiscovery.json new file mode 100644 index 000000000..9e3b63b27 --- /dev/null +++ b/tests/apps/microsoft/hyperv/2012/local/scvmmdiscovery.json @@ -0,0 +1,25 @@ +[ + { + "description":"description", + "type":"vm", + "computerName":"computer1.centreon.local", + "vmId":"VM-123", + "ipv4Addresses":"10.0.0.1", + "name":"Computer1", + "hostGroupPath":"Hostgroup1", + "tag":"(aucun)", + "vmHostId":"DEF-456", + "status":0, + "operatingSystem":"Windows Server 2022 Standard", + "enabled":true + }, + { + "description":"description", + "type":"host", + "clusterName":"cluster.centreon.local", + "id":"CL-456", + "name": "host.centreon.local", + "fqdn":"host.centreon.local", + "operatingSystem":"Windows Server 2022 Standard" + } +] diff --git a/tests/apps/microsoft/hyperv/2012/local/scvmmdiscovery.robot b/tests/apps/microsoft/hyperv/2012/local/scvmmdiscovery.robot new file mode 100644 index 000000000..0a469fad4 --- /dev/null +++ b/tests/apps/microsoft/hyperv/2012/local/scvmmdiscovery.robot @@ -0,0 +1,35 @@ +*** 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=scvmm-discovery +... --scvmm-username='username' +... --scvmm-password='password' +... --command=cat +... --command-path=/usr/bin +... --no-ps + + +*** Test Cases *** +HyperV 2022-2 ${tc} + [Documentation] Apps Microsoft HyperV 2022 + [Tags] applications microsoft hyperv virtualization + ${command} Catenate + ... ${CMD} + ... --command-options=${CURDIR}/scvmmdiscovery.json + ... --resource-type='${resource_type}' + ... | jq -c --sort-keys + + Ctn Run Command And Check Result As Regexp ${command} ${expected_result} + + Examples: tc resource_type expected_result -- + ... 1 ${EMPTY} \\\\{"discovered_items":1,"duration":0,"end_time":\\\\d+,"results":\\\\[\\\\{"cluster_name":null,"computer_name":"computer1.centreon.local","description":"description","enabled":"yes","hostgroup_path":"Hostgroup1","id":"VM-123","ipv4_address":"10.0.0.1","ipv4_addresses":\\\\["10.0.0.1"\\\\],"name":"Computer1","operating_system":"Windows Server 2022 Standard","status":"Running","tag":"\\\\(aucun\\\\)","type":"vm","vmhost_name":null\\\\}\\\\],"start_time":\\\\d+\\\\} + ... 2 vm \\\\{"discovered_items":1,"duration":0,"end_time":\\\\d+,"results":\\\\[\\\\{"cluster_name":null,"computer_name":"computer1.centreon.local","description":"description","enabled":"yes","hostgroup_path":"Hostgroup1","id":"VM-123","ipv4_address":"10.0.0.1","ipv4_addresses":\\\\["10.0.0.1"\\\\],"name":"Computer1","operating_system":"Windows Server 2022 Standard","status":"Running","tag":"\\\\(aucun\\\\)","type":"vm","vmhost_name":null\\\\}\\\\],"start_time":\\\\d+\\\\} + ... 3 host \\\\{"discovered_items":1,"duration":0,"end_time":\\\\d+,"results":\\\\[\\\\{"cluster_name":"cluster.centreon.local","description":"description","fqdn":null,"id":"CL-456","name":"host.centreon.local","operating_system":"Windows Server 2022 Standard","type":"host"\\\\}\\\\],"start_time":\\\\d+\\\\} \ No newline at end of file diff --git a/tests/resources/spellcheck/stopwords.txt b/tests/resources/spellcheck/stopwords.txt index c0b1cfbc8..335cf715c 100644 --- a/tests/resources/spellcheck/stopwords.txt +++ b/tests/resources/spellcheck/stopwords.txt @@ -276,6 +276,7 @@ snmp snmpd.conf space-usage-prct --sql-errors-exit +SCVMM SRX SSDCapacity SSG