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

[MON-22331] [Plugins] Mode sql-string not working anymore #4746

Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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@v4
Expand All @@ -71,3 +76,6 @@ jobs:
sudo cp 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
Loading