Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ctor 302 windows services decode filter #4955

Merged
merged 3 commits into from Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/os/windows/snmp/mode/service.pm
Expand Up @@ -212,6 +212,7 @@ sub manage_selection {
my $instance = $1 . '.' . $2;

my $name = $self->{output}->decode(join('', map(chr($_), split(/\./, $2))));
$self->{option_results}->{filter_name} = $self->{output}->decode($self->{option_results}->{filter_name});

next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$name !~ /$self->{option_results}->{filter_name}/);
Expand Down
70 changes: 70 additions & 0 deletions tests/functional/snmp/os-windows-services.robot
@@ -0,0 +1,70 @@
*** Settings ***
Documentation Linux Local Systemd-sc-status

Library OperatingSystem
Library String
Library Examples

Test Timeout 120s


*** Variables ***
${CENTREON_PLUGINS} ${CURDIR}${/}..${/}..${/}..${/}src${/}centreon_plugins.pl

${CMD} perl ${CENTREON_PLUGINS} --plugin=os::windows::snmp::plugin
... --mode=service
... --hostname=127.0.0.1
... --snmp-port=2024

*** Test Cases ***
Windows Services EN ${tc}/x
[Documentation] Full ASCII
[Tags] os linux local
${command} Catenate
... ${CMD}
... --snmp-community=os_windows_services_en
... --filter-name='${filter}'
... ${extra_option}

${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 extra_option expected_result --
... 1 ${EMPTY} ${EMPTY} OK: All services are ok | 'services.total.count'=168;;;0; 'services.active.count'=168;;;0; 'services.continue.pending.count'=0;;;0; 'services.pause.pending.count'=0;;;0; 'services.paused.count'=0;;;0;
... 2 toto ${EMPTY} OK: ${SPACE}| 'services.total.count'=0;;;0; 'services.active.count'=0;;;0; 'services.continue.pending.count'=0;;;0; 'services.pause.pending.count'=0;;;0; 'services.paused.count'=0;;;0;
... 3 toto --critical-active=1: CRITICAL: Number of services active: 0 | 'services.total.count'=0;;;0; 'services.active.count'=0;;1:;0; 'services.continue.pending.count'=0;;;0; 'services.pause.pending.count'=0;;;0; 'services.paused.count'=0;;;0;
... 4 ${EMPTY} --critical-active=1: OK: All services are ok | 'services.total.count'=168;;;0; 'services.active.count'=168;;1:;0; 'services.continue.pending.count'=0;;;0; 'services.pause.pending.count'=0;;;0; 'services.paused.count'=0;;;0;
... 5 ${EMPTY} --critical-active=1:1 CRITICAL: Number of services active: 168 | 'services.total.count'=168;;;0; 'services.active.count'=168;;1:1;0; 'services.continue.pending.count'=0;;;0; 'services.pause.pending.count'=0;;;0; 'services.paused.count'=0;;;0;


Windows Services FR ${tc}/x
[Documentation] Systemd version < 248
[Tags] os linux local
${command} Catenate
... ${CMD}
... --snmp-community=os_windows_services_fr
... --filter-name='${filter}'
... ${extra_option}

${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 extra_option expected_result --
... 1 ${EMPTY} ${EMPTY} OK: All services are ok | 'services.total.count'=80;;;0; 'services.active.count'=80;;;0; 'services.continue.pending.count'=0;;;0; 'services.pause.pending.count'=0;;;0; 'services.paused.count'=0;;;0;
... 2 toto ${EMPTY} OK: ${SPACE}| 'services.total.count'=0;;;0; 'services.active.count'=0;;;0; 'services.continue.pending.count'=0;;;0; 'services.pause.pending.count'=0;;;0; 'services.paused.count'=0;;;0;
... 3 toto --critical-active=1: CRITICAL: Number of services active: 0 | 'services.total.count'=0;;;0; 'services.active.count'=0;;1:;0; 'services.continue.pending.count'=0;;;0; 'services.pause.pending.count'=0;;;0; 'services.paused.count'=0;;;0;
... 4 ${EMPTY} --critical-active=1: OK: All services are ok | 'services.total.count'=80;;;0; 'services.active.count'=80;;1:;0; 'services.continue.pending.count'=0;;;0; 'services.pause.pending.count'=0;;;0; 'services.paused.count'=0;;;0;
... 5 ${EMPTY} --critical-active=1:1 CRITICAL: Number of services active: 80 | 'services.total.count'=80;;;0; 'services.active.count'=80;;1:1;0; 'services.continue.pending.count'=0;;;0; 'services.pause.pending.count'=0;;;0; 'services.paused.count'=0;;;0;
... 6 .v.nement --critical-active=1: OK: All services are ok | 'services.total.count'=5;;;0; 'services.active.count'=5;;1:;0; 'services.continue.pending.count'=0;;;0; 'services.pause.pending.count'=0;;;0; 'services.paused.count'=0;;;0;
... 7 \xe9v\xe9nement ${EMPTY} OK: All services are ok | 'services.total.count'=5;;;0; 'services.active.count'=5;;;0; 'services.continue.pending.count'=0;;;0; 'services.pause.pending.count'=0;;;0; 'services.paused.count'=0;;;0;
... 8 SNMP ${EMPTY} OK: Service 'Service SNMP' state is 'active' [installed state: 'installed'] | 'services.total.count'=1;;;0; 'services.active.count'=1;;;0; 'services.continue.pending.count'=0;;;0; 'services.pause.pending.count'=0;;;0; 'services.paused.count'=0;;;0;