Skip to content

Commit

Permalink
[MON-22331] [Plugins] Mode sql-string not working anymore (#4746)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucie-dubrunfaut authored and omercier committed Jan 8, 2024
1 parent ef9b28a commit c6bfbd1
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/plugins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ jobs:
steps:
- name: Checkout sources
if: ${{ matrix.distrib == 'el7' }}
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
uses: actions/checkout@v3 # el7 is not compatible with checkout v4 which uses node20

- name: Checkout sources
if: ${{ matrix.distrib != 'el7' }}
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/tests-functional.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ jobs:
Net::SNMP
URI::Encode
XML::LibXML
DBI
DBD::mysql
POSIX
Time::HiRes
JSON::XS
- name: Install Python
uses: actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236 # v4.7.1
Expand All @@ -71,3 +76,6 @@ jobs:
sudo cp -r tests/resources/snmp/* /usr/snmpsim/data/
snmpsimd --agent-udpv4-endpoint=127.0.0.1:2024 --process-user=snmp --process-group=snmp &
robot tests/functional/snmp
- name: Run Robot Framework Database tests
run: robot tests/functional/database
9 changes: 5 additions & 4 deletions src/centreon/common/protocols/sql/mode/sqlstring.pm
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,13 @@ sub check_options {
$self->{printf_value} = 'value_field';
if (defined($self->{option_results}->{printf_value}) && $self->{option_results}->{printf_value} ne '') {
$self->{printf_value} = $1
if ($self->{option_results}->{printf_value} =~ /\$self->{result_values}->{(value_field|key_field)}/);
if ($self->{option_results}->{printf_value} =~ /\$self->\{result_values}->\{(value_field|key_field)}/);
$self->{printf_value} = $1
if ($self->{option_results}->{printf_value} =~ /\%{(value_field|key_field)}/);
if ($self->{option_results}->{printf_value} =~ /\%\{(value_field|key_field)}/);
$self->{printf_value} = $1
if ($self->{option_results}->{printf_value} =~ /\%\((value_field|key_field)\)/);
}

}

sub manage_selection {
Expand Down Expand Up @@ -170,8 +171,8 @@ Specify a custom output message relying on printf formatting. If this option is
=item B<--printf-value>
Specify scalar used to replace in printf. If this option is set --printf-format is mandatory.
(can be: %{key_field}, %{value_field})
Specify variable used to replace in printf. If this option is set --printf-format is mandatory.
Can be: %{key_field} (default value) or %{value_field}
=item B<--warning-string>
Expand Down
36 changes: 36 additions & 0 deletions tests/functional/database/database-mysql.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
*** Settings ***
Documentation Database Mysql plugin
Library OperatingSystem
Library Process
Library String

Test Timeout 120s


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

${CMD} perl ${CENTREON_PLUGINS} --plugin=database::mysql::plugin

&{sql_string_test1}
... result=UNKNOWN: Need to specify data_source arguments.
@{sql_string_tests}
... &{sql_string_test1}


*** Test Cases ***
Database Mysql sql string mode
[Documentation] Mode sql string (common protocol database)
[Tags] database mysql sql-string
FOR ${sql_string_test} IN @{sql_string_tests}
${command} Catenate
... ${CMD}
... --mode=sql-string
${output} Run ${command}
${output} Strip String ${output}
Should Be Equal As Strings
... ${output}
... ${sql_string_test.result}
... Wrong output result for compliance of ${sql_string_test.result}{\n}Command output:{\n}${output}{\n}{\n}{\n}
END

0 comments on commit c6bfbd1

Please sign in to comment.