Skip to content

Commit

Permalink
fix(option): fixed the OK case and added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
omercier committed Jan 7, 2025
1 parent efbfa9d commit 95089e8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/centreon/plugins/output.pm
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ sub check_options {
push @{$self->{change_output_adv}}, {
expr => $expr,
short_output => $short_output,
exit_code => defined($exit_code) && $exit_code ne '' && $self->{errors}->{uc($exit_code)} ? uc($exit_code) : undef
exit_code => defined($exit_code) && $exit_code ne '' && defined($self->{errors}->{uc($exit_code)}) ? uc($exit_code) : undef
};
}
}
Expand Down
12 changes: 8 additions & 4 deletions tests/os/linux/snmp/load.robot
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ Documentation Check load table
Resource ${CURDIR}${/}..${/}..${/}..${/}resources/import.resource

Test Timeout 120s

Test Setup Ctn Generic Suite Setup

*** Variables ***
${CMD} ${CENTREON_PLUGINS} --plugin=os::linux::snmp::plugin


*** Test Cases ***
load ${tc}
[Tags] os linux
[Tags] os linux snmp
${command} Catenate
... ${CMD}
... --mode=load
Expand All @@ -23,11 +23,15 @@ load ${tc}
... --snmp-timeout=1
... --critical=${critical}
... --warning=${warning}
... --average=${average}
... --average
... ${extra_options}

Ctn Run Command And Check Result As Strings ${command} ${expected_result}

Examples: tc critical warning average expected_result --
Examples: tc critical warning extra_options expected_result --
... 1 '6,5,4' '4,3,2' ${EMPTY} OK: Load average: 0.43 [0.87/2 CPUs], 0.32 [0.63/2 CPUs], 0.23 [0.47/2 CPUs] | 'avg_load1'=0.43;0:4;0:6;0; 'avg_load5'=0.32;0:3;0:5;0; 'avg_load15'=0.23;0:2;0:4;0; 'load1'=0.87;0:8;0:12;0; 'load5'=0.63;0:6;0:10;0; 'load15'=0.47;0:4;0:8;0;
... 2 '0,0,0' '4,3,2' ${EMPTY} CRITICAL: Load average: 0.43 [0.87/2 CPUs], 0.32 [0.63/2 CPUs], 0.23 [0.47/2 CPUs] | 'avg_load1'=0.43;0:4;0:0;0; 'avg_load5'=0.32;0:3;0:0;0; 'avg_load15'=0.23;0:2;0:0;0; 'load1'=0.87;0:8;0:0;0; 'load5'=0.63;0:6;0:0;0; 'load15'=0.47;0:4;0:0;0;
... 3 '600,500,100' '0,0,0' ${EMPTY} WARNING: Load average: 0.43 [0.87/2 CPUs], 0.32 [0.63/2 CPUs], 0.23 [0.47/2 CPUs] | 'avg_load1'=0.43;0:0;0:600;0; 'avg_load5'=0.32;0:0;0:500;0; 'avg_load15'=0.23;0:0;0:100;0; 'load1'=0.87;0:0;0:1200;0; 'load5'=0.63;0:0;0:1000;0; 'load15'=0.47;0:0;0:200;0;
... 4 '6,5,4' '4,3,2' --change-output-adv='%(short_output) =~ /OK:/ and %(exit_code) == 0,Forced from OK to WARNING,WARNING' Forced from OK to WARNING| 'avg_load1'=0.43;0:4;0:6;0; 'avg_load5'=0.32;0:3;0:5;0; 'avg_load15'=0.23;0:2;0:4;0; 'load1'=0.87;0:8;0:12;0; 'load5'=0.63;0:6;0:10;0; 'load15'=0.47;0:4;0:8;0;
... 5 '0,0,0' '4,3,2' --change-output-adv='%(short_output) =~ /CRITICAL:/ and %(exit_code) == 2,Forced from CRITICAL to OK,OK' Forced from CRITICAL to OK| 'avg_load1'=0.43;0:4;0:0;0; 'avg_load5'=0.32;0:3;0:0;0; 'avg_load15'=0.23;0:2;0:0;0; 'load1'=0.87;0:8;0:0;0; 'load5'=0.63;0:6;0:0;0; 'load15'=0.47;0:4;0:0;0;
... 6 '600,500,100' '0,0,0' --change-output-adv='%(short_output) =~ /WARNING:/ and %(exit_code) == 1,Forced from WARNING to CRITICAL,CRITICAL' Forced from WARNING to CRITICAL| 'avg_load1'=0.43;0:0;0:600;0; 'avg_load5'=0.32;0:0;0:500;0; 'avg_load15'=0.23;0:0;0:100;0; 'load1'=0.87;0:0;0:1200;0; 'load5'=0.63;0:0;0:1000;0; 'load15'=0.47;0:0;0:200;0;

0 comments on commit 95089e8

Please sign in to comment.