diff --git a/.github/workflows/plugins.yml b/.github/workflows/plugins.yml index 274f6280f..74d80778f 100644 --- a/.github/workflows/plugins.yml +++ b/.github/workflows/plugins.yml @@ -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' }} diff --git a/.github/workflows/tests-functional.yml b/.github/workflows/tests-functional.yml index a3d2f13e6..a9978146f 100644 --- a/.github/workflows/tests-functional.yml +++ b/.github/workflows/tests-functional.yml @@ -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 @@ -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 diff --git a/src/centreon/common/protocols/sql/mode/sqlstring.pm b/src/centreon/common/protocols/sql/mode/sqlstring.pm index a76d686de..8acb399fc 100644 --- a/src/centreon/common/protocols/sql/mode/sqlstring.pm +++ b/src/centreon/common/protocols/sql/mode/sqlstring.pm @@ -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 { @@ -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> diff --git a/tests/functional/database/database-mysql.robot b/tests/functional/database/database-mysql.robot new file mode 100644 index 000000000..7f0a51dd6 --- /dev/null +++ b/tests/functional/database/database-mysql.robot @@ -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